本文整理汇总了TypeScript中electron.screen.getDisplayMatching方法的典型用法代码示例。如果您正苦于以下问题:TypeScript screen.getDisplayMatching方法的具体用法?TypeScript screen.getDisplayMatching怎么用?TypeScript screen.getDisplayMatching使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类electron.screen
的用法示例。
在下文中一共展示了screen.getDisplayMatching方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
const rememberBounds = () => {
const bounds = mainWindow.getBounds();
dispatch<WindowStateAction>({
type: 'Window_RememberBounds',
state: {
displayId: Electron.screen.getDisplayMatching(bounds).id,
width: bounds.width,
height: bounds.height,
left: bounds.x,
top: bounds.y
}
});
}
示例2: isValidWindowState
function isValidWindowState(windowState: WindowState) {
if (windowState && windowState.bounds && windowState.displayBounds) {
// check if the display where the window was last open is still available
var displayBounds = screen.getDisplayMatching(windowState.bounds).bounds;
if (
windowState.displayBounds.x == displayBounds.x &&
windowState.displayBounds.y == displayBounds.y &&
windowState.displayBounds.width == displayBounds.width &&
windowState.displayBounds.height == displayBounds.height
) {
return true;
}
}
return false;
}
示例3: ensureWindowInsideDisplay
/**
* Make sure the window isn't outside the bounds of the screen,
* cf. https://github.com/itchio/itch/issues/1051
*/
function ensureWindowInsideDisplay(nativeWindow: Electron.BrowserWindow) {
if (!nativeWindow || !nativeWindow.isVisible()) {
return;
}
const originalBounds = nativeWindow.getBounds();
logger.debug(
`Ensuring ${JSON.stringify(originalBounds)} is inside a display`
);
const display = screen.getDisplayMatching(originalBounds);
if (!display) {
logger.warn(`No display found matching ${JSON.stringify(originalBounds)}`);
return;
}
const displayBounds = display.bounds;
logger.debug(`Display bounds: ${JSON.stringify(displayBounds)}`);
let bounds = originalBounds;
const displayLeft = displayBounds.x;
if (bounds.x < displayLeft) {
bounds = { ...bounds, x: displayLeft };
}
const displayTop = displayBounds.y;
if (bounds.y < displayTop) {
bounds = { ...bounds, y: displayTop };
}
const displayRight = displayBounds.width + displayBounds.x;
if (bounds.x + bounds.width > displayRight) {
bounds = { ...bounds, x: displayRight - bounds.width };
}
const displayBottom = displayBounds.height + displayBounds.y;
if (bounds.y + bounds.height > displayBottom) {
bounds = { ...bounds, y: displayBottom - bounds.height };
}
if (bounds !== originalBounds) {
logger.debug(`New bounds: ${JSON.stringify(bounds)}`);
nativeWindow.setBounds(bounds);
}
}
示例4: getSettings
mainWindow.on('restore', () => {
if (windowIsOffScreen(mainWindow.getBounds())) {
const bounds = mainWindow.getBounds();
let display = Electron.screen.getAllDisplays().find(display => display.id === getSettings().windowState.displayId);
display = display || Electron.screen.getDisplayMatching(bounds);
mainWindow.setPosition(display.workArea.x, display.workArea.y);
dispatch<WindowStateAction>({
type: 'Window_RememberBounds',
state: {
displayId: display.id,
width: bounds.width,
height: bounds.height,
left: display.workArea.x,
top: display.workArea.y
}
});
}
});
示例5: updateState
function updateState() {
var windowBounds = window.getBounds();
if (!window.isMaximized() && !window.isMinimized() && !window.isFullScreen()) {
normalWindowBounds = Object.assign({}, windowBounds);
}
var displayBounds = screen.getDisplayMatching(windowBounds).bounds;
action(() => {
settings.windowStates[windowId] = {
bounds: normalWindowBounds,
isMaximized: window.isMaximized(),
isFullScreen: window.isFullScreen(),
displayBounds: Object.assign({}, displayBounds)
};
})();
}
示例6:
socket.on('screen-getDisplayMatching', (rectangle) => {
var display = screen.getDisplayMatching(rectangle);
socket.emit('screen-getDisplayMatchingCompleted', display);
});