feat: retain previous screen sizing on startup (#1057)

This commit is contained in:
miikkatu 2018-03-21 15:29:51 +02:00 committed by Igor Gassmann
parent 262dd8f5a1
commit b0cc40f045
4 changed files with 34 additions and 4 deletions

View file

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

View file

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

View file

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

View file

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