本文整理汇总了TypeScript中electron.screen类的典型用法代码示例。如果您正苦于以下问题:TypeScript screen类的具体用法?TypeScript screen怎么用?TypeScript screen使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了screen类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: BrowserWindow
app.on('ready', () => {
let cursorPos = screen.getCursorScreenPoint()
let workAreaSize = screen.getDisplayNearestPoint(cursorPos).workAreaSize
app.setName('Ansel')
mainWindow = new BrowserWindow({
width: 1356,
height: 768,
title: 'Ansel',
titleBarStyle: 'hiddenInset',
backgroundColor: '#37474f', // @blue-grey-800
webPreferences: {
experimentalFeatures: true,
blinkFeatures: 'CSSGridLayout'
}
})
if (workAreaSize.width <= 1366 && workAreaSize.height <= 768)
mainWindow.maximize()
mainWindow.loadURL('file://' + __dirname + '/../../static/index.html')
mainWindow.setTitle('Ansel')
initBackgroundService(mainWindow)
initForegroundClient(mainWindow)
//let usb = new Usb()
//
//usb.scan((err, drives) => {
// mainWindow.webContents.send('scanned-devices', drives)
//})
//
//usb.watch((err, action, drive) => {
// if (action === 'add')
// mainWindow.webContents.send('add-device', drive)
// else
// mainWindow.webContents.send('remove-device', drive)
//})
if (fs.existsSync(config.settings)) {
initLibrary(mainWindow)
} else {
initDb()
ipcMain.on('settings-created', () => initLibrary(mainWindow))
}
// Emitted when the window is closed.
mainWindow.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null
})
})
示例2: async
watcher.on(actions.preferencesLoaded, async (store, action) => {
const hidden = action.payload.openAsHidden;
if (!hidden) {
store.dispatch(actions.focusWindow({ window: "root" }));
}
screen.on("display-added", () => ensureMainWindowInsideDisplay(store));
screen.on("display-removed", () => ensureMainWindowInsideDisplay(store));
screen.on("display-metrics-changed", () =>
ensureMainWindowInsideDisplay(store)
);
});
示例3: createWindow
function createWindow() {
const size = screen.getPrimaryDisplay().workAreaSize;
// Create the browser window.
win = new BrowserWindow({
x: 0,
y: 0,
width: size.width,
height: size.height
});
// and load the index.html of the app.
win.loadURL(url.format({
protocol: 'file:',
pathname: path.join(__dirname, '/index.html'),
slashes: true
}));
if (serve) {
win.webContents.openDevTools();
}
// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store window
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null;
});
}
示例4: createWindow
function createWindow() {
const size = screen.getPrimaryDisplay().workAreaSize;
const args = process.argv.slice(1);
window = new BrowserWindow({
backgroundColor: '#ffffff',
icon: `${__dirname}/ux/favicon.ico`,
width: size.width,
height: size.height
});
if(args.some(val => val == '--serve')) {
require('electron-reload')(__dirname, {
electron: require(`${__dirname}/../node_modules/electron`)
});
window.loadURL(`http://localhost:4200/`);
}
else {
window.loadURL(`file://${__dirname}/ux/index.html`);
}
window.on('closed', function() {
window = null;
});
}
示例5: function
app.on('ready', function() {
// Create the browser window.
let displays = electron.screen.getAllDisplays()
let d = displays.find((display) => {
return { width: display.bounds.width, height: display.bounds.height }
})
let minScreenWidth = 650;
let minScreenHeight = 450;
mainWindow = new BrowserWindow({
width: Math.max(minScreenWidth, ~~(d.bounds.width * 0.75)),
height: Math.max(minScreenHeight, ~~(d.bounds.height * 0.75)),
minWidth: minScreenWidth,
minHeight: minScreenHeight,
title: 'Leto'
})
mainWindow.loadURL(`file://${ path.join(__dirname, '../www/index_electron.html')}`)
// Open the DevTools.
mainWindow.webContents.openDevTools({mode:'undocked'});
// Emitted when the window is closed.
mainWindow.on('closed', function() {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
});
示例6: function
var resetToDefaults = function(windowState) {
var bounds = screen.getPrimaryDisplay().bounds;
return Object.assign({}, defaultSize, {
x: (bounds.width - defaultSize.width) / 2,
y: (bounds.height - defaultSize.height) / 2
});
};
示例7: getMainWindow
function getMainWindow(): Electron.BrowserWindow {
const workAreaSize = screen.getPrimaryDisplay().workAreaSize;
if (!browserWindow) {
let options: Electron.BrowserWindowOptions = {
webPreferences: {
experimentalFeatures: true,
experimentalCanvasFeatures: true,
},
titleBarStyle: "hidden",
resizable: true,
minWidth: 500,
minHeight: 300,
width: workAreaSize.width,
height: workAreaSize.height,
show: false,
};
browserWindow = new BrowserWindow(options);
browserWindow.loadURL("file://" + __dirname + "/../views/index.html");
menu.setMenu(app, browserWindow);
browserWindow.on("closed", (): void => browserWindow = undefined)
.on("focus", (): void => app.dock && app.dock.setBadge(""));
browserWindow.webContents.on("did-finish-load", () => {
browserWindow.show();
browserWindow.focus();
});
}
return browserWindow;
}
示例8: function
var windowIsOffScreen = function(windowBounds: Electron.Rectangle): boolean {
const nearestDisplay = Electron.screen.getDisplayMatching(windowBounds).workArea;
return (
windowBounds.x > (nearestDisplay.x + nearestDisplay.width) ||
(windowBounds.x + windowBounds.width) < nearestDisplay.x ||
windowBounds.y > (nearestDisplay.y + nearestDisplay.height) ||
(windowBounds.y + windowBounds.height) < nearestDisplay.y
);
}
示例9: 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
}
});
}
});
示例10: enableHiresResources
function enableHiresResources(): void {
const scaleFactor = Math.max(
...electronScreen.getAllDisplays().map(display => display.scaleFactor)
);
if (scaleFactor === 1) {
return;
}
const filter = {urls: [`*://*.${domain}/`]};
session.defaultSession!.webRequest.onBeforeSendHeaders(
filter,
(details: OnSendHeadersDetails, callback: (response: BeforeSendHeadersResponse) => void) => {
let cookie = (details.requestHeaders as any).Cookie;
if (cookie && details.method === 'GET') {
if (/(; )?dpr=\d/.test(cookie)) {
cookie = cookie.replace(/dpr=\d/, `dpr=${scaleFactor}`);
} else {
cookie = `${cookie}; dpr=${scaleFactor}`;
}
(details.requestHeaders as any).Cookie = cookie;
}
callback({
cancel: false,
requestHeaders: details.requestHeaders
});
}
);
}