Mailspring/internal_packages/verify-install-location/lib/main.es6
Halla Moore 9e3c3c14cd feat(sidebar-notifs) Create sidebar notifications to replace old bars
Summary:
Move the old bar notifications to the sidebar, and only display one notification
at a time using a priority-rating system. Remove all of the old notification
infrastructure.

Test Plan: Added specs, also reproduced notifications locally

Reviewers: bengotow

Reviewed By: bengotow

Subscribers: juan

Differential Revision: https://phab.nylas.com/D3310
2016-10-04 08:08:23 -07:00

82 lines
2 KiB
JavaScript

const {dialog} = require('electron').remote
import {ipcRenderer} from 'electron'
/**
* We want to make sure that people have installed the app in a
* reasonable location.
*
* On the Mac, you can accidentally run the app from the DMG. If you do
* this, it will no longer auto-update. It's also common for Mac users to
* leave their app in the /Downloads folder (which frequently gets
* erased!).
*/
function onDialogActionTaken(numAsks) {
return (buttonIndex) => {
if (buttonIndex === 0) {
ipcRenderer.send("move-to-applications")
}
if (numAsks >= 1) {
if (buttonIndex === 1) {
NylasEnv.config.set("asksAboutAppMove", 5)
} else {
NylasEnv.config.set("asksAboutAppMove", numAsks + 1)
}
} else {
NylasEnv.config.set("asksAboutAppMove", numAsks + 1)
}
}
}
export function activate() {
if (NylasEnv.inDevMode() || NylasEnv.inSpecMode()) { return; }
if (process.platform !== "darwin") { return; }
const appRe = /Applications/gi;
if (appRe.test(process.argv[0])) { return; }
// If we're in Volumes, that means we've launched from the DMG. This
// is unsupported. We should optimistically move.
const volTest = /Volumes/gi;
if (volTest.test(process.argv[0])) {
ipcRenderer.send("move-to-applications");
return;
}
const numAsks = NylasEnv.config.get("asksAboutAppMove")
if (numAsks >= 5) return;
let buttons;
if (numAsks >= 1) {
buttons = [
"Move to Applications folder",
"Don't ask again",
"Do not move",
]
} else {
buttons = [
"Move to Applications folder",
"Do not move",
]
}
const msg = `We recommend that you move N1 to your Applications folder to get updates correctly and keep this folder uncluttered.`
const CANCEL_ID = 3;
dialog.showMessageBox({
type: "question",
buttons: buttons,
title: "A Better Place to Install N1",
message: "Move to Applications folder?",
detail: msg,
defaultId: 0,
cancelId: CANCEL_ID,
}, onDialogActionTaken(numAsks))
}
export function deactivate() {
}