Skip to content

Commit

Permalink
fix portable app restart
Browse files Browse the repository at this point in the history
  • Loading branch information
Araxeus committed Feb 24, 2022
1 parent 4078872 commit 704fba9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 24 deletions.
11 changes: 3 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { fileExists, injectCSS } = require("./plugins/utils");
const { isTesting } = require("./utils/testing");
const { setUpTray } = require("./tray");
const { setupSongInfo } = require("./providers/song-info");
const { setupAppControls } = require("./providers/app-controls");
const { setupAppControls, restart } = require("./providers/app-controls");

// Catch errors and log them
unhandled({
Expand Down Expand Up @@ -435,13 +435,8 @@ function showUnresponsiveDialog(win, details) {
cancelId: 0
}).then( result => {
switch (result.response) {
case 1: //if relaunch - relaunch+exit
app.relaunch();
case 2:
app.quit();
break;
default:
break;
case 1: restart(); break;
case 2: app.quit(); break;
}
});
}
Expand Down
6 changes: 2 additions & 4 deletions menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require("path");

const { app, Menu, dialog } = require("electron");
const is = require("electron-is");
const { restart } = require("./providers/app-controls");

const { getAllPlugins } = require("./plugins/utils");
const config = require("./config");
Expand Down Expand Up @@ -279,10 +280,7 @@ const mainMenuTemplate = (win) => {
},
{
label: "Restart App",
click: () => {
app.relaunch();
app.quit();
},
click: restart
},
{ role: "quit" },
],
Expand Down
6 changes: 1 addition & 5 deletions preload.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const path = require("path");

require("./providers/front-logger")();
const config = require("./config");
const { fileExists } = require("./plugins/utils");
const setupFrontLogger = require("./providers/front-logger");
const setupSongInfo = require("./providers/song-info-front");
const { setupSongControls } = require("./providers/song-controls-front");
const { ipcRenderer } = require("electron");
Expand Down Expand Up @@ -48,9 +47,6 @@ document.addEventListener("DOMContentLoaded", () => {
// inject song-controls
setupSongControls();

// inject front logger
setupFrontLogger();

// Add action for reloading
global.reload = () => ipcRenderer.send('reload');

Expand Down
5 changes: 3 additions & 2 deletions providers/app-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports.setupAppControls = () => {
}

function restart() {
app.relaunch();
app.exit();
app.relaunch({ execPath: process.env.PORTABLE_EXECUTABLE_FILE });
// execPath will be undefined if not running portable app, resulting in default behavior
app.quit();
}
8 changes: 3 additions & 5 deletions tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require("path");

const { Menu, nativeImage, Tray } = require("electron");

const { restart } = require("./providers/app-controls");
const config = require("./config");
const getSongControls = require("./providers/song-controls");

Expand Down Expand Up @@ -58,12 +59,9 @@ module.exports.setUpTray = (app, win) => {
},
{
label: "Restart App",
click: () => {
app.relaunch();
app.quit();
},
click: restart
},
{ role: "quit" }
{ role: "quit" }
];

const trayMenu = Menu.buildFromTemplate(template);
Expand Down

0 comments on commit 704fba9

Please sign in to comment.