[FirstRun > win32] Various minor rewrites
This commit is contained in:
parent
50907d05e1
commit
a5cf9aa76b
|
@ -1,36 +1,33 @@
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { join, resolve, basename } = require('path');
|
const { join, resolve, basename } = require('path');
|
||||||
|
|
||||||
const paths = require('../paths');
|
|
||||||
const registry = require('../utils/registry');
|
const registry = require('../utils/registry');
|
||||||
const Constants = require('../Constants');
|
const Constants = require('../Constants');
|
||||||
|
|
||||||
const appPath = resolve(process.execPath, '..');
|
const appPath = resolve(process.execPath, '..');
|
||||||
const rootPath = resolve(appPath, '..');
|
const rootPath = resolve(appPath, '..');
|
||||||
|
|
||||||
const iconFile = 'app.ico';
|
const rootIcon = () => {
|
||||||
const copyIconToRoot = () => {
|
const c = join(appPath, 'app.ico'); // Current
|
||||||
const currentPath = join(appPath, iconFile);
|
const n = join(rootPath, 'app.ico'); // New
|
||||||
const newPath = join(rootPath, iconFile);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.copyFileSync(currentPath, newPath);
|
fs.copyFileSync(c, n);
|
||||||
return newPath;
|
return n;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('FirstRun', 'Failed to copy icon to root', e);
|
log('FirstRun', e);
|
||||||
return currentPath;
|
return c;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateShortcuts = (updater) => {
|
const updateShortcuts = (updater) => {
|
||||||
try {
|
try {
|
||||||
const filename = Constants.APP_NAME_FOR_HUMANS + '.lnk';
|
const file = Constants.APP_NAME_FOR_HUMANS + '.lnk';
|
||||||
|
const icon_path = rootIcon();
|
||||||
const icon_path = copyIconToRoot();
|
|
||||||
|
|
||||||
for (const shortcut_path of [
|
for (const shortcut_path of [
|
||||||
join(updater.getKnownFolder('desktop'), filename),
|
join(updater.getKnownFolder('desktop'), file),
|
||||||
join(updater.getKnownFolder('programs'), Constants.APP_COMPANY, filename)
|
join(updater.getKnownFolder('programs'), Constants.APP_COMPANY, file)
|
||||||
]) {
|
]) {
|
||||||
if (!fs.existsSync(shortcut_path)) continue; // Don't update already deleted paths
|
if (!fs.existsSync(shortcut_path)) continue; // Don't update already deleted paths
|
||||||
|
|
||||||
|
@ -48,25 +45,22 @@ const updateShortcuts = (updater) => {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('FirstRun', 'Shortcuts error', e);
|
log('FirstRun', e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.performFirstRunTasks = (updater) => {
|
|
||||||
log('FirstRun', 'Perform');
|
|
||||||
|
|
||||||
const flagPath = join(paths.getUserDataVersioned(), '.first-run');
|
exports.do = (updater) => {
|
||||||
if (fs.existsSync(flagPath)) return; // Already done, skip
|
const flag = join(appPath, '.first-run');
|
||||||
|
if (fs.existsSync(flag)) return; // Already done, skip
|
||||||
const shortcutSuccess = updateShortcuts(updater);
|
|
||||||
|
|
||||||
registry.installProtocol(Constants.APP_PROTOCOL, () => {
|
registry.installProtocol(Constants.APP_PROTOCOL, () => {
|
||||||
if (!shortcutSuccess) return;
|
if (!updateShortcuts(updater)) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.writeFileSync(flagPath, 'true');
|
fs.writeFileSync(flag, 'true');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('FirstRun', 'Error writing .first-run', e);
|
log('FirstRun', e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
Loading…
Reference in New Issue