From 1c5b9fe49092c85b004b60bc9427aa877f993f7a Mon Sep 17 00:00:00 2001 From: Evan Morikawa Date: Fri, 22 Apr 2016 16:21:07 -0700 Subject: [PATCH] fix(win): fix frame settings on windows --- src/browser/nylas-window.coffee | 29 +++++++---------------------- src/browser/window-launcher.es6 | 12 +++++++++++- src/browser/window-manager.coffee | 16 +++++++++------- src/nylas-env.coffee | 13 ++++++++----- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/browser/nylas-window.coffee b/src/browser/nylas-window.coffee index 4c6d45ead..01ba1c8ca 100644 --- a/src/browser/nylas-window.coffee +++ b/src/browser/nylas-window.coffee @@ -19,7 +19,8 @@ class NylasWindow isSpec: null constructor: (settings={}) -> - {title, + {frame, + title, width, height, toolbar, @@ -44,28 +45,13 @@ class NylasWindow # Normalize to make sure drive letter case is consistent on Windows @resourcePath = path.normalize(@resourcePath) if @resourcePath - # Mac: We'll render a CSS toolbar if `toolbar=true`. No frame required. - # Win / Linux: We don't render a toolbar in CSS - include frame if the - # window requests a toolbar. Remove this code once we have custom toolbars - # on win/linux. - - toolbar ?= true - if process.platform is 'darwin' - frame = false - else - frame = toolbar - - if @isSpec - frame = true - toolbar = false - - options = + browserWindowOptions = show: false title: title ? 'Nylas N1' frame: frame width: width height: height - resizable: resizable ? true + resizable: resizable webPreferences: directWrite: true @@ -76,7 +62,7 @@ class NylasWindow # This option is no longer working according to # https://github.com/atom/electron/issues/3225 # Look into using option --disable-renderer-backgrounding - options.webPreferences.pageVisibility = true + browserWindowOptions.webPreferences.pageVisibility = true # Don't set icon on Windows so the exe's ico will be used as window and # taskbar's icon. See https://github.com/atom/atom/issues/4811 for more. @@ -85,15 +71,14 @@ class NylasWindow WindowIconPath = path.resolve(__dirname, '..', '..', 'nylas.png') unless fs.existsSync(WindowIconPath) WindowIconPath = path.resolve(__dirname, '..', '..', 'build', 'resources', 'nylas.png') - options.icon = WindowIconPath + browserWindowOptions.icon = WindowIconPath - @browserWindow = new BrowserWindow(options) + @browserWindow = new BrowserWindow(browserWindowOptions) @browserWindow.updateLoadSettings = @updateLoadSettings @handleEvents() loadSettings = _.extend({}, settings) - loadSettings.toolbar = toolbar loadSettings.windowState ?= '{}' loadSettings.appVersion = app.getVersion() loadSettings.resourcePath = @resourcePath diff --git a/src/browser/window-launcher.es6 b/src/browser/window-launcher.es6 index 77315c0d9..b33cc59ca 100644 --- a/src/browser/window-launcher.es6 +++ b/src/browser/window-launcher.es6 @@ -17,9 +17,12 @@ export default class WindowLauncher { constructor(appOpts) { this.defaultWindowOpts = { + frame: process.platform !== "darwin", hidden: false, + toolbar: true, devMode: appOpts.devMode, safeMode: appOpts.safeMode, + resizable: true, windowType: WindowLauncher.EMPTY_WINDOW, resourcePath: appOpts.resourcePath, configDirPath: appOpts.configDirPath, @@ -38,7 +41,7 @@ export default class WindowLauncher { win = new NylasWindow(opts) } else { opts.bootstrapScript = this._secondaryWindowBootstrap() - if (opts.coldStartOnly) { + if (this._unableToModifyHotWindow(opts) || opts.coldStartOnly) { // Useful for the Worker Window: A secondary window that shouldn't // be hot-loaded win = new NylasWindow(opts) @@ -81,6 +84,13 @@ export default class WindowLauncher { this.hotWindow.browserWindow.destroy() } + // Some properties, like the `frame` or `toolbar` can't be updated once + // a window has been setup. If we detect this case we have to bootup a + // plain NylasWindow instead of using a hot window. + _unableToModifyHotWindow(opts) { + return this.defaultWindowOpts.frame !== (!!opts.frame) + } + _secondaryWindowBootstrap() { if (!this._bootstrap) { this._bootstrap = require.resolve("../secondary-window-bootstrap") diff --git a/src/browser/window-manager.coffee b/src/browser/window-manager.coffee index 29f21b06f..9e2af9e98 100644 --- a/src/browser/window-manager.coffee +++ b/src/browser/window-manager.coffee @@ -98,10 +98,10 @@ class WindowManager neverClose: true bootstrapScript: require.resolve("../window-bootstrap") mainWindow: true - width: 640 - height: 396 - center: true - resizable: false + width: 640 # Gets reset once app boots up + height: 396 # Gets reset once app boots up + center: true # Gets reset once app boots up + resizable: false # Gets reset once app boots up initializeInBackground: @initializeInBackground coreWinOpts[WindowManager.WORK_WINDOW] = @@ -109,7 +109,6 @@ class WindowManager windowType: WindowManager.WORK_WINDOW coldStartOnly: true # It's a secondary window, but not a hot window title: "Activity" - toolbar: true hidden: true neverClose: true width: 800 @@ -118,17 +117,20 @@ class WindowManager coreWinOpts[WindowManager.ONBOARDING_WINDOW] = windowKey: WindowManager.ONBOARDING_WINDOW windowType: WindowManager.ONBOARDING_WINDOW - resizable: false - toolbar: false hidden: true # Displayed by PageRouter::_initializeWindowSize + frame: false # Always false on Mac, explicitly set for Win & Linux + toolbar: false + resizable: false # The SPEC_WINDOW gets passed its own bootstrapScript coreWinOpts[WindowManager.SPEC_WINDOW] = windowKey: WindowManager.SPEC_WINDOW windowType: WindowManager.SPEC_WINDOW + frame: true, hidden: true, isSpec: true, devMode: true, + toolbar: false defaultOptions = coreWinOpts[winId] ? {} diff --git a/src/nylas-env.coffee b/src/nylas-env.coffee index 594b5a96a..90398dcc0 100644 --- a/src/nylas-env.coffee +++ b/src/nylas-env.coffee @@ -717,18 +717,21 @@ class NylasEnvConstructor extends Model @loadSettings = loadSettings @constructor.loadSettings = loadSettings - {width, height, windowProps, windowType, hidden} = loadSettings - - @packages.loadPackages(windowType) + @packages.loadPackages(loadSettings.windowType) @deserializePackageStates() @packages.activate() - @emitter.emit('window-props-received', windowProps ? {}) + @emitter.emit('window-props-received', loadSettings.windowProps ? {}) + {width, height} = loadSettings if width and height @setWindowDimensions({width, height}) + browserWindow = @getCurrentWindow() + if browserWindow.isResizable() isnt loadSettings.resizable + console.log(loadSettings.resizable) + browserWindow.setResizable(loadSettings.resizable) - @displayWindow() unless hidden + @displayWindow() unless loadSettings.hidden # We extend nylas observables with our own methods. This happens on # require of nylas-observables