Skip to content

Commit 8366437

Browse files
committed
Add squirrel handler
1 parent 9058301 commit 8366437

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

main.js

+51-1
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,54 @@ ipcMain.handle('install-package', async (event, aPackage, serialPort, compileFil
9595
console.error(`Failed to install package ${packageDesignator}:`, error);
9696
return { success: false, error: error.message };
9797
}
98-
});
98+
});
99+
100+
// Handle auto updater events
101+
function handleSquirrelEvent() {
102+
if (process.argv.length === 1) {
103+
return false;
104+
}
105+
106+
const ChildProcess = require('child_process');
107+
108+
const appFolder = path.resolve(process.execPath, '..');
109+
const rootAtomFolder = path.resolve(appFolder, '..');
110+
const updateDotExe = path.resolve(path.join(rootAtomFolder, 'Update.exe'));
111+
const exeName = path.basename(process.execPath);
112+
113+
const spawn = function (command, args) {
114+
let spawnedProcess, error;
115+
116+
try {
117+
spawnedProcess = ChildProcess.spawn(command, args, { detached: true });
118+
} catch (error) { }
119+
120+
return spawnedProcess;
121+
};
122+
123+
const spawnUpdate = function (args) {
124+
return spawn(updateDotExe, args);
125+
};
126+
127+
const squirrelEvent = process.argv[1];
128+
switch (squirrelEvent) {
129+
case '--squirrel-install':
130+
case '--squirrel-updated':
131+
// Install desktop and start menu shortcuts
132+
spawnUpdate(['--createShortcut', exeName]);
133+
setTimeout(app.quit, 1000);
134+
return true;
135+
case '--squirrel-uninstall':
136+
// Remove desktop and start menu shortcuts
137+
spawnUpdate(['--removeShortcut', exeName]);
138+
setTimeout(app.quit, 1000);
139+
return true;
140+
141+
case '--squirrel-obsolete':
142+
// This is called on the outgoing version of your app before
143+
// we update to the new version - it's the opposite of
144+
// --squirrel-updated
145+
app.quit();
146+
return true;
147+
}
148+
};

0 commit comments

Comments
 (0)