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
|
|
|
|
2022-04-27 20:54:08 +00:00
|
|
|
const Constants = require('./Constants');
|
2022-04-30 11:13:49 +00:00
|
|
|
const reg = (a, c) => require('child_process').execFile('reg.exe', a, c);
|
2021-12-13 08:11:10 +00:00
|
|
|
|
2022-04-12 17:18:47 +00:00
|
|
|
const exec = process.execPath;
|
|
|
|
const app = resolve(exec, '..');
|
2022-04-12 17:12:42 +00:00
|
|
|
const root = resolve(app, '..');
|
2021-12-13 08:11:10 +00:00
|
|
|
|
|
|
|
|
2022-03-25 22:54:40 +00:00
|
|
|
exports.do = (updater) => {
|
2022-04-12 17:12:42 +00:00
|
|
|
const flag = join(app, '.first-run');
|
2022-03-25 22:54:40 +00:00
|
|
|
if (fs.existsSync(flag)) return; // Already done, skip
|
2021-12-13 08:11:10 +00:00
|
|
|
|
2022-04-12 17:12:42 +00:00
|
|
|
const proto = Constants.APP_PROTOCOL;
|
|
|
|
const base = 'HKCU\\Software\\Classes\\' + proto;
|
|
|
|
|
2022-04-29 22:15:34 +00:00
|
|
|
for (const x of [
|
2022-04-30 11:06:27 +00:00
|
|
|
[base, '/ve', '/d', `URL:${proto} Protocol`],
|
|
|
|
[base, '/v', 'URL Protocol'],
|
2022-04-29 22:15:34 +00:00
|
|
|
[base + '\\DefaultIcon', '/ve', '/d', `"${exec}",-1`],
|
|
|
|
[base + '\\shell\\open\\command', '/ve', '/d', `"${exec}" --url -- "%1"`]
|
|
|
|
]) reg([ 'add', ...x, '/f' ], e => {});
|
|
|
|
|
|
|
|
try { // Make shortcuts
|
|
|
|
const file = Constants.APP_NAME_FOR_HUMANS + '.lnk';
|
|
|
|
const icon_path = join(root, 'app.ico');
|
|
|
|
|
|
|
|
fs.copyFileSync(join(app, 'app.ico'), icon_path); // app-1.0.0/app.ico -> app.ico
|
|
|
|
|
|
|
|
for (const shortcut_path of [
|
|
|
|
join(updater.getKnownFolder('desktop'), file),
|
|
|
|
join(updater.getKnownFolder('programs'), Constants.APP_COMPANY, file)
|
|
|
|
]) {
|
|
|
|
if (!fs.existsSync(shortcut_path)) continue; // Don't update already deleted paths
|
|
|
|
|
|
|
|
updater.createShortcut({
|
|
|
|
target_path: join(root, 'Update.exe'),
|
|
|
|
shortcut_path,
|
|
|
|
arguments: '--processStart ' + basename(exec),
|
|
|
|
icon_path,
|
|
|
|
icon_index: 0,
|
|
|
|
description: Constants.APP_DESCRIPTION,
|
|
|
|
app_user_model_id: Constants.APP_ID,
|
|
|
|
working_directory: app
|
|
|
|
});
|
2021-12-13 08:11:10 +00:00
|
|
|
}
|
2022-04-29 22:15:34 +00:00
|
|
|
|
|
|
|
fs.writeFileSync(flag, 'true');
|
|
|
|
} catch (e) {
|
|
|
|
log('FirstRun', e);
|
|
|
|
}
|
2022-01-29 11:12:39 +00:00
|
|
|
};
|