Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions first-run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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', '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;
}

fs.outputFileSync(configPath, '');
} catch (error) {
console.warn(`First run: Unable to write firstRun file`, error);
}

return true;
}

module.exports = { onFirstRunMaybe }

8 changes: 6 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { ipcMain } = require('electron');
const { ipcMain, app } = require('electron');
const { menubar } = require('menubar');
const { autoUpdater } = require('electron-updater');
const { onFirstRunMaybe } = require('./first-run');
const path = require('path');

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

const browserWindowOpts = {
width: 500,
Expand All @@ -19,6 +19,10 @@ const browserWindowOpts = {
},
};

app.on('ready', async () => {
await onFirstRunMaybe();
})

const menubarApp = menubar({
icon: iconIdle,
index: `file://${__dirname}/index.html`,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
"assets/**/*",
"index.html",
"LICENSE",
"main.js"
"main.js",
"first-run.js"
],
"mac": {
"category": "public.app-category.developer-tools",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"typeRoots": ["./src/types", "node_modules/@types"]
},
"exclude": ["node_modules"],
"include": ["src/**/*.js", "src/**/*.ts", "src/**/*.tsx"]
"include": ["src/**/*.js", "src/**/*.ts", "src/**/*.tsx", "first-run.js", "main.js"]
}