From 43d02da5d9b1d1d0cdbd2e6b5145704b1604a1e2 Mon Sep 17 00:00:00 2001 From: Juan Tejada Date: Tue, 16 Aug 2016 17:36:46 -0700 Subject: [PATCH] fix(build): Fix specs and lint errors Summary: Fix specs and lint errors Test Plan: Unit Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D3168 --- .../verify-install-location/lib/main.es6 | 148 +++++++++--------- spec/spec-helper.coffee | 8 +- 2 files changed, 82 insertions(+), 74 deletions(-) diff --git a/internal_packages/verify-install-location/lib/main.es6 b/internal_packages/verify-install-location/lib/main.es6 index eaea223b3..5598c32e0 100644 --- a/internal_packages/verify-install-location/lib/main.es6 +++ b/internal_packages/verify-install-location/lib/main.es6 @@ -10,79 +10,81 @@ import {ipcRenderer} from 'electron' * leave their app in the /Downloads folder (which frequently gets * erased!). */ -module.exports = { - activate() { - this._unlisten = Actions.notificationActionTaken.listen(this._onNotificationActionTaken, this) - if (NylasEnv.inDevMode() || NylasEnv.inSpecMode()) return; - if (process.platform === "darwin") { - const appRe = /Applications/gi; - if (appRe.test(process.argv[0])) return; +let unlisten = () => {} - // 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; - - const actions = [] - if (numAsks >= 1) { - actions.push({ - label: "Don't ask again", - dismisses: true, - id: 'verify-install:dont-ask-again', - }) - } - - const re = /(^.*?\.app)/i; - let enclosingFolder = (re.exec(process.argv[0]) || [])[0].split("/"); - enclosingFolder = enclosingFolder[enclosingFolder.length - 2] - - let msg = `I can move myself to your Applications folder if you'd like.` - if (enclosingFolder) { - 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', - }, - ]), - }); - } - }, - - _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") - } - }, - - deactivate() { - this._unlisten() - }, +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") + } +} + +export function activate() { + unlisten = Actions.notificationActionTaken.listen(onNotificationActionTaken) + + 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; + + const actions = [] + if (numAsks >= 1) { + actions.push({ + label: "Don't ask again", + dismisses: true, + id: 'verify-install:dont-ask-again', + }) + } + + const re = /(^.*?\.app)/i; + let enclosingFolder = (re.exec(process.argv[0]) || [])[0].split("/"); + enclosingFolder = enclosingFolder[enclosingFolder.length - 2] + + let msg = `I can move myself to your Applications folder if you'd like.` + if (enclosingFolder) { + 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', + }, + ]), + }); +} + +export function deactivate() { + unlisten() } diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 5897e0a20..9bd514760 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -120,6 +120,12 @@ require('moment-round') window.testNowMoment = -> moment.tz("2016-03-15 12:00", TEST_TIME_ZONE) +# We need to mock the config even before `beforeEach` runs because it gets +# accessed on module definitions +fakePersistedConfig = {env: 'production'} +NylasEnv.config = new Config() +NylasEnv.config.settings = fakePersistedConfig + beforeEach -> NylasEnv.testOrganizationUnit = null Grim.clearDeprecations() if isCoreSpec @@ -196,7 +202,7 @@ beforeEach -> FocusedPerspectiveStore._current = MailboxPerspective.forNothing() # reset config before each spec; don't load or save from/to `config.json` - fakePersistedConfig = {} + fakePersistedConfig = {env: 'production'} spyOn(Config::, 'getRawValues').andCallFake => fakePersistedConfig spyOn(Config::, 'setRawValue').andCallFake (keyPath, value) ->