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
|
|
|
|
2021-12-13 08:11:10 +00:00
|
|
|
const paths = require('../paths');
|
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
|
|
|
|
|
|
|
const iconFile = 'app.ico';
|
|
|
|
const copyIconToRoot = () => {
|
2022-01-29 11:12:39 +00:00
|
|
|
const currentPath = join(appPath, iconFile);
|
|
|
|
const newPath = join(rootPath, iconFile);
|
2021-12-13 08:11:10 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
fs.copyFileSync(currentPath, newPath);
|
|
|
|
return newPath;
|
|
|
|
} catch (e) {
|
|
|
|
log('FirstRun', 'Failed to copy icon to root', e);
|
|
|
|
return currentPath;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const updateShortcuts = (updater) => {
|
|
|
|
const filename = Constants.APP_NAME_FOR_HUMANS + '.lnk';
|
|
|
|
|
2022-03-11 13:22:46 +00:00
|
|
|
const icon_path = copyIconToRoot();
|
2021-12-13 08:11:10 +00:00
|
|
|
|
2022-03-11 13:22:46 +00:00
|
|
|
for (const shortcut_path of [
|
|
|
|
join(updater.getKnownFolder('desktop'), filename),
|
|
|
|
join(updater.getKnownFolder('programs'), Constants.APP_COMPANY, filename)
|
|
|
|
]) {
|
2021-12-13 08:11:10 +00:00
|
|
|
if (!fs.existsSync(path)) continue; // Don't update already deleted paths
|
|
|
|
|
|
|
|
updater.createShortcut({
|
2022-01-29 11:12:39 +00:00
|
|
|
target_path: join(rootPath, 'Update.exe'),
|
2022-03-11 13:22:46 +00:00
|
|
|
shortcut_path,
|
2022-01-29 11:12:39 +00:00
|
|
|
arguments: '--processStart ' + basename(process.execPath),
|
2022-03-11 13:22:46 +00:00
|
|
|
icon_path,
|
2021-12-13 08:11:10 +00:00
|
|
|
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
|
|
|
|
|
|
|
return true;
|
2021-12-13 08:11:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.performFirstRunTasks = (updater) => {
|
2021-12-13 19:02:18 +00:00
|
|
|
log('FirstRun', 'Perform');
|
|
|
|
|
2022-01-29 11:12:39 +00:00
|
|
|
const flagPath = join(paths.getUserDataVersioned(), '.first-run');
|
|
|
|
if (fs.existsSync(flagPath)) return; // Already done, skip
|
2021-12-13 08:11:10 +00:00
|
|
|
|
|
|
|
let shortcutSuccess = false;
|
|
|
|
try {
|
2022-03-11 13:22:46 +00:00
|
|
|
shortcutSuccess = updateShortcuts(updater);
|
2021-12-13 08:11:10 +00:00
|
|
|
} catch (e) {
|
|
|
|
log('FirstRun', 'Error updating shortcuts', e);
|
|
|
|
}
|
|
|
|
|
2022-03-11 12:49:39 +00:00
|
|
|
registry.installProtocol(Constants.APP_PROTOCOL, () => {
|
2022-01-28 20:06:36 +00:00
|
|
|
if (!shortcutSuccess) return;
|
|
|
|
|
|
|
|
try {
|
2022-02-16 09:10:18 +00:00
|
|
|
fs.writeFileSync(flagPath, 'true');
|
2022-01-28 20:06:36 +00:00
|
|
|
} catch (e) {
|
|
|
|
log('FirstRun', 'Error writing .first-run', e);
|
2021-12-13 08:11:10 +00:00
|
|
|
}
|
|
|
|
});
|
2022-01-29 11:12:39 +00:00
|
|
|
};
|