2016-10-18 08:59:33 +08:00
|
|
|
import {ipcRenderer, remote} from 'electron'
|
2016-08-17 07:58:13 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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!).
|
|
|
|
*/
|
|
|
|
|
2016-10-04 23:02:11 +08:00
|
|
|
function onDialogActionTaken(numAsks) {
|
2016-08-19 00:57:48 +08:00
|
|
|
return (buttonIndex) => {
|
|
|
|
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)
|
|
|
|
}
|
2016-08-17 08:36:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function activate() {
|
|
|
|
if (NylasEnv.inDevMode() || NylasEnv.inSpecMode()) { return; }
|
2016-08-17 07:58:13 +08:00
|
|
|
|
2016-08-17 08:36:46 +08:00
|
|
|
if (process.platform !== "darwin") { return; }
|
2016-08-17 07:58:13 +08:00
|
|
|
|
2016-08-17 08:36:46 +08:00
|
|
|
const appRe = /Applications/gi;
|
|
|
|
if (appRe.test(process.argv[0])) { return; }
|
2016-08-17 07:58:13 +08:00
|
|
|
|
2016-08-17 08:36:46 +08:00
|
|
|
// 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;
|
|
|
|
}
|
2016-08-17 07:58:13 +08:00
|
|
|
|
2017-01-17 04:31:08 +08:00
|
|
|
const numAsks = NylasEnv.config.get("asksAboutAppMove") || 0
|
|
|
|
if (numAsks <= 0) {
|
|
|
|
NylasEnv.config.set("asksAboutAppMove", 1)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NylasEnv.config.set("asksAboutAppMove", numAsks + 1)
|
2016-08-17 08:36:46 +08:00
|
|
|
if (numAsks >= 5) return;
|
2016-08-17 07:58:13 +08:00
|
|
|
|
2016-08-19 00:57:48 +08:00
|
|
|
let buttons;
|
2016-08-17 08:36:46 +08:00
|
|
|
if (numAsks >= 1) {
|
2016-08-19 00:57:48 +08:00
|
|
|
buttons = [
|
2017-01-17 04:31:08 +08:00
|
|
|
"Okay",
|
2016-08-19 00:57:48 +08:00
|
|
|
"Don't ask again",
|
|
|
|
]
|
|
|
|
} else {
|
|
|
|
buttons = [
|
2017-01-17 04:31:08 +08:00
|
|
|
"Okay",
|
2016-08-19 00:57:48 +08:00
|
|
|
]
|
2016-08-17 08:36:46 +08:00
|
|
|
}
|
2016-08-17 07:58:13 +08:00
|
|
|
|
2017-01-12 09:41:07 +08:00
|
|
|
const msg = `We recommend that you move Nylas Mail to your Applications folder to get updates correctly and keep this folder uncluttered.`
|
2016-08-17 08:36:46 +08:00
|
|
|
|
2017-01-17 04:31:08 +08:00
|
|
|
const CANCEL_ID = 0;
|
2016-08-19 00:57:48 +08:00
|
|
|
|
2016-10-18 08:59:33 +08:00
|
|
|
remote.dialog.showMessageBox({
|
2017-01-17 04:31:08 +08:00
|
|
|
type: "warning",
|
2016-08-19 00:57:48 +08:00
|
|
|
buttons: buttons,
|
2017-01-12 09:41:07 +08:00
|
|
|
title: "A Better Place to Install Nylas Mail",
|
2017-01-17 04:31:08 +08:00
|
|
|
message: "Please move Nylas Mail to your Applications folder",
|
2016-08-19 00:57:48 +08:00
|
|
|
detail: msg,
|
|
|
|
defaultId: 0,
|
|
|
|
cancelId: CANCEL_ID,
|
2016-10-04 23:02:11 +08:00
|
|
|
}, onDialogActionTaken(numAsks))
|
2016-08-17 08:36:46 +08:00
|
|
|
}
|
2016-08-17 07:58:13 +08:00
|
|
|
|
2016-08-17 08:36:46 +08:00
|
|
|
export function deactivate() {
|
2016-08-17 07:58:13 +08:00
|
|
|
}
|