-
Notifications
You must be signed in to change notification settings - Fork 14
/
first-run.js
53 lines (41 loc) · 1.26 KB
/
first-run.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const { app, dialog } = require('electron');
const fs = require('fs-extra');
const path = require('path');
async function onFirstRunMaybe() {
if (isFirstRun()) {
await promptMoveToApplicationsFolder();
}
}
// Ask user if the app should be moved to the applications folder.
async function promptMoveToApplicationsFolder() {
if (process.platform !== 'darwin') return;
const isDevMode = !!process.defaultApp;
if (isDevMode || app.isInApplicationsFolder()) return;
const { response } = await dialog.showMessageBox({
type: 'question',
buttons: ['Move to Applications Folder', 'Do Not Move'],
defaultId: 0,
message: 'Move to Applications Folder?',
});
if (response === 0) {
app.moveToApplicationsFolder();
}
}
const getConfigPath = () => {
const userDataPath = app.getPath('userData');
return path.join(userDataPath, 'FirstRun', 'instatus-out-first-run');
};
// Whether or not the app is being run for the first time.
function isFirstRun() {
const configPath = getConfigPath();
try {
if (fs.existsSync(configPath)) {
return false;
}
fs.outputFileSync(configPath, '');
} catch (error) {
console.warn(`First run: Unable to write firstRun file`, error);
}
return true;
}
module.exports = { onFirstRunMaybe };