Skip to content

Commit

Permalink
chore: added wait for ShipIt process to complete in app.on("ready"
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Villa committed Feb 9, 2024
1 parent 2bd007f commit 33b29bb
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 9 deletions.
30 changes: 24 additions & 6 deletions packages/desktop-app/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { environment } from "../src/environments/environment";
import * as https from "https";
import * as http from "http";
import { execFile as child } from "child_process";
import findProcess from 'find-process';
import Electron from "electron";

const { app, BrowserWindow, ipcMain, Tray, Menu, dialog } = require("electron");
const electronLocalshortcut = require('electron-localshortcut');
Expand Down Expand Up @@ -138,10 +140,7 @@ const buildAutoUpdater = (win: any): void => {
message: 'A new update has been downloaded. Would you like to install and restart the app now?'
}).then(async (selection) => {
if (selection.response === 0) {
setTimeout(() => {
autoUpdater.quitAndInstall();
app.exit();
}, 10000);
autoUpdater.quitAndInstall();
}
});
});
Expand Down Expand Up @@ -322,11 +321,30 @@ const generateMainWindow = () => {
forceQuit = true;
});

app.on("ready", () => {
app.on("ready", async () => {
createWindow();
// createTray();
buildAutoUpdater(win);

let isShipItStillRunning = true;
let shouldRestartBeforeLaunch = false;

while (isShipItStillRunning) {
const shipItProcesses = await findProcess("name", "ShipIt");
if (shipItProcesses.some(f => f.cmd.includes("com.leapp.app"))) {
// if we don't restart, the old app from memory will keep running
shouldRestartBeforeLaunch = true;
console.debug("Waiting for auto update to finish");
} else {
isShipItStillRunning = false;
}
}

if (shouldRestartBeforeLaunch) {
app.relaunch();
app.exit(0);
}

buildAutoUpdater(win);
});

// when the app on macOS is starting for the first time the frontend is not ready so we use 'will-finish-launching'
Expand Down
137 changes: 134 additions & 3 deletions packages/desktop-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/desktop-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
"electron-updater": "4.6.5",
"emoji-regex": "^8.0.0",
"extract-zip": "~2.0.1",
"find-process": "^1.4.7",
"fix-path": "~3.0.0",
"folder-hash": "^4.0.2",
"follow-redirects": "1.15.4",
Expand Down

0 comments on commit 33b29bb

Please sign in to comment.