Skip to content

Commit d0ca1a0

Browse files
authored
Merge pull request #418 from codebytere/move-to-applications-folder
feat: move to app folder on first run
2 parents a01e140 + 3be8999 commit d0ca1a0

File tree

4 files changed

+63
-4
lines changed

4 files changed

+63
-4
lines changed

first-run.js

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

main.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const { ipcMain } = require('electron');
1+
const { ipcMain, app } = require('electron');
22
const { menubar } = require('menubar');
33
const { autoUpdater } = require('electron-updater');
4+
const { onFirstRunMaybe } = require('./first-run');
45
const path = require('path');
56

67
const iconIdle = path.join(__dirname, 'assets', 'images', 'tray-idleTemplate.png');
78
const iconActive = path.join(__dirname, 'assets', 'images', 'tray-active.png');
8-
const isDarwin = process.platform === 'darwin';
99

1010
const browserWindowOpts = {
1111
width: 500,
@@ -19,6 +19,10 @@ const browserWindowOpts = {
1919
},
2020
};
2121

22+
app.on('ready', async () => {
23+
await onFirstRunMaybe();
24+
})
25+
2226
const menubarApp = menubar({
2327
icon: iconIdle,
2428
index: `file://${__dirname}/index.html`,

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
"assets/**/*",
7070
"index.html",
7171
"LICENSE",
72-
"main.js"
72+
"main.js",
73+
"first-run.js"
7374
],
7475
"mac": {
7576
"category": "public.app-category.developer-tools",

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
"typeRoots": ["./src/types", "node_modules/@types"]
1212
},
1313
"exclude": ["node_modules"],
14-
"include": ["src/**/*.js", "src/**/*.ts", "src/**/*.tsx"]
14+
"include": ["src/**/*.js", "src/**/*.ts", "src/**/*.tsx", "first-run.js", "main.js"]
1515
}

0 commit comments

Comments
 (0)