this is shit
This commit is contained in:
parent
5c7a05ff61
commit
b97e940d9d
1 changed files with 37 additions and 30 deletions
|
@ -1,5 +1,6 @@
|
||||||
import * as electron from 'electron';
|
import * as electron from 'electron';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
export class AppEvents {
|
export class AppEvents {
|
||||||
private static protocols: any = [
|
private static protocols: any = [
|
||||||
"ame",
|
"ame",
|
||||||
|
@ -11,6 +12,7 @@ export class AppEvents {
|
||||||
]
|
]
|
||||||
private static plugin: any = null;
|
private static plugin: any = null;
|
||||||
private static store: any = null;
|
private static store: any = null;
|
||||||
|
private static win: any = null;
|
||||||
|
|
||||||
constructor(store: any) {
|
constructor(store: any) {
|
||||||
console.log('App started');
|
console.log('App started');
|
||||||
|
@ -101,62 +103,66 @@ export class AppEvents {
|
||||||
}
|
}
|
||||||
|
|
||||||
public bwCreated(win: Electron.BrowserWindow) {
|
public bwCreated(win: Electron.BrowserWindow) {
|
||||||
|
AppEvents.win = win
|
||||||
|
|
||||||
electron.app.on('open-url', (event, url) => {
|
electron.app.on('open-url', (event, url) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
if (AppEvents.protocols.some((protocol: string) => url.includes(protocol))) {
|
if (AppEvents.protocols.some((protocol: string) => url.includes(protocol))) {
|
||||||
AppEvents.LinkHandler(url, win)
|
AppEvents.LinkHandler(url)
|
||||||
|
console.log(url)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
AppEvents.InstanceHandler(win)
|
AppEvents.InstanceHandler()
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************************************************************
|
/***********************************************************************************************************************
|
||||||
* Private methods
|
* Private methods
|
||||||
**********************************************************************************************************************/
|
**********************************************************************************************************************/
|
||||||
|
|
||||||
private static LinkHandler(arg: any, win: Electron.BrowserWindow) {
|
private static LinkHandler(arg: string) {
|
||||||
|
console.log(arg)
|
||||||
|
|
||||||
if (!arg) return;
|
if (!arg) return;
|
||||||
|
|
||||||
// LastFM Auth URL
|
// LastFM Auth URL
|
||||||
if (arg.includes('auth')) {
|
if (arg.includes('auth')) {
|
||||||
let authURI = String(arg).split('/auth/')[1]
|
let authURI = arg.split('/auth/')[1]
|
||||||
if (authURI.startsWith('lastfm')) { // If we wanted more auth options
|
if (authURI.startsWith('lastfm')) { // If we wanted more auth options
|
||||||
const authKey = authURI.split('lastfm?token=')[1];
|
const authKey = authURI.split('lastfm?token=')[1];
|
||||||
AppEvents.store.set('lastfm.enabled', true);
|
AppEvents.store.set('lastfm.enabled', true);
|
||||||
AppEvents.store.set('lastfm.auth_token', authKey);
|
AppEvents.store.set('lastfm.auth_token', authKey);
|
||||||
win.webContents.send('LastfmAuthenticated', authKey);
|
AppEvents.win.webContents.send('LastfmAuthenticated', authKey);
|
||||||
AppEvents.plugin.callPlugin('lastfm', 'authenticate', authKey);
|
AppEvents.plugin.callPlugin('lastfm', 'authenticate', authKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Play
|
// Play
|
||||||
else if (arg.includes('/play/')) { //Steer away from protocol:// specific conditionals
|
else if (arg.includes('/play/')) { //Steer away from protocol:// specific conditionals
|
||||||
const playParam = arg.split('/play/')[1]
|
const playParam = arg.split('/play/')[1]
|
||||||
if (playParam.includes('s/')) { // song
|
|
||||||
console.log(playParam)
|
const mediaType = {
|
||||||
let song = playParam.split('s/')[1]
|
"s/": "song",
|
||||||
console.warn(`[LinkHandler] Attempting to load song by id: ${song}`);
|
"a/": "album",
|
||||||
electron.ipcRenderer.send('play', 'song', song)
|
"p/": "playlist"
|
||||||
} else if (playParam.includes('a/')) { // album
|
|
||||||
console.log(playParam)
|
|
||||||
let album = playParam.split('a/')[1]
|
|
||||||
console.warn(`[LinkHandler] Attempting to load album by id: ${album}`);
|
|
||||||
electron.ipcRenderer.send('play', 'album', album)
|
|
||||||
} else if (playParam.includes('p/')) { // playlist
|
|
||||||
console.log(playParam)
|
|
||||||
let playlist = playParam.split('p/')[1]
|
|
||||||
console.warn(`[LinkHandler] Attempting to load playlist by id: ${playlist}`);
|
|
||||||
electron.ipcRenderer.send('play', 'playlist', playlist)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(mediaType)) {
|
||||||
|
if (playParam.includes(key)) {
|
||||||
|
const id = playParam.split(key)[1]
|
||||||
|
AppEvents.win.webContents.send('play', value, id)
|
||||||
|
console.debug(`[LinkHandler] Attempting to load ${value} by id: ${id}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else if (arg.includes('music.apple.com')) { // URL (used with itms/itmss/music/musics uris)
|
} else if (arg.includes('music.apple.com')) { // URL (used with itms/itmss/music/musics uris)
|
||||||
console.log(arg)
|
console.log(arg)
|
||||||
let url = arg.split('//')[1]
|
let url = arg.split('//')[1]
|
||||||
console.warn(`[LinkHandler] Attempting to load url: ${url}`);
|
console.warn(`[LinkHandler] Attempting to load url: ${url}`);
|
||||||
electron.ipcRenderer.send('play', 'url', url)
|
AppEvents.win.webContents.send('play', 'url', url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static InstanceHandler(win: Electron.BrowserWindow) {
|
private static InstanceHandler() {
|
||||||
|
|
||||||
// Detects of an existing instance is running (So if the lock has been achieved, no existing instance has been found)
|
// Detects of an existing instance is running (So if the lock has been achieved, no existing instance has been found)
|
||||||
const gotTheLock = electron.app.requestSingleInstanceLock()
|
const gotTheLock = electron.app.requestSingleInstanceLock()
|
||||||
|
@ -166,14 +172,15 @@ export class AppEvents {
|
||||||
electron.app.quit()
|
electron.app.quit()
|
||||||
} else { // Runs on the first instance if no other instance has been found
|
} else { // Runs on the first instance if no other instance has been found
|
||||||
electron.app.on('second-instance', (_event, startArgs) => {
|
electron.app.on('second-instance', (_event, startArgs) => {
|
||||||
|
console.log(startArgs)
|
||||||
if (startArgs.includes("--force-quit")) {
|
if (startArgs.includes("--force-quit")) {
|
||||||
console.warn('[InstanceHandler][SecondInstanceHandler] Force Quit found. Quitting App.');
|
console.warn('[InstanceHandler][SecondInstanceHandler] Force Quit found. Quitting App.');
|
||||||
electron.app.quit()
|
electron.app.quit()
|
||||||
} else if (startArgs.includes("cider://")) {
|
} else if (startArgs.includes("cider://")) {
|
||||||
AppEvents.LinkHandler(startArgs, win)
|
AppEvents.LinkHandler(startArgs.toString())
|
||||||
} else if (win) {
|
} else if (AppEvents.win) {
|
||||||
if (win.isMinimized()) win.restore()
|
if (AppEvents.win.isMinimized()) AppEvents.win.restore()
|
||||||
win.focus()
|
AppEvents.win.focus()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue