-
Notifications
You must be signed in to change notification settings - Fork 272
/
Copy pathfirst-run.ts
57 lines (45 loc) · 1.38 KB
/
first-run.ts
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
54
55
56
57
import fs from 'node:fs';
import path from 'node:path';
import { app, dialog } from 'electron';
import { logError } from '../shared/logger';
export 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', 'gitify-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;
}
const firstRunFolder = path.dirname(configPath);
if (!fs.existsSync(firstRunFolder)) {
fs.mkdirSync(firstRunFolder);
}
fs.writeFileSync(configPath, '');
} catch (err) {
logError('isFirstRun', 'Unable to write firstRun file', err);
}
return true;
}