cli: add --client-size & --client-position options

This commit is contained in:
jean-emmanuel 2022-11-07 10:26:05 +01:00
parent 5af6abb06d
commit 2164964116
3 changed files with 45 additions and 6 deletions

View file

@ -170,6 +170,20 @@ The following options can only be set from a terminal.
Override default config file location (contains session history and launcher config). Defaults to `cache-dir/config.json`.
!!! quote ""
#### `client-position`
Define the built-in client window position, must be a pair of integers separated by a comma (`x,y`).
!!! quote ""
#### `client-size`
Define the built-in client window size, must be a pair of integers separated by a comma (`width,height`).
!!! quote ""
#### `help`

View file

@ -33,20 +33,33 @@ module.exports = function(options={}) {
height = options.height || screenSize.height,
bounds = currentScreen.bounds,
x = Math.ceil(bounds.x + ((bounds.width - width) / 2)),
y = Math.ceil(bounds.y + ((bounds.height - height) / 2))
window.setBounds({x, y, width, height})
y = Math.ceil(bounds.y + ((bounds.height - height) / 2)),
geometry = {x, y, width, height}
// retrieve last geometry
if (settings.read('geometry') && settings.read('geometry')[options.id]) {
var geometry = settings.read('geometry')[options.id],
var last_geometry = settings.read('geometry')[options.id],
mScreen = screen.getDisplayMatching(geometry)
if (intersectionArea(geometry, mScreen.bounds) > 20000) {
// don't load geometry if the window is not visible enough
window.setBounds(geometry)
Object.assign(geometry, last_geometry)
}
}
if (options.id === 'client') {
if (settings.read('client-position')) {
[x, y] = settings.read('client-position').split(',').map(x=>parseInt(x))
Object.assign(geometry, {x, y})
}
if (settings.read('client-size')) {
[width, height] = settings.read('client-size').split(',').map(x=>parseInt(x))
Object.assign(geometry, {width, height})
}
}
window.setBounds(geometry)
window.once('ready-to-show', ()=>{
window.show()
})

View file

@ -93,5 +93,17 @@ module.exports = {
'inspect': {type: 'boolean', describe: 'enable node/electron inspector', launcher: false},
'cache-dir': {type: 'string', describe: 'override default cache directory', launcher: false},
'config-file': {type: 'string', describe: 'override default config file (defaults to cache-dir/config.json)', launcher: false},
'docs': {type: 'boolean', describe: 'serve documentation website locally and open it with the system\'s default browser', launcher: false}
'docs': {type: 'boolean', describe: 'serve documentation website locally and open it with the system\'s default browser', launcher: false},
'client-position': {type: 'string', describe: 'position of the client window ("x,y" pair of integers)', launcher: false,
check: (s)=>{
return s.match(/^[0-9]+,[0-9]+$/) ?
'Position must a x,y pair of integers' : true
}
},
'client-size': {type: 'string', describe: 'size of the client window ("width,height" pair of integers)', launcher: false,
check: (s)=>{
return s.match(/^[0-9]+,[0-9]+$/) ?
'Size must a x,y pair of integers' : true
}
},
}