mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 20:40:20 +00:00
Merge pull request #8064 from rhysd/electron-window-state
Add type definitions for electron-window-state module
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
/// <reference path="electron-window-state.d.ts" />
|
||||
|
||||
import {app, BrowserWindow} from 'electron';
|
||||
import windowStateKeeper = require('electron-window-state');
|
||||
|
||||
let win: Electron.BrowserWindow = null;
|
||||
|
||||
app.on('ready', function () {
|
||||
const mainWindowState = windowStateKeeper({
|
||||
defaultWidth: 1000,
|
||||
defaultHeight: 800
|
||||
});
|
||||
|
||||
win = new BrowserWindow({
|
||||
'x': mainWindowState.x,
|
||||
'y': mainWindowState.y,
|
||||
'width': mainWindowState.width,
|
||||
'height': mainWindowState.height,
|
||||
});
|
||||
|
||||
mainWindowState.manage(win);
|
||||
});
|
||||
|
||||
const s2 = windowStateKeeper({
|
||||
defaultWidth: 1000,
|
||||
defaultHeight: 800,
|
||||
file: __dirname + '/foo.json',
|
||||
path: __dirname,
|
||||
maximize: true,
|
||||
fullScreen: false,
|
||||
});
|
||||
|
||||
console.log(s2.isMaximized, s2.isFullScreen);
|
||||
|
||||
s2.saveState(win);
|
||||
@@ -0,0 +1,90 @@
|
||||
// Type definitions for electron-window-state 2.0.0
|
||||
// Project: https://github.com/mawie81/electron-window-state
|
||||
// Definitions by: rhysd <https://github.com/rhysd>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../github-electron/github-electron.d.ts" />
|
||||
|
||||
declare namespace ElectronWindowState {
|
||||
interface WindowState {
|
||||
/*
|
||||
* The saved x coordinate of the loaded state.
|
||||
* undefined if the state has not been saved yet.
|
||||
*/
|
||||
x: number;
|
||||
/*
|
||||
* The saved y coordinate of the loaded state.
|
||||
* undefined if the state has not been saved yet.
|
||||
*/
|
||||
y: number;
|
||||
/*
|
||||
* The saved width of loaded state.
|
||||
* defaultWidth if the state has not been saved yet.
|
||||
*/
|
||||
width: number;
|
||||
/*
|
||||
* The saved heigth of loaded state.
|
||||
* defaultHeight if the state has not been saved yet.
|
||||
*/
|
||||
height: number;
|
||||
/*
|
||||
* true if the window state was saved while the the window was maximized.
|
||||
* undefined if the state has not been saved yet.
|
||||
*/
|
||||
isMaximized: boolean;
|
||||
/*
|
||||
* true if the window state was saved while the the window was in full screen
|
||||
* mode. undefined if the state has not been saved yet.
|
||||
*/
|
||||
isFullScreen: boolean;
|
||||
/*
|
||||
* Register listeners on the given BrowserWindow for events that are related
|
||||
* to size or position changes (resize, move).
|
||||
* It will also restore the window's maximized or full screen state.
|
||||
* When the window is closed we automatically remove the listeners and save the state.
|
||||
*/
|
||||
manage(win: Electron.BrowserWindow): void;
|
||||
/*
|
||||
* Saves the current state of the given BrowserWindow.
|
||||
* This exists mostly for legacy purposes, and in most cases it's better to just use manage.
|
||||
*/
|
||||
saveState(win: Electron.BrowserWindow): void;
|
||||
}
|
||||
interface WindowStateKeeperOptions {
|
||||
/*
|
||||
* The width that should be returned if no file exists yet. Defaults to 800.
|
||||
*/
|
||||
defaultWidth?: number;
|
||||
/*
|
||||
* The height that should be returned if no file exists yet. Defaults to 600.
|
||||
*/
|
||||
defaultHeight?: number;
|
||||
/*
|
||||
* The path where the state file should be written to.
|
||||
* Defaults to app.getPath('userData')
|
||||
*/
|
||||
path?: string;
|
||||
/*
|
||||
* The name of file. Defaults to window-state.json
|
||||
*/
|
||||
file?: string;
|
||||
/*
|
||||
* Should we automatically maximize the window,
|
||||
* if it was last closed maximized. Defaults to true
|
||||
*/
|
||||
maximize?: boolean;
|
||||
/*
|
||||
* Should we automatically restore the window to full screen,
|
||||
* if it was last closed full screen. Defaults to true
|
||||
*/
|
||||
fullScreen?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'electron-window-state' {
|
||||
/*
|
||||
* Load the previous state with fallback to defaults
|
||||
*/
|
||||
function windowStateKeeper(opts: ElectronWindowState.WindowStateKeeperOptions): ElectronWindowState.WindowState;
|
||||
export = windowStateKeeper;
|
||||
}
|
||||
Reference in New Issue
Block a user