fix(win): fix frame settings on windows

This commit is contained in:
Evan Morikawa 2016-04-22 16:21:07 -07:00
parent f1d3638bc2
commit 1c5b9fe490
4 changed files with 35 additions and 35 deletions

View file

@ -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

View file

@ -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")

View file

@ -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] ? {}

View file

@ -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