Implement min/max window width and height

Fixes #82
This commit is contained in:
Goh Jia Hao 2016-05-26 17:11:51 +08:00
parent fcab2a9a95
commit 7945f7802e
5 changed files with 62 additions and 2 deletions

View File

@ -28,6 +28,10 @@ function createMainWindow(options, onAppQuit, setDockBadge) {
frame: !options.hideWindowFrame,
width: mainWindowState.width,
height: mainWindowState.height,
minWidth: options.minWidth,
minHeight: options.minHeight,
maxWidth: options.maxWidth,
maxHeight: options.maxHeight,
x: mainWindowState.x,
y: mainWindowState.y,
autoHideMenuBar: !options.showMenuBar,

View File

@ -17,6 +17,10 @@
- [[counter]](#counter)
- [[width]](#width)
- [[height]](#height)
- [[min-width]](#min-width)
- [[min-height]](#min-height)
- [[max-width]](#max-width)
- [[max-height]](#max-height)
- [[show-menu-bar]](#show-menu-bar)
- [[fast-quit]](#fast-quit)
- [[user-agent]](#user-agent)
@ -159,6 +163,38 @@ Width of the packaged application, defaults to `1280px`.
Height of the packaged application, defaults to `800px`.
#### [min-width]
```
--min-width <value>
```
Minimum width of the packaged application, defaults to `0`.
#### [min-height]
```
--min-height <value>
```
Minimum height of the packaged application, defaults to `0`.
#### [max-width]
```
--max-width <value>
```
Maximum width of the packaged application, default is no limit.
#### [max-height]
```
--max-height <value>
```
Maximum height of the packaged application, default is no limit.
#### [show-menu-bar]
```

View File

@ -99,6 +99,10 @@ function selectAppArgs(options) {
counter: options.counter,
width: options.width,
height: options.height,
minWidth: options.minWidth,
minHeight: options.minHeight,
maxWidth: options.maxWidth,
maxHeight: options.maxHeight,
showMenuBar: options.showMenuBar,
fastQuit: options.fastQuit,
userAgent: options.userAgent,

View File

@ -29,8 +29,12 @@ if (require.main === module) {
.option('-c, --conceal', 'packages the source code within your app into an archive, defaults to false, see http://electron.atom.io/docs/v0.36.0/tutorial/application-packaging/')
.option('--counter', 'if the target app should use a persistant counter badge in the dock (OSX only), defaults to false')
.option('-i, --icon <value>', 'the icon file to use as the icon for the app (should be a .icns file on OSX, .png for Windows and Linux)')
.option('--width <value>', 'set window width, defaults to 1280px', parseInt)
.option('--height <value>', 'set window height, defaults to 800px', parseInt)
.option('--width <value>', 'set window default width, defaults to 1280px', parseInt)
.option('--height <value>', 'set window default height, defaults to 800px', parseInt)
.option('--min-width <value>', 'set window minimum width, defaults to 0px', parseInt)
.option('--min-height <value>', 'set window minimum height, defaults to 0px', parseInt)
.option('--max-width <value>', 'set window maximum width, default is no limit', parseInt)
.option('--max-height <value>', 'set window maximum height, default is no limit', parseInt)
.option('-m, --show-menu-bar', 'set menu bar visible, defaults to false')
.option('-f, --fast-quit', 'quit app after window close (OSX only), defaults to false')
.option('-u, --user-agent <value>', 'set the user agent string for the app')

View File

@ -46,6 +46,10 @@ function optionsFactory(inpOptions, callback) {
counter: inpOptions.counter || false,
width: inpOptions.width || 1280,
height: inpOptions.height || 800,
minWidth: inpOptions.minWidth,
minHeight: inpOptions.minHeight,
maxWidth: inpOptions.maxWidth,
maxHeight: inpOptions.maxHeight,
showMenuBar: inpOptions.showMenuBar || false,
fastQuit: inpOptions.fastQuit || false,
userAgent: inpOptions.userAgent,
@ -84,6 +88,14 @@ function optionsFactory(inpOptions, callback) {
options.platform = 'darwin';
}
if (options.width > options.maxWidth) {
options.width = options.maxWidth;
}
if (options.height > options.maxHeight) {
options.height = options.maxHeight;
}
async.waterfall([
callback => {
if (options.userAgent) {