2021-12-13 08:11:10 +00:00
|
|
|
const fs = require('fs');
|
2022-01-29 11:12:39 +00:00
|
|
|
const { join, resolve, basename } = require('path');
|
2022-03-10 08:46:09 +00:00
|
|
|
|
|
|
|
const registry = require('../utils/registry');
|
2021-12-13 08:11:10 +00:00
|
|
|
const Constants = require('../Constants');
|
|
|
|
|
2022-01-29 11:12:39 +00:00
|
|
|
const appPath = resolve(process.execPath, '..');
|
|
|
|
const rootPath = resolve(appPath, '..');
|
2021-12-13 08:11:10 +00:00
|
|
|
|
2022-03-25 22:54:40 +00:00
|
|
|
const rootIcon = () => {
|
|
|
|
const c = join(appPath, 'app.ico'); // Current
|
|
|
|
const n = join(rootPath, 'app.ico'); // New
|
2021-12-13 08:11:10 +00:00
|
|
|
|
|
|
|
try {
|
2022-03-25 22:54:40 +00:00
|
|
|
fs.copyFileSync(c, n);
|
|
|
|
return n;
|
2021-12-13 08:11:10 +00:00
|
|
|
} catch (e) {
|
2022-03-25 22:54:40 +00:00
|
|
|
log('FirstRun', e);
|
|
|
|
return c;
|
2021-12-13 08:11:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const updateShortcuts = (updater) => {
|
2022-03-14 09:33:27 +00:00
|
|
|
try {
|
2022-03-25 22:54:40 +00:00
|
|
|
const file = Constants.APP_NAME_FOR_HUMANS + '.lnk';
|
|
|
|
const icon_path = rootIcon();
|
2021-12-13 08:11:10 +00:00
|
|
|
|
2022-03-14 09:33:27 +00:00
|
|
|
for (const shortcut_path of [
|
2022-03-25 22:54:40 +00:00
|
|
|
join(updater.getKnownFolder('desktop'), file),
|
|
|
|
join(updater.getKnownFolder('programs'), Constants.APP_COMPANY, file)
|
2022-03-14 09:33:27 +00:00
|
|
|
]) {
|
|
|
|
if (!fs.existsSync(shortcut_path)) continue; // Don't update already deleted paths
|
2021-12-13 08:11:10 +00:00
|
|
|
|
2022-03-14 09:33:27 +00:00
|
|
|
updater.createShortcut({
|
|
|
|
target_path: join(rootPath, 'Update.exe'),
|
|
|
|
shortcut_path,
|
|
|
|
arguments: '--processStart ' + basename(process.execPath),
|
|
|
|
icon_path,
|
|
|
|
icon_index: 0,
|
|
|
|
description: Constants.APP_DESCRIPTION,
|
|
|
|
app_user_model_id: Constants.APP_ID,
|
|
|
|
working_directory: appPath
|
|
|
|
});
|
|
|
|
}
|
2022-03-11 13:22:46 +00:00
|
|
|
|
2022-03-14 09:33:27 +00:00
|
|
|
return true;
|
|
|
|
} catch (e) {
|
2022-03-25 22:54:40 +00:00
|
|
|
log('FirstRun', e);
|
2022-03-14 09:33:27 +00:00
|
|
|
}
|
2021-12-13 08:11:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-03-25 22:54:40 +00:00
|
|
|
exports.do = (updater) => {
|
|
|
|
const flag = join(appPath, '.first-run');
|
|
|
|
if (fs.existsSync(flag)) return; // Already done, skip
|
2021-12-13 08:11:10 +00:00
|
|
|
|
2022-03-11 12:49:39 +00:00
|
|
|
registry.installProtocol(Constants.APP_PROTOCOL, () => {
|
2022-03-25 22:54:40 +00:00
|
|
|
if (!updateShortcuts(updater)) return;
|
2022-01-28 20:06:36 +00:00
|
|
|
|
|
|
|
try {
|
2022-03-25 22:54:40 +00:00
|
|
|
fs.writeFileSync(flag, 'true');
|
2022-01-28 20:06:36 +00:00
|
|
|
} catch (e) {
|
2022-03-25 22:54:40 +00:00
|
|
|
log('FirstRun', e);
|
2021-12-13 08:11:10 +00:00
|
|
|
}
|
|
|
|
});
|
2022-01-29 11:12:39 +00:00
|
|
|
};
|