|
| 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 | + |
0 commit comments