From 31c7a330bf0d22d6ba23c01549d7cd2e96ab5788 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Sat, 3 Oct 2015 19:04:19 -0700 Subject: [PATCH] feat(dev-mode): Toggle dev mode, sticky through restarts --- docs/Debugging.md | 4 +-- .../plugins/lib/packages-store.coffee | 17 ++++++++++-- .../plugins/lib/tab-installed.cjsx | 25 +++++++++++++++--- menus/darwin.cson | 6 ++--- menus/linux.cson | 6 ++--- menus/win32.cson | 6 ++--- src/browser/application-menu.coffee | 9 ++++++- src/browser/application.coffee | 18 ++++++++++--- src/flux/nylas-api.coffee | 4 ++- src/window-event-handler.coffee | 26 +++++++++++++++++++ 10 files changed, 99 insertions(+), 22 deletions(-) diff --git a/docs/Debugging.md b/docs/Debugging.md index a667086b2..828d605be 100644 --- a/docs/Debugging.md +++ b/docs/Debugging.md @@ -21,13 +21,13 @@ Here are a few hidden tricks for getting the most out of the Chromium DevTools: ### Nylas Developer Panel -If you choose `Developer > Relaunch with Debug Flags...` from the menu, you can enable the Nylas Developer Panel at the bottom of the main window. +If you choose `Developer > Show Activity Window` from the menu, you can see detailed logs of the requests, tasks, and streaming updates processed by N1. The Developer Panel provides three views which you can click to activate: - `Tasks`: This view allows you to inspect the {TaskQueue} and see the what tasks are pending and complete. Click a task to see its JSON representation and inspect it's values, including the last error it encountered. -- `Delta Stream`: This view allows you to see the streaming updates from the Nylas API that the app has received. You can click individual updates to see the exact JSON that was consumed by the app, and search in the lower left for updates pertaining to an object ID or type. +- `Long Polling`: This view allows you to see the streaming updates from the Nylas API that the app has received. You can click individual updates to see the exact JSON that was consumed by the app, and search in the lower left for updates pertaining to an object ID or type. - `Requests`: This view shows the requests the app has made to the Nylas API in `curl`-equivalent form. (The app does not actually make `curl` requests). You can click "Copy" to copy a `curl` command to the clipboard, or "Run" to execute it in a new Terminal window. diff --git a/internal_packages/plugins/lib/packages-store.coffee b/internal_packages/plugins/lib/packages-store.coffee index 2a9b8a297..66ec4121f 100644 --- a/internal_packages/plugins/lib/packages-store.coffee +++ b/internal_packages/plugins/lib/packages-store.coffee @@ -176,7 +176,20 @@ PackagesStore = Reflux.createStore @_displayMessage("Package installed", msg) _onCreatePackage: -> - packagesDir = path.join(atom.getConfigDirPath(), 'packages') + if not atom.inDevMode() + btn = dialog.showMessageBox + type: 'warning' + message: "Run with debug flags?" + detail: "To develop plugins, you should run N1 with debug flags. + This gives you better error messages, the debug version of + React, and more. You can disable it at any time from the + Developer menu." + buttons: ["OK", "Cancel"] + if btn is 0 + ipc.send('command', 'application:toggle-dev') + return + + packagesDir = path.join(atom.getConfigDirPath(), 'dev', 'packages') fs.makeTreeSync(packagesDir) dialog.showSaveDialog @@ -248,7 +261,7 @@ PackagesStore = Reflux.createStore pkgs _displayMessage: (title, message) -> - chosen = dialog.showMessageBox + dialog.showMessageBox type: 'warning' message: title detail: message diff --git a/internal_packages/plugins/lib/tab-installed.cjsx b/internal_packages/plugins/lib/tab-installed.cjsx index 366e4024b..40ce02eaf 100644 --- a/internal_packages/plugins/lib/tab-installed.cjsx +++ b/internal_packages/plugins/lib/tab-installed.cjsx @@ -17,6 +17,20 @@ class TabInstalled extends React.Component if @state.search.length > 0 searchEmpty = "No matching packages." + if atom.inDevMode() + devPackages = @state.packages.dev + devEmpty = + You don't have any packages installed in ~/.nylas/dev/packages. + These packages are only loaded when you run the app with debug flags + enabled (via the Developer menu).

Learn more about building + packages at https://nylas.github.io/N1/docs +
+ devCTA =
Create New Package...
+ else + devPackages = [] + devEmpty = Run with debug flags enabled to load ~/.nylas/dev/packages. + devCTA =
Enable Debug Flags
+
+ emptyText={searchEmpty ? You don't have any packages installed in ~/.nylas/packages.} /> You don't have any packages installed in ~/.nylas/dev/packages. These packages are only loaded when you run the app with debug flags enabled (via the Developer menu).

Learn more about building packages at https://nylas.github.io/N1/docs} /> + packages={devPackages} + emptyText={searchEmpty ? devEmpty} />
-
Create New Package...
+ {devCTA}
+ _onEnableDevMode: => + require('ipc').send('command', 'application:toggle-dev') + componentDidMount: => @_unsubscribers = [] @_unsubscribers.push PackagesStore.listen(@_onChange) diff --git a/menus/darwin.cson b/menus/darwin.cson index 839f94248..70fe3b248 100644 --- a/menus/darwin.cson +++ b/menus/darwin.cson @@ -54,15 +54,15 @@ { label: 'Developer' submenu: [ + { label: 'Run with Debug Flags', type: 'checkbox', command: 'application:toggle-dev' } + { type: 'separator' } + { label: 'Reload', command: 'window:reload' } { label: 'Toggle Developer Tools', command: 'window:toggle-dev-tools' } { label: 'Toggle Component Regions', command: 'window:toggle-component-regions' } { label: 'Toggle React Remote', command: 'window:toggle-react-remote' } { type: 'separator' } { label: 'Open Activity Window', command: 'application:show-work-window' } { type: 'separator' } - { label: 'Reload', command: 'window:reload' } - { label: 'Relaunch with Debug Flags...', command: 'application:open-dev' } - { type: 'separator' } { label: 'Create a Package...', command: 'application:create-package' } { label: 'Install a Package Manually...', command: 'application:install-package' } { type: 'separator' } diff --git a/menus/linux.cson b/menus/linux.cson index a1ba26dab..e15d64eee 100644 --- a/menus/linux.cson +++ b/menus/linux.cson @@ -34,15 +34,15 @@ { label: 'Developer' submenu: [ + { label: 'Run with &Debug Flags', type: 'checkbox', command: 'application:toggle-dev' } + { type: 'separator' } + { label: 'Reload', command: 'window:reload' } { label: 'Toggle Developer &Tools', command: 'window:toggle-dev-tools' } { label: 'Toggle Component Regions', command: 'window:toggle-component-regions' } { label: 'Toggle React Remote', command: 'window:toggle-react-remote' } { type: 'separator' } { label: 'Open Activity Window', command: 'application:show-work-window' } { type: 'separator' } - { label: '&Reload', command: 'window:reload' } - { label: 'Relaunch with &Debug Flags...', command: 'application:open-dev' } - { type: 'separator' } { label: 'Create a Package...', command: 'application:create-package' } { label: 'Install a Package Manually...', command: 'application:install-package' } { type: 'separator' } diff --git a/menus/win32.cson b/menus/win32.cson index 1bfc4fec9..8ec0e2f48 100644 --- a/menus/win32.cson +++ b/menus/win32.cson @@ -23,15 +23,15 @@ { label: 'Developer' submenu: [ + { label: 'Run with &Debug Flags', type: 'checkbox', command: 'application:toggle-dev' } + { type: 'separator' } + { label: '&Reload', command: 'window:reload' } { label: 'Toggle Developer &Tools', command: 'window:toggle-dev-tools' } { label: 'Toggle Component Regions', command: 'window:toggle-component-regions' } { label: 'Toggle React Remote', command: 'window:toggle-react-remote' } { type: 'separator' } { label: 'Open Activity Window', command: 'application:show-work-window' } { type: 'separator' } - { label: '&Reload', command: 'window:reload' } - { label: 'Relaunch with &Debug Flags...', command: 'application:open-dev' } - { type: 'separator' } { label: 'Create a Package...', command: 'application:create-package' } { label: 'Install a Package Manually...', command: 'application:install-package' } { type: 'separator' } diff --git a/src/browser/application-menu.coffee b/src/browser/application-menu.coffee index 08abd9721..62bae61c6 100644 --- a/src/browser/application-menu.coffee +++ b/src/browser/application-menu.coffee @@ -16,6 +16,8 @@ class ApplicationMenu @setActiveTemplate(@getDefaultTemplate()) global.application.autoUpdateManager.on 'state-changed', (state) => @showUpdateMenuItem(state) + global.application.config.observe 'devMode', (state) => + @showDevModeItem() # Public: Updates the entire menu with the given keybindings. # @@ -37,6 +39,7 @@ class ApplicationMenu @showUpdateMenuItem(global.application.autoUpdateManager.getState()) @showFullscreenMenuItem(@lastFocusedWindow?.isFullScreen()) + @showDevModeItem() # Register a BrowserWindow with this application menu. addWindow: (window) -> @@ -123,12 +126,16 @@ class ApplicationMenu enterItem.visible = !fullscreen exitItem.visible = fullscreen + showDevModeItem: -> + devModeItem = _.find(@flattenMenuItems(@menu), ({label}) -> label == 'Run with Debug Flags') + devModeItem?.checked = global.application.devMode + # Default list of menu items. # # Returns an Array of menu item Objects. getDefaultTemplate: -> [ - label: "Atom" + label: "N1" submenu: [ { label: "Check for Update", metadata: {autoUpdate: true}} { label: 'Reload', accelerator: 'Command+R', click: => @focusedWindow()?.reload() } diff --git a/src/browser/application.coffee b/src/browser/application.coffee index f0d0f8849..a74b93e6a 100644 --- a/src/browser/application.coffee +++ b/src/browser/application.coffee @@ -80,6 +80,12 @@ class Application @config = new Config({configDirPath, @resourcePath}) @config.load() + # Normally, you enter dev mode by passing the --dev command line flag. + # But for developers using the compiled app, it's easier to toggle dev + # mode from the menu and have it persist through relaunch. + if @config.get('devMode') + @devMode = true + @windowManager = new WindowManager({@resourcePath, @config, @devMode, @safeMode}) @autoUpdateManager = new AutoUpdateManager(@version, @config, @specMode) @applicationMenu = new ApplicationMenu(@version) @@ -250,10 +256,16 @@ class Application @windowManager.unregisterAllHotWindows() @autoUpdateManager.install() - @on 'application:open-dev', => - @devMode = true + @on 'application:toggle-dev', => + @devMode = !@devMode + + if @devMode + @config.set('devMode', true) + else + @config.set('devMode', undefined) + @windowManager.closeAllWindows() - @windowManager.devMode = true + @windowManager.devMode = @devMode @openWindowsForTokenState() @on 'application:toggle-theme', => diff --git a/src/flux/nylas-api.coffee b/src/flux/nylas-api.coffee index 973d177f9..fa898b695 100644 --- a/src/flux/nylas-api.coffee +++ b/src/flux/nylas-api.coffee @@ -226,7 +226,9 @@ class NylasAPI type: 'error' tag: '401' sticky: true - message: "Nylas can no longer authenticate with your mail provider. You will not be able to send or receive mail. Please unlink your account and sign in again.", + message: "Nylas can no longer authenticate with your mail provider. You + will not be able to send or receive mail. Please unlink your + account and sign in again.", icon: 'fa-sign-out' actions: [{ label: 'Unlink' diff --git a/src/window-event-handler.coffee b/src/window-event-handler.coffee index 3c717aa6a..468a2f6c6 100644 --- a/src/window-event-handler.coffee +++ b/src/window-event-handler.coffee @@ -16,6 +16,9 @@ class WindowEventHandler constructor: -> @reloadRequested = false + _.defer => + @showDevModeMessages() + @subscribe ipc, 'open-path', (pathToOpen) -> unless atom.project?.getPaths().length if fs.existsSync(pathToOpen) or fs.existsSync(path.dirname(pathToOpen)) @@ -208,3 +211,26 @@ class WindowEventHandler previousElement.focus() else if highestElement? highestElement.focus() + + showDevModeMessages: -> + return unless atom.isMainWindow() + + if atom.inDevMode() + Actions = require './flux/actions' + Actions.postNotification + icon: 'fa-flask' + type: 'info' + sticky: true + actions: [{label: 'Thanks', id: 'ok'}] + message: "N1 is running with debug flags enabled (slower). Packages in + ~/.nylas/dev/packages will be loaded. Have fun!" + else + console.log("%c Welcome to N1! If you're exploring the source or building a + plugin, you should enable debug flags. It's slower, but + gives you better exceptions, the debug version of React, + and more. Choose %c Developer > Run with Debug Flags %c + from the menu. Also, check out https://nylas.github.io/N1/docs + for documentation and sample code!", + "background-color: antiquewhite;", + "background-color: antiquewhite; font-weight:bold;", + "background-color: antiquewhite; font-weight:normal;")