diff --git a/CHANGELOG.md b/CHANGELOG.md index 8990be581..cc52d8cff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). * Codacy support for Github contributions ([#1059](https://github.com/lbryio/lbry-app/pull/1059)) * App category for Linux ([#877](https://github.com/lbryio/lbry-app/pull/877)) * Add YouTube Sync reward ([1147](https://github.com/lbryio/lbry-app/pull/1147)) + * Retain previous screen sizing on startup ([#338](https://github.com/lbryio/lbry-app/issues/338)) ### Changed * Update LBRY Protocol to 0.19.1 (See change log for [0.19.0](https://github.com/lbryio/lbry/releases/tag/v0.19.0) and [0.19.1](https://github.com/lbryio/lbry/releases/tag/v0.19.1)) diff --git a/package.json b/package.json index 4bcbf6a9b..52902273f 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "electron-log": "^2.2.12", "electron-publisher-s3": "^20.2.0", "electron-updater": "^2.21.0", + "electron-window-state": "^4.1.1", "find-process": "^1.1.0", "formik": "^0.10.4", "from2": "^2.3.0", @@ -123,4 +124,4 @@ "lbrynetDaemonDir": "static/daemon", "lbrynetDaemonFileName": "lbrynet-daemon" } -} +} \ No newline at end of file diff --git a/src/main/createWindow.js b/src/main/createWindow.js index 27af06c38..afdfe5d65 100644 --- a/src/main/createWindow.js +++ b/src/main/createWindow.js @@ -1,15 +1,32 @@ -import { app, BrowserWindow, dialog } from 'electron'; +import { app, BrowserWindow, dialog, screen } from 'electron'; import isDev from 'electron-is-dev'; +import windowStateKeeper from 'electron-window-state'; + import setupBarMenu from './menu/setupBarMenu'; import setupContextMenu from './menu/setupContextMenu'; export default appState => { + // Get primary display dimensions from Electron. + const { width, height } = screen.getPrimaryDisplay().workAreaSize; + + // Load the previous state with fallback to defaults. + const windowState = windowStateKeeper({ + defaultWidth: width, + defaultHeight: height, + }); + let windowConfiguration = { backgroundColor: '#155B4A', minWidth: 800, minHeight: 600, autoHideMenuBar: true, show: false, + // Create the window using the state information. + x: windowState.x, + y: windowState.y, + // If state is undefined, create window as maximized. + width: windowState.width === undefined ? width : windowState.width, + height: windowState.height === undefined ? height : windowState.height, }; // Disable renderer process's webSecurity on development to enable CORS. @@ -28,7 +45,10 @@ export default appState => { let window = new BrowserWindow(windowConfiguration); - window.maximize(); + // Let us register listeners on the window, so we can update the state + // automatically (the listeners will be removed when the window is closed) + // and restore the maximized or full screen state. + windowState.manage(window); window.loadURL(rendererURL); diff --git a/yarn.lock b/yarn.lock index f546b55ab..957d3991b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3106,6 +3106,14 @@ electron-webpack@^1.13.0: webpack-merge "^4.1.1" yargs "^11.0.0" +electron-window-state@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/electron-window-state/-/electron-window-state-4.1.1.tgz#6b34fdc31b38514dfec8b7c8f7b5d4addb67632d" + dependencies: + deep-equal "^1.0.1" + jsonfile "^2.2.3" + mkdirp "^0.5.1" + electron@1.7.12: version "1.7.12" resolved "https://registry.yarnpkg.com/electron/-/electron-1.7.12.tgz#dcc61a2c1b0c3df25f68b3425379a01abd01190e" @@ -5640,7 +5648,7 @@ json5@^0.5.0, json5@^0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821" -jsonfile@^2.1.0: +jsonfile@^2.1.0, jsonfile@^2.2.3: version "2.4.0" resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-2.4.0.tgz#3736a2b428b87bbda0cc83b53fa3d633a35c2ae8" optionalDependencies: