forked from klaudiosinani/tusk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
win.js
83 lines (70 loc) · 1.91 KB
/
win.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict';
const {join} = require('path');
const electron = require('electron');
const {is} = require('./util');
const file = require('./file');
const settings = require('./settings');
const {app, BrowserWindow} = electron;
class Win {
get _screenDimensions() {
const {width, height} = electron.screen.getPrimaryDisplay().workAreaSize;
return [width, height];
}
get _defaultDimensions() {
return this._screenDimensions.map(x => Math.round(x * 0.9));
}
get _lastState() {
const {x, y, width, height} = settings.get('lastWindowState');
const [defaultWidth, defaultHeight] = this._defaultDimensions;
return {
x,
y,
width: width || defaultWidth,
height: height || defaultHeight
};
}
get _minDimensions() {
const [minWidth, minHeight] = this._screenDimensions.map(x => Math.round(x * 0.3));
return {minWidth, minHeight};
}
get defaultOpts() {
return Object.assign({}, this._minDimensions, this._lastState, {
alwaysOnTop: settings.get('alwaysOnTop'),
autoHideMenuBar: settings.get('menuBarHidden'),
darkTheme: settings.get('mode.dark') || settings.get('mode.black'),
icon: is.linux && file.icon,
show: false,
title: app.getName(),
titleBarStyle: 'hiddenInset',
webPreferences: {
nodeIntegration: false,
plugins: true,
preload: join(__dirname, './browser.js')
}
});
}
activate(command) {
const [win] = BrowserWindow.getAllWindows();
if (is.darwin) {
win.restore();
}
win.webContents.send(command);
}
appear() {
const [win] = BrowserWindow.getAllWindows();
if (!win.isVisible() || !win.isFocused()) {
win.show();
win.focus();
}
}
toggle() {
const [win] = BrowserWindow.getAllWindows();
if (win.isVisible()) {
win.hide();
} else {
win.show();
win.focus();
}
}
}
module.exports = new Win();