mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2024-11-22 05:23:09 +01:00
Merge pull request #374 from TheRockYT/custom_protocol_fix
Custom protocol fix (tidal://...)
This commit is contained in:
commit
25afd05ad7
68
src/main.ts
68
src/main.ts
@ -5,7 +5,6 @@ import {
|
|||||||
components,
|
components,
|
||||||
globalShortcut,
|
globalShortcut,
|
||||||
ipcMain,
|
ipcMain,
|
||||||
protocol,
|
|
||||||
session,
|
session,
|
||||||
} from "electron";
|
} from "electron";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
@ -61,20 +60,31 @@ function syncMenuBarWithStore() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine whether the current window is the main window
|
* @returns true/false based on whether the current window is the main window
|
||||||
* if singleInstance is requested.
|
|
||||||
* If singleInstance isn't requested simply return true
|
|
||||||
* @returns true if singInstance is not requested, otherwise true/false based on whether the current window is the main window
|
|
||||||
*/
|
*/
|
||||||
function isMainInstanceOrMultipleInstancesAllowed() {
|
function isMainInstance() {
|
||||||
if (settingsStore.get(settings.singleInstance)) {
|
return app.requestSingleInstanceLock();
|
||||||
const gotTheLock = app.requestSingleInstanceLock();
|
}
|
||||||
|
|
||||||
if (!gotTheLock) {
|
/**
|
||||||
return false;
|
* @returns true/false based on whether multiple instances are allowed
|
||||||
}
|
*/
|
||||||
|
function isMultipleInstancesAllowed() {
|
||||||
|
return !settingsStore.get(settings.singleInstance);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param args the arguments passed to the app
|
||||||
|
* @returns the custom protocol url if it exists, otherwise null
|
||||||
|
*/
|
||||||
|
function getCustomProtocolUrl(args: string[]) {
|
||||||
|
const customProtocolArg = args.find((arg) => arg.startsWith(PROTOCOL_PREFIX));
|
||||||
|
|
||||||
|
if (!customProtocolArg) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
return tidalUrl + "/" + customProtocolArg.substring(PROTOCOL_PREFIX.length + 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
function createWindow(options = { x: 0, y: 0, backgroundColor: "white" }) {
|
function createWindow(options = { x: 0, y: 0, backgroundColor: "white" }) {
|
||||||
@ -98,8 +108,16 @@ function createWindow(options = { x: 0, y: 0, backgroundColor: "white" }) {
|
|||||||
registerHttpProtocols();
|
registerHttpProtocols();
|
||||||
syncMenuBarWithStore();
|
syncMenuBarWithStore();
|
||||||
|
|
||||||
// load the Tidal website
|
// find the custom protocol argument
|
||||||
mainWindow.loadURL(tidalUrl);
|
const customProtocolUrl = getCustomProtocolUrl(process.argv);
|
||||||
|
|
||||||
|
if(customProtocolUrl) {
|
||||||
|
// load the url received from the custom protocol
|
||||||
|
mainWindow.loadURL(customProtocolUrl);
|
||||||
|
} else {
|
||||||
|
// load the Tidal website
|
||||||
|
mainWindow.loadURL(tidalUrl);
|
||||||
|
}
|
||||||
|
|
||||||
if (settingsStore.get(settings.disableBackgroundThrottle)) {
|
if (settingsStore.get(settings.disableBackgroundThrottle)) {
|
||||||
// prevent setInterval lag
|
// prevent setInterval lag
|
||||||
@ -139,9 +157,6 @@ function createWindow(options = { x: 0, y: 0, backgroundColor: "white" }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function registerHttpProtocols() {
|
function registerHttpProtocols() {
|
||||||
protocol.registerHttpProtocol(PROTOCOL_PREFIX, (request) => {
|
|
||||||
mainWindow.loadURL(`${tidalUrl}/${request.url.substring(PROTOCOL_PREFIX.length + 3)}`);
|
|
||||||
});
|
|
||||||
if (!app.isDefaultProtocolClient(PROTOCOL_PREFIX)) {
|
if (!app.isDefaultProtocolClient(PROTOCOL_PREFIX)) {
|
||||||
app.setAsDefaultProtocolClient(PROTOCOL_PREFIX);
|
app.setAsDefaultProtocolClient(PROTOCOL_PREFIX);
|
||||||
}
|
}
|
||||||
@ -159,7 +174,24 @@ function addGlobalShortcuts() {
|
|||||||
// initialization and is ready to create browser windows.
|
// initialization and is ready to create browser windows.
|
||||||
// Some APIs can only be used after this event occurs.
|
// Some APIs can only be used after this event occurs.
|
||||||
app.on("ready", async () => {
|
app.on("ready", async () => {
|
||||||
if (isMainInstanceOrMultipleInstancesAllowed()) {
|
|
||||||
|
// check if the app is the main instance and multiple instances are not allowed
|
||||||
|
if (isMainInstance() && !isMultipleInstancesAllowed()) {
|
||||||
|
app.on('second-instance', (_, commandLine) => {
|
||||||
|
const customProtocolUrl = getCustomProtocolUrl(commandLine);
|
||||||
|
|
||||||
|
if (customProtocolUrl) {
|
||||||
|
mainWindow.loadURL(customProtocolUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mainWindow) {
|
||||||
|
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||||
|
mainWindow.focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMainInstance() || isMultipleInstancesAllowed()) {
|
||||||
await components.whenReady();
|
await components.whenReady();
|
||||||
|
|
||||||
// Adblock
|
// Adblock
|
||||||
|
Loading…
Reference in New Issue
Block a user