diff --git a/internal_packages/verify-install-location/lib/main.es6 b/internal_packages/verify-install-location/lib/main.es6 index 5598c32e0..2d95333c6 100644 --- a/internal_packages/verify-install-location/lib/main.es6 +++ b/internal_packages/verify-install-location/lib/main.es6 @@ -1,4 +1,4 @@ -import {Actions} from 'nylas-exports' +const {dialog} = require('electron').remote import {ipcRenderer} from 'electron' /** @@ -11,22 +11,25 @@ import {ipcRenderer} from 'electron' * erased!). */ -let unlisten = () => {} +function onNotificationActionTaken(numAsks) { + return (buttonIndex) => { + if (buttonIndex === 0) { + ipcRenderer.send("move-to-applications") + } -function onNotificationActionTaken({action}) { - if (action.id === "verify-install:dont-ask-again") { - NylasEnv.config.set("asksAboutAppMove", 5) - } else if (action.id === "verify-install:do-not-move") { - const numAsks = NylasEnv.config.get("asksAboutAppMove") || 0 - NylasEnv.config.set("asksAboutAppMove", numAsks + 1) - } else if (action.id === "verify-install:move-to-applications") { - 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() { - unlisten = Actions.notificationActionTaken.listen(onNotificationActionTaken) - if (NylasEnv.inDevMode() || NylasEnv.inSpecMode()) { return; } if (process.platform !== "darwin") { return; } @@ -45,13 +48,18 @@ export function activate() { const numAsks = NylasEnv.config.get("asksAboutAppMove") if (numAsks >= 5) return; - const actions = [] + let buttons; if (numAsks >= 1) { - actions.push({ - label: "Don't ask again", - dismisses: true, - id: 'verify-install:dont-ask-again', - }) + buttons = [ + "Move to Applications Folder", + "Don't ask again", + "Do Not Move", + ] + } else { + buttons = [ + "Move to Applications Folder", + "Do Not Move", + ] } const re = /(^.*?\.app)/i; @@ -63,28 +71,18 @@ export function activate() { msg += ` This will keep your ${enclosingFolder} folder uncluttered.` } - Actions.postNotification({ - type: 'info', - tag: 'app-update', - sticky: true, - message: msg, - icon: 'fa-flag', - actions: actions.concat([ - { - label: "Do Not Move", - dismisses: true, - id: 'verify-install:do-not-move', - }, - { - "label": "Move to Applications Folder", - "dismisses": true, - "default": true, - "id": 'verify-install:move-to-applications', - }, - ]), - }); + 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, + }, onNotificationActionTaken(numAsks)) } export function deactivate() { - unlisten() } diff --git a/src/browser/application.es6 b/src/browser/application.es6 index 446f9cba6..98abc9fc7 100644 --- a/src/browser/application.es6 +++ b/src/browser/application.es6 @@ -596,14 +596,19 @@ export default class Application extends EventEmitter { const escapedName = this._escapeShell(appName); const escapedPath = this._escapeShell(appPath); + if (!escapedName || escapedName.trim().length === 0) { + throw new Error(`escapedName is invalid: ${escapedName}`) + } + // We separate the commands with a `;` instead of `&&` so in case the // mv fails, the open will still run. // We need the sleep to let the first app fully finish quitting. // Otherwise it'll attempt to re-open the existing app (the one in // the process of quitting) + const newAppDest = `/Applications/${escapedName}` let move = `mv` try { fs.accessSync(appPath, fs.W_OK) } catch (e) { move = `cp -r` } - const cmd = `${move} ${escapedPath} /Applications/; sleep 0.5; open /Applications/${escapedName}`; + const cmd = `rm -rf ${newAppDest}; ${move} ${escapedPath} ${newAppDest}; sleep 0.5; open ${newAppDest}`; app.once('will-quit', () => { // We need to use `exec` since that will start a new shell process and // allow us to kill this one.