custom-electron-titlebar 4.2.0 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base/browser/browser.d.ts +26 -0
- package/dist/base/browser/browser.js +317 -0
- package/dist/base/browser/event.d.ts +12 -0
- package/dist/base/browser/event.js +215 -0
- package/dist/base/browser/keyboardEvent.d.ts +38 -0
- package/dist/base/browser/keyboardEvent.js +466 -0
- package/dist/base/browser/mouseEvent.d.ts +61 -0
- package/dist/base/browser/mouseEvent.js +327 -0
- package/dist/base/browser/touch.d.ts +39 -0
- package/dist/base/browser/touch.js +454 -0
- package/dist/base/common/arrays.d.ts +10 -0
- package/dist/base/common/arrays.js +210 -0
- package/dist/base/common/async.d.ts +35 -0
- package/dist/base/common/async.js +280 -0
- package/dist/base/common/charCode.d.ts +405 -0
- package/dist/base/common/charCode.js +9 -0
- package/dist/base/common/color.d.ts +159 -0
- package/dist/base/common/color.js +709 -0
- package/dist/base/common/decorators.d.ts +6 -0
- package/dist/base/common/decorators.js +300 -0
- package/dist/base/common/dom.d.ts +221 -0
- package/dist/base/common/dom.js +1478 -0
- package/dist/base/common/event.d.ts +213 -0
- package/dist/base/common/event.js +804 -0
- package/dist/base/common/iterator.d.ts +69 -0
- package/dist/base/common/iterator.js +381 -0
- package/dist/base/common/keyCodes.d.ts +478 -0
- package/dist/base/common/keyCodes.js +479 -0
- package/dist/base/common/lifecycle.d.ts +17 -0
- package/dist/base/common/lifecycle.js +258 -0
- package/dist/base/common/linkedList.d.ts +17 -0
- package/dist/base/common/linkedList.js +319 -0
- package/dist/base/common/platform.d.ts +33 -0
- package/dist/base/common/platform.js +302 -0
- package/dist/base/common/strings.d.ts +23 -0
- package/dist/base/common/strings.js +273 -0
- package/dist/consts.d.ts +49 -0
- package/dist/consts.js +303 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +211 -0
- package/dist/main/attach-titlebar-to-window.d.ts +3 -0
- package/dist/main/attach-titlebar-to-window.js +207 -0
- package/dist/main/index.d.ts +3 -0
- package/dist/main/index.js +202 -0
- package/dist/main/setup-titlebar.d.ts +2 -0
- package/dist/main/setup-titlebar.js +242 -0
- package/dist/menubar/index.d.ts +86 -0
- package/dist/menubar/index.js +1118 -0
- package/dist/menubar/menu/index.d.ts +46 -0
- package/dist/menubar/menu/index.js +556 -0
- package/dist/menubar/menu/item.d.ts +67 -0
- package/dist/menubar/menu/item.js +575 -0
- package/dist/menubar/menu/separator.d.ts +11 -0
- package/dist/menubar/menu/separator.js +213 -0
- package/dist/menubar/menu/submenu.d.ts +32 -0
- package/dist/menubar/menu/submenu.js +372 -0
- package/dist/menubar/menubar-options.d.ts +55 -0
- package/dist/menubar/menubar-options.js +9 -0
- package/dist/titlebar/index.d.ts +99 -0
- package/dist/titlebar/index.js +663 -0
- package/dist/titlebar/options.d.ts +84 -0
- package/dist/titlebar/options.js +9 -0
- package/dist/titlebar/themebar.d.ts +20 -0
- package/dist/titlebar/themebar.js +267 -0
- package/package.json +1 -1
|
@@ -0,0 +1,663 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/* ---------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright (c) AlexTorresDev. All rights reserved.
|
|
5
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
6
|
+
*-------------------------------------------------------------------------------------------- */
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports.CustomTitlebar = void 0;
|
|
11
|
+
const electron_1 = require("electron");
|
|
12
|
+
const color_1 = require("../base/common/color");
|
|
13
|
+
const dom_1 = require("../base/common/dom");
|
|
14
|
+
const platform_1 = require("../base/common/platform");
|
|
15
|
+
const menubar_1 = require("../menubar");
|
|
16
|
+
const themebar_1 = require("./themebar");
|
|
17
|
+
const consts_1 = require("../consts");
|
|
18
|
+
class CustomTitlebar extends _get__("themebar_1").ThemeBar {
|
|
19
|
+
/**
|
|
20
|
+
* Create a new TitleBar instance
|
|
21
|
+
* @param options The options for the title bar
|
|
22
|
+
*/
|
|
23
|
+
constructor(options) {
|
|
24
|
+
super();
|
|
25
|
+
this.isInactive = false;
|
|
26
|
+
this.currentOptions = {
|
|
27
|
+
closeable: true,
|
|
28
|
+
enableMnemonics: true,
|
|
29
|
+
// hideWhenClickingClose: false,
|
|
30
|
+
iconSize: 16,
|
|
31
|
+
itemBackgroundColor: undefined,
|
|
32
|
+
maximizable: true,
|
|
33
|
+
menuPosition: 'left',
|
|
34
|
+
menuTransparency: 0,
|
|
35
|
+
minimizable: true,
|
|
36
|
+
onlyShowMenuBar: false,
|
|
37
|
+
shadow: false,
|
|
38
|
+
titleHorizontalAlignment: 'center',
|
|
39
|
+
tooltips: {
|
|
40
|
+
close: 'Close',
|
|
41
|
+
maximize: 'Maximize',
|
|
42
|
+
minimize: 'Minimize',
|
|
43
|
+
restoreDown: 'Restore Down'
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
// TODO: Refactor, verify if is possible use into menubar
|
|
47
|
+
this.closeMenu = () => {
|
|
48
|
+
if (this.menuBar) {
|
|
49
|
+
this.menuBar.blur();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
this.currentOptions = {
|
|
53
|
+
...this.currentOptions,
|
|
54
|
+
...options
|
|
55
|
+
};
|
|
56
|
+
const jWindowIcons = _get__("consts_1").menuIcons[(0, _get__("platform_1").PlatformToString)(_get__("platform_1").platform).toLocaleLowerCase()];
|
|
57
|
+
this.platformIcons = jWindowIcons;
|
|
58
|
+
this.titlebar = (0, _get__("dom_1").$)('.cet-titlebar');
|
|
59
|
+
this.dragRegion = (0, _get__("dom_1").$)('.cet-drag-region');
|
|
60
|
+
this.icon = (0, _get__("dom_1").$)('.cet-icon');
|
|
61
|
+
this.menuBarContainer = (0, _get__("dom_1").$)('.cet-menubar');
|
|
62
|
+
this.title = (0, _get__("dom_1").$)('.cet-title');
|
|
63
|
+
this.controlsContainer = (0, _get__("dom_1").$)('.cet-window-controls');
|
|
64
|
+
this.container = (0, _get__("dom_1").$)('.cet-container');
|
|
65
|
+
this.controls = {
|
|
66
|
+
minimize: (0, _get__("dom_1").$)('.cet-control-minimize'),
|
|
67
|
+
maximize: (0, _get__("dom_1").$)('.cet-control-maximize'),
|
|
68
|
+
close: (0, _get__("dom_1").$)('.cet-control-close')
|
|
69
|
+
};
|
|
70
|
+
this.resizer = {
|
|
71
|
+
top: (0, _get__("dom_1").$)('.cet-resizer.top'),
|
|
72
|
+
left: (0, _get__("dom_1").$)('.cet-resizer.left')
|
|
73
|
+
};
|
|
74
|
+
(0, _get__("dom_1").append)(this.titlebar, this.dragRegion);
|
|
75
|
+
(0, _get__("dom_1").append)(this.titlebar, this.resizer.left);
|
|
76
|
+
(0, _get__("dom_1").append)(this.titlebar, this.resizer.top);
|
|
77
|
+
this.loadIcons();
|
|
78
|
+
this.setupBackgroundColor();
|
|
79
|
+
this.createIcon();
|
|
80
|
+
this.setupMenubar();
|
|
81
|
+
this.setupTitle();
|
|
82
|
+
this.setupWindowControls();
|
|
83
|
+
this.setupContainer();
|
|
84
|
+
this.setupTitleBar();
|
|
85
|
+
this.loadEvents();
|
|
86
|
+
// this.registerTheme(ThemeBar.win)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
loadIcons() {
|
|
90
|
+
const icons = this.currentOptions.icons;
|
|
91
|
+
if (icons) {
|
|
92
|
+
const {
|
|
93
|
+
platformIcons
|
|
94
|
+
} = (0, _get__("consts_1").loadWindowIcons)(icons);
|
|
95
|
+
this.platformIcons = platformIcons;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Setup the background color of the title bar
|
|
100
|
+
* By default, it will use the meta theme-color or msapplication-TileColor and if it doesn't exist, it will use white
|
|
101
|
+
*/
|
|
102
|
+
setupBackgroundColor() {
|
|
103
|
+
let color = this.currentOptions.backgroundColor;
|
|
104
|
+
if (!color) {
|
|
105
|
+
const metaColor = document.querySelectorAll('meta[name="theme-color"]') || document.querySelectorAll('meta[name="msapplication-TileColor"]');
|
|
106
|
+
metaColor.forEach(meta => {
|
|
107
|
+
color = _get__("color_1").Color.fromHex(meta.getAttribute('content'));
|
|
108
|
+
});
|
|
109
|
+
if (!color) color = _get__("color_1").Color.WHITE;
|
|
110
|
+
this.currentOptions.backgroundColor = color;
|
|
111
|
+
}
|
|
112
|
+
this.titlebar.style.backgroundColor = color.toString();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Render the icon of the title bar, if is mac, it will not render
|
|
116
|
+
* By default, it will use the first icon found in the head of the document
|
|
117
|
+
*/
|
|
118
|
+
createIcon() {
|
|
119
|
+
// const onlyRendererMenuBar = this.currentOptions.onlyShowMenuBar
|
|
120
|
+
if (_get__("platform_1").isMacintosh) return;
|
|
121
|
+
let icon = this.currentOptions.icon;
|
|
122
|
+
if (!icon) {
|
|
123
|
+
const tagLink = document.querySelectorAll('link');
|
|
124
|
+
tagLink.forEach(link => {
|
|
125
|
+
if (link.getAttribute('rel') === 'icon' || link.getAttribute('rel') === 'shortcut icon') {
|
|
126
|
+
icon = link.getAttribute('href');
|
|
127
|
+
}
|
|
128
|
+
this.currentOptions.icon = icon;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (icon) {
|
|
132
|
+
const windowIcon = (0, _get__("dom_1").append)(this.icon, (0, _get__("dom_1").$)('img'));
|
|
133
|
+
if (typeof icon === 'string') {
|
|
134
|
+
windowIcon.setAttribute('src', icon);
|
|
135
|
+
} else {
|
|
136
|
+
windowIcon.setAttribute('src', icon.toDataURL());
|
|
137
|
+
}
|
|
138
|
+
this.setIconSize(this.currentOptions.iconSize);
|
|
139
|
+
(0, _get__("dom_1").append)(this.titlebar, this.icon);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
setIconSize(size) {
|
|
143
|
+
if (size < 16) size = 16;
|
|
144
|
+
if (size > 24) size = 24;
|
|
145
|
+
this.icon.firstElementChild.setAttribute('style', `height: ${size}px`);
|
|
146
|
+
}
|
|
147
|
+
setupMenubar() {
|
|
148
|
+
_get__("electron_1").ipcRenderer.invoke('request-application-menu').then(menu => this.updateMenu(menu));
|
|
149
|
+
const menuPosition = this.currentOptions.menuPosition;
|
|
150
|
+
if (menuPosition) {
|
|
151
|
+
this.updateMenuPosition(menuPosition);
|
|
152
|
+
}
|
|
153
|
+
(0, _get__("dom_1").append)(this.titlebar, this.menuBarContainer);
|
|
154
|
+
}
|
|
155
|
+
setupTitle() {
|
|
156
|
+
const onlyRendererMenuBar = this.currentOptions.onlyShowMenuBar;
|
|
157
|
+
if (onlyRendererMenuBar) return;
|
|
158
|
+
this.updateTitle(document.title);
|
|
159
|
+
this.updateTitleAlignment(this.currentOptions.titleHorizontalAlignment);
|
|
160
|
+
(0, _get__("dom_1").append)(this.titlebar, this.title);
|
|
161
|
+
}
|
|
162
|
+
createControlButton(element, icon, title, active = true) {
|
|
163
|
+
(0, _get__("dom_1").addClass)(element, 'cet-control-icon');
|
|
164
|
+
element.innerHTML = icon;
|
|
165
|
+
element.title = title;
|
|
166
|
+
if (!active) {
|
|
167
|
+
(0, _get__("dom_1").addClass)(element, 'inactive');
|
|
168
|
+
}
|
|
169
|
+
(0, _get__("dom_1").append)(this.controlsContainer, element);
|
|
170
|
+
}
|
|
171
|
+
setupWindowControls() {
|
|
172
|
+
const onlyRendererMenuBar = this.currentOptions.onlyShowMenuBar;
|
|
173
|
+
const tooltips = this.currentOptions.tooltips;
|
|
174
|
+
if (_get__("platform_1").isMacintosh || onlyRendererMenuBar) return;
|
|
175
|
+
this.createControlButton(this.controls.minimize, this.platformIcons.minimize, tooltips.minimize, this.currentOptions.minimizable);
|
|
176
|
+
this.createControlButton(this.controls.maximize, this.platformIcons.maximize, tooltips.maximize, this.currentOptions.maximizable);
|
|
177
|
+
this.createControlButton(this.controls.close, this.platformIcons.close, tooltips.close, this.currentOptions.closeable);
|
|
178
|
+
(0, _get__("dom_1").append)(this.titlebar, this.controlsContainer);
|
|
179
|
+
}
|
|
180
|
+
setupContainer() {
|
|
181
|
+
while (document.body.firstChild) {
|
|
182
|
+
(0, _get__("dom_1").append)(this.container, document.body.firstChild);
|
|
183
|
+
}
|
|
184
|
+
(0, _get__("dom_1").append)(document.body, this.container);
|
|
185
|
+
}
|
|
186
|
+
setupTitleBar() {
|
|
187
|
+
const order = this.currentOptions.order;
|
|
188
|
+
const hasShadow = this.currentOptions.shadow;
|
|
189
|
+
(0, _get__("dom_1").addClass)(this.titlebar, `cet-${(0, _get__("platform_1").PlatformToString)(_get__("platform_1").platform).toLocaleLowerCase()}`);
|
|
190
|
+
if (order) {
|
|
191
|
+
(0, _get__("dom_1").addClass)(this.titlebar, `cet-${order}`);
|
|
192
|
+
}
|
|
193
|
+
if (hasShadow) {
|
|
194
|
+
(0, _get__("dom_1").addClass)(this.titlebar, 'cet-shadow');
|
|
195
|
+
}
|
|
196
|
+
if (!_get__("platform_1").isMacintosh) {
|
|
197
|
+
this.title.style.cursor = 'default';
|
|
198
|
+
}
|
|
199
|
+
(0, _get__("dom_1").prepend)(document.body, this.titlebar);
|
|
200
|
+
}
|
|
201
|
+
loadEvents() {
|
|
202
|
+
const onlyRendererMenuBar = this.currentOptions.onlyShowMenuBar;
|
|
203
|
+
if (onlyRendererMenuBar) return;
|
|
204
|
+
const minimizable = this.currentOptions.minimizable;
|
|
205
|
+
const maximizable = this.currentOptions.maximizable;
|
|
206
|
+
const closeable = this.currentOptions.closeable;
|
|
207
|
+
_get__("electron_1").ipcRenderer.on('window-maximize', (_, isMaximized) => this.onDidChangeMaximized(isMaximized));
|
|
208
|
+
_get__("electron_1").ipcRenderer.on('window-fullscreen', (_, isFullScreen) => this.onWindowFullScreen(isFullScreen));
|
|
209
|
+
_get__("electron_1").ipcRenderer.on('window-focus', (_, isFocused) => this.onWindowFocus(isFocused));
|
|
210
|
+
if (minimizable) {
|
|
211
|
+
(0, _get__("dom_1").addDisposableListener)(this.controls.minimize, _get__("dom_1").EventType.CLICK, () => {
|
|
212
|
+
_get__("electron_1").ipcRenderer.send('window-event', 'window-minimize');
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
if (_get__("platform_1").isMacintosh) {
|
|
216
|
+
(0, _get__("dom_1").addDisposableListener)(this.titlebar, _get__("dom_1").EventType.DBLCLICK, () => {
|
|
217
|
+
_get__("electron_1").ipcRenderer.send('window-event', 'window-maximize');
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
if (maximizable) {
|
|
221
|
+
(0, _get__("dom_1").addDisposableListener)(this.controls.maximize, _get__("dom_1").EventType.CLICK, () => {
|
|
222
|
+
_get__("electron_1").ipcRenderer.send('window-event', 'window-maximize');
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
if (closeable) {
|
|
226
|
+
(0, _get__("dom_1").addDisposableListener)(this.controls.close, _get__("dom_1").EventType.CLICK, () => {
|
|
227
|
+
_get__("electron_1").ipcRenderer.send('window-event', 'window-close');
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
onBlur() {
|
|
232
|
+
this.isInactive = true;
|
|
233
|
+
this.updateStyles();
|
|
234
|
+
}
|
|
235
|
+
onFocus() {
|
|
236
|
+
this.isInactive = false;
|
|
237
|
+
this.updateStyles();
|
|
238
|
+
}
|
|
239
|
+
onMenuBarVisibilityChanged(visible) {
|
|
240
|
+
if (_get__("platform_1").isWindows || _get__("platform_1").isLinux) {
|
|
241
|
+
if (visible) {
|
|
242
|
+
// Hack to fix issue #52522 with layered webkit-app-region elements appearing under cursor
|
|
243
|
+
(0, _get__("dom_1").hide)(this.dragRegion);
|
|
244
|
+
setTimeout(() => (0, _get__("dom_1").show)(this.dragRegion), 50);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
onMenuBarFocusChanged(focused) {
|
|
249
|
+
if (_get__("platform_1").isWindows || _get__("platform_1").isLinux) {
|
|
250
|
+
if (focused) (0, _get__("dom_1").hide)(this.dragRegion);else (0, _get__("dom_1").show)(this.dragRegion);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
onDidChangeMaximized(isMaximized) {
|
|
254
|
+
const maximize = this.controls.maximize;
|
|
255
|
+
if (maximize) {
|
|
256
|
+
maximize.title = isMaximized ? this.currentOptions.tooltips?.restoreDown : this.currentOptions.tooltips?.maximize;
|
|
257
|
+
maximize.innerHTML = isMaximized ? this.platformIcons.restore : this.platformIcons.maximize;
|
|
258
|
+
}
|
|
259
|
+
if (this.resizer) {
|
|
260
|
+
if (isMaximized) (0, _get__("dom_1").hide)(this.resizer.top, this.resizer.left);else (0, _get__("dom_1").show)(this.resizer.top, this.resizer.left);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
updateMenu(menu) {
|
|
264
|
+
if (_get__("platform_1").isMacintosh || !menu) return;
|
|
265
|
+
this.menuBar = new (_get__("menubar_1").MenuBar)(this.menuBarContainer, _get__("consts_1").menuIcons, this.currentOptions, {
|
|
266
|
+
enableMnemonics: true
|
|
267
|
+
}, this.closeMenu); // TODO: Verify menubar options
|
|
268
|
+
this.menuBar.push(menu);
|
|
269
|
+
this.menuBar.update();
|
|
270
|
+
this.menuBar.onVisibilityChange(e => this.onMenuBarVisibilityChanged(e));
|
|
271
|
+
this.menuBar.onFocusStateChange(e => this.onMenuBarFocusChanged(e));
|
|
272
|
+
this.updateStyles();
|
|
273
|
+
}
|
|
274
|
+
updateStyles() {
|
|
275
|
+
if (this.isInactive) {
|
|
276
|
+
(0, _get__("dom_1").addClass)(this.titlebar, 'inactive');
|
|
277
|
+
} else {
|
|
278
|
+
(0, _get__("dom_1").removeClass)(this.titlebar, 'inactive');
|
|
279
|
+
}
|
|
280
|
+
const backgroundColor = this.isInactive ? this.currentOptions.backgroundColor?.lighten(0.12) : this.currentOptions.backgroundColor;
|
|
281
|
+
if (backgroundColor) {
|
|
282
|
+
this.titlebar.style.backgroundColor = backgroundColor.toString();
|
|
283
|
+
}
|
|
284
|
+
let foregroundColor;
|
|
285
|
+
if (backgroundColor?.isLighter()) {
|
|
286
|
+
(0, _get__("dom_1").addClass)(this.titlebar, 'light');
|
|
287
|
+
foregroundColor = this.isInactive ? _get__("consts_1").INACTIVE_FOREGROUND_DARK : _get__("consts_1").ACTIVE_FOREGROUND_DARK;
|
|
288
|
+
} else {
|
|
289
|
+
(0, _get__("dom_1").removeClass)(this.titlebar, 'light');
|
|
290
|
+
foregroundColor = this.isInactive ? _get__("consts_1").INACTIVE_FOREGROUND : _get__("consts_1").ACTIVE_FOREGROUND;
|
|
291
|
+
}
|
|
292
|
+
this.titlebar.style.color = foregroundColor.toString();
|
|
293
|
+
if (this.menuBar) {
|
|
294
|
+
let fgColor;
|
|
295
|
+
const backgroundColor = this.currentOptions.menuBarBackgroundColor ?? this.currentOptions.backgroundColor?.darken(0.12);
|
|
296
|
+
const foregroundColor = backgroundColor?.isLighter() ? _get__("consts_1").INACTIVE_FOREGROUND_DARK : _get__("consts_1").INACTIVE_FOREGROUND;
|
|
297
|
+
const bgColor = !this.currentOptions.itemBackgroundColor || this.currentOptions.itemBackgroundColor.equals(backgroundColor) ? _get__("consts_1").DEFAULT_ITEM_SELECTOR : this.currentOptions.itemBackgroundColor;
|
|
298
|
+
if (bgColor.equals(_get__("consts_1").DEFAULT_ITEM_SELECTOR)) {
|
|
299
|
+
fgColor = backgroundColor?.isLighter() ? _get__("consts_1").ACTIVE_FOREGROUND_DARK : _get__("consts_1").ACTIVE_FOREGROUND;
|
|
300
|
+
} else {
|
|
301
|
+
fgColor = bgColor.isLighter() ? _get__("consts_1").ACTIVE_FOREGROUND_DARK : _get__("consts_1").ACTIVE_FOREGROUND;
|
|
302
|
+
}
|
|
303
|
+
this.menuBar.setStyles({
|
|
304
|
+
backgroundColor,
|
|
305
|
+
foregroundColor,
|
|
306
|
+
selectionBackgroundColor: bgColor,
|
|
307
|
+
selectionForegroundColor: fgColor,
|
|
308
|
+
separatorColor: this.currentOptions.menuSeparatorColor ?? foregroundColor,
|
|
309
|
+
svgColor: this.currentOptions.svgColor
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
/// Public methods
|
|
314
|
+
/**
|
|
315
|
+
* Update title bar styles based on focus state.
|
|
316
|
+
* @param hasFocus focus state of the window
|
|
317
|
+
*/
|
|
318
|
+
onWindowFocus(focus) {
|
|
319
|
+
if (this.titlebar) {
|
|
320
|
+
if (focus) {
|
|
321
|
+
(0, _get__("dom_1").removeClass)(this.titlebar, 'inactive');
|
|
322
|
+
this.onFocus();
|
|
323
|
+
} else {
|
|
324
|
+
(0, _get__("dom_1").addClass)(this.titlebar, 'inactive');
|
|
325
|
+
this.menuBar?.blur();
|
|
326
|
+
this.onBlur();
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Update the full screen state and hide or show the title bar.
|
|
332
|
+
* @param fullscreen Fullscreen state of the window
|
|
333
|
+
*/
|
|
334
|
+
onWindowFullScreen(fullscreen) {
|
|
335
|
+
if (!_get__("platform_1").isMacintosh) {
|
|
336
|
+
if (fullscreen) {
|
|
337
|
+
(0, _get__("dom_1").hide)(this.titlebar);
|
|
338
|
+
this.container.style.top = '0px';
|
|
339
|
+
} else {
|
|
340
|
+
(0, _get__("dom_1").show)(this.titlebar);
|
|
341
|
+
if (this.currentOptions.menuPosition === 'bottom') {
|
|
342
|
+
this.container.style.top = _get__("consts_1").BOTTOM_TITLEBAR_HEIGHT;
|
|
343
|
+
this.controlsContainer.style.height = _get__("consts_1").TOP_TITLEBAR_HEIGHT_WIN;
|
|
344
|
+
} else {
|
|
345
|
+
this.container.style.top = _get__("platform_1").isMacintosh ? _get__("consts_1").TOP_TITLEBAR_HEIGHT_MAC : _get__("consts_1").TOP_TITLEBAR_HEIGHT_WIN;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Update the title of the title bar.
|
|
352
|
+
* You can use this method if change the content of `<title>` tag on your html.
|
|
353
|
+
* @param title The title of the title bar and document.
|
|
354
|
+
*/
|
|
355
|
+
updateTitle(title) {
|
|
356
|
+
this.title.innerText = title;
|
|
357
|
+
document.title = title;
|
|
358
|
+
return this;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* It method set new icon to title-bar-icon of title-bar.
|
|
362
|
+
* @param path path to icon
|
|
363
|
+
*/
|
|
364
|
+
updateIcon(path) {
|
|
365
|
+
if (this.icon) {
|
|
366
|
+
this.icon.firstElementChild.setAttribute('src', path);
|
|
367
|
+
}
|
|
368
|
+
return this;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Horizontal alignment of the title.
|
|
372
|
+
* @param side `left`, `center` or `right`.
|
|
373
|
+
*/
|
|
374
|
+
updateTitleAlignment(side) {
|
|
375
|
+
const order = this.currentOptions.order;
|
|
376
|
+
const menuPosition = this.currentOptions.menuPosition;
|
|
377
|
+
if (side === 'left' || side === 'right' && order === 'inverted') {
|
|
378
|
+
(0, _get__("dom_1").removeClass)(this.title, 'cet-title-left');
|
|
379
|
+
(0, _get__("dom_1").removeClass)(this.title, 'cet-title-right');
|
|
380
|
+
(0, _get__("dom_1").removeClass)(this.title, 'cet-title-center');
|
|
381
|
+
(0, _get__("dom_1").addClass)(this.title, 'cet-title-left');
|
|
382
|
+
}
|
|
383
|
+
if (side === 'right' || side === 'left' && order === 'inverted') {
|
|
384
|
+
if (side !== 'left' && order !== 'inverted') {
|
|
385
|
+
this.controlsContainer.style.marginLeft = '10px';
|
|
386
|
+
}
|
|
387
|
+
(0, _get__("dom_1").removeClass)(this.title, 'cet-title-left');
|
|
388
|
+
(0, _get__("dom_1").removeClass)(this.title, 'cet-title-right');
|
|
389
|
+
(0, _get__("dom_1").removeClass)(this.title, 'cet-title-center');
|
|
390
|
+
(0, _get__("dom_1").addClass)(this.title, 'cet-title-right');
|
|
391
|
+
}
|
|
392
|
+
if (side === 'center') {
|
|
393
|
+
(0, _get__("dom_1").removeClass)(this.title, 'cet-title-left');
|
|
394
|
+
(0, _get__("dom_1").removeClass)(this.title, 'cet-title-right');
|
|
395
|
+
(0, _get__("dom_1").removeClass)(this.title, 'cet-title-center');
|
|
396
|
+
if (menuPosition !== 'bottom') {
|
|
397
|
+
/* addDisposableListener(window, 'resize', () => {
|
|
398
|
+
if (window.innerWidth >= 1188) {
|
|
399
|
+
addClass(this.title, 'cet-title-center')
|
|
400
|
+
} else {
|
|
401
|
+
removeClass(this.title, 'cet-title-center')
|
|
402
|
+
}
|
|
403
|
+
}) */
|
|
404
|
+
(0, _get__("dom_1").addClass)(this.title, 'cet-title-center');
|
|
405
|
+
}
|
|
406
|
+
if (!_get__("platform_1").isMacintosh && order === 'first-buttons') {
|
|
407
|
+
this.controlsContainer.style.marginLeft = 'auto';
|
|
408
|
+
}
|
|
409
|
+
this.title.style.maxWidth = 'calc(100% - 296px)';
|
|
410
|
+
}
|
|
411
|
+
return this;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Update the background color of the title bar
|
|
415
|
+
* @param backgroundColor The color for the background
|
|
416
|
+
*/
|
|
417
|
+
updateBackground(backgroundColor) {
|
|
418
|
+
this.currentOptions.backgroundColor = backgroundColor;
|
|
419
|
+
// this.updateStyles()
|
|
420
|
+
return this;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Update the item background color of the menubar
|
|
424
|
+
* @param itemBGColor The color for the item background
|
|
425
|
+
*/
|
|
426
|
+
updateItemBGColor(itemBGColor) {
|
|
427
|
+
this.currentOptions.itemBackgroundColor = itemBGColor;
|
|
428
|
+
// this._updateStyles()
|
|
429
|
+
return this;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Update the menu from Menu.getApplicationMenu()
|
|
433
|
+
*/
|
|
434
|
+
async refreshMenu() {
|
|
435
|
+
if (!_get__("platform_1").isMacintosh) {
|
|
436
|
+
_get__("electron_1").ipcRenderer.invoke('request-application-menu').then(menu => this.updateMenu(menu));
|
|
437
|
+
}
|
|
438
|
+
return this;
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Update the position of menubar.
|
|
442
|
+
* @param menuPosition The position of the menu `left` or `bottom`.
|
|
443
|
+
*/
|
|
444
|
+
updateMenuPosition(menuPosition) {
|
|
445
|
+
const height = _get__("platform_1").isMacintosh ? _get__("consts_1").TOP_TITLEBAR_HEIGHT_MAC : _get__("consts_1").TOP_TITLEBAR_HEIGHT_WIN;
|
|
446
|
+
const onlyRendererMenuBar = this.currentOptions.onlyShowMenuBar;
|
|
447
|
+
this.currentOptions.menuPosition = menuPosition;
|
|
448
|
+
if (menuPosition === 'left' || onlyRendererMenuBar) {
|
|
449
|
+
this.titlebar.style.height = height;
|
|
450
|
+
this.container.style.top = height;
|
|
451
|
+
(0, _get__("dom_1").removeClass)(this.menuBarContainer, 'bottom');
|
|
452
|
+
} else {
|
|
453
|
+
this.titlebar.style.height = _get__("consts_1").BOTTOM_TITLEBAR_HEIGHT;
|
|
454
|
+
this.container.style.top = _get__("consts_1").BOTTOM_TITLEBAR_HEIGHT;
|
|
455
|
+
this.controlsContainer.style.height = height;
|
|
456
|
+
(0, _get__("dom_1").addClass)(this.menuBarContainer, 'bottom');
|
|
457
|
+
}
|
|
458
|
+
return this;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Remove the titlebar, menubar and all methods.
|
|
462
|
+
*/
|
|
463
|
+
dispose() {
|
|
464
|
+
// if (this.menuBar) this.menuBar.dispose()
|
|
465
|
+
this.titlebar.remove();
|
|
466
|
+
while (this.container.firstChild) (0, _get__("dom_1").append)(document.body, this.container.firstChild);
|
|
467
|
+
this.container.remove();
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
exports.CustomTitlebar = _get__("CustomTitlebar");
|
|
471
|
+
function _getGlobalObject() {
|
|
472
|
+
try {
|
|
473
|
+
if (!!global) {
|
|
474
|
+
return global;
|
|
475
|
+
}
|
|
476
|
+
} catch (e) {
|
|
477
|
+
try {
|
|
478
|
+
if (!!window) {
|
|
479
|
+
return window;
|
|
480
|
+
}
|
|
481
|
+
} catch (e) {
|
|
482
|
+
return this;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
;
|
|
487
|
+
var _RewireModuleId__ = null;
|
|
488
|
+
function _getRewireModuleId__() {
|
|
489
|
+
if (_RewireModuleId__ === null) {
|
|
490
|
+
let globalVariable = _getGlobalObject();
|
|
491
|
+
if (!globalVariable.__$$GLOBAL_REWIRE_NEXT_MODULE_ID__) {
|
|
492
|
+
globalVariable.__$$GLOBAL_REWIRE_NEXT_MODULE_ID__ = 0;
|
|
493
|
+
}
|
|
494
|
+
_RewireModuleId__ = __$$GLOBAL_REWIRE_NEXT_MODULE_ID__++;
|
|
495
|
+
}
|
|
496
|
+
return _RewireModuleId__;
|
|
497
|
+
}
|
|
498
|
+
function _getRewireRegistry__() {
|
|
499
|
+
let theGlobalVariable = _getGlobalObject();
|
|
500
|
+
if (!theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__) {
|
|
501
|
+
theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__ = Object.create(null);
|
|
502
|
+
}
|
|
503
|
+
return theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__;
|
|
504
|
+
}
|
|
505
|
+
function _getRewiredData__() {
|
|
506
|
+
let moduleId = _getRewireModuleId__();
|
|
507
|
+
let registry = _getRewireRegistry__();
|
|
508
|
+
let rewireData = registry[moduleId];
|
|
509
|
+
if (!rewireData) {
|
|
510
|
+
registry[moduleId] = Object.create(null);
|
|
511
|
+
rewireData = registry[moduleId];
|
|
512
|
+
}
|
|
513
|
+
return rewireData;
|
|
514
|
+
}
|
|
515
|
+
(function registerResetAll() {
|
|
516
|
+
let theGlobalVariable = _getGlobalObject();
|
|
517
|
+
if (!theGlobalVariable['__rewire_reset_all__']) {
|
|
518
|
+
theGlobalVariable['__rewire_reset_all__'] = function () {
|
|
519
|
+
theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__ = Object.create(null);
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
})();
|
|
523
|
+
var INTENTIONAL_UNDEFINED = '__INTENTIONAL_UNDEFINED__';
|
|
524
|
+
let _RewireAPI__ = {};
|
|
525
|
+
(function () {
|
|
526
|
+
function addPropertyToAPIObject(name, value) {
|
|
527
|
+
Object.defineProperty(_RewireAPI__, name, {
|
|
528
|
+
value: value,
|
|
529
|
+
enumerable: false,
|
|
530
|
+
configurable: true
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
addPropertyToAPIObject('__get__', _get__);
|
|
534
|
+
addPropertyToAPIObject('__GetDependency__', _get__);
|
|
535
|
+
addPropertyToAPIObject('__Rewire__', _set__);
|
|
536
|
+
addPropertyToAPIObject('__set__', _set__);
|
|
537
|
+
addPropertyToAPIObject('__reset__', _reset__);
|
|
538
|
+
addPropertyToAPIObject('__ResetDependency__', _reset__);
|
|
539
|
+
addPropertyToAPIObject('__with__', _with__);
|
|
540
|
+
})();
|
|
541
|
+
function _get__(variableName) {
|
|
542
|
+
let rewireData = _getRewiredData__();
|
|
543
|
+
if (rewireData[variableName] === undefined) {
|
|
544
|
+
return _get_original__(variableName);
|
|
545
|
+
} else {
|
|
546
|
+
var value = rewireData[variableName];
|
|
547
|
+
if (value === INTENTIONAL_UNDEFINED) {
|
|
548
|
+
return undefined;
|
|
549
|
+
} else {
|
|
550
|
+
return value;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
function _get_original__(variableName) {
|
|
555
|
+
switch (variableName) {
|
|
556
|
+
case "consts_1":
|
|
557
|
+
return consts_1;
|
|
558
|
+
case "platform_1":
|
|
559
|
+
return platform_1;
|
|
560
|
+
case "dom_1":
|
|
561
|
+
return dom_1;
|
|
562
|
+
case "color_1":
|
|
563
|
+
return color_1;
|
|
564
|
+
case "electron_1":
|
|
565
|
+
return electron_1;
|
|
566
|
+
case "menubar_1":
|
|
567
|
+
return menubar_1;
|
|
568
|
+
case "themebar_1":
|
|
569
|
+
return themebar_1;
|
|
570
|
+
case "CustomTitlebar":
|
|
571
|
+
return CustomTitlebar;
|
|
572
|
+
}
|
|
573
|
+
return undefined;
|
|
574
|
+
}
|
|
575
|
+
function _assign__(variableName, value) {
|
|
576
|
+
let rewireData = _getRewiredData__();
|
|
577
|
+
if (rewireData[variableName] === undefined) {
|
|
578
|
+
return _set_original__(variableName, value);
|
|
579
|
+
} else {
|
|
580
|
+
return rewireData[variableName] = value;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
function _set_original__(variableName, _value) {
|
|
584
|
+
switch (variableName) {}
|
|
585
|
+
return undefined;
|
|
586
|
+
}
|
|
587
|
+
function _update_operation__(operation, variableName, prefix) {
|
|
588
|
+
var oldValue = _get__(variableName);
|
|
589
|
+
var newValue = operation === '++' ? oldValue + 1 : oldValue - 1;
|
|
590
|
+
_assign__(variableName, newValue);
|
|
591
|
+
return prefix ? newValue : oldValue;
|
|
592
|
+
}
|
|
593
|
+
function _set__(variableName, value) {
|
|
594
|
+
let rewireData = _getRewiredData__();
|
|
595
|
+
if (typeof variableName === 'object') {
|
|
596
|
+
Object.keys(variableName).forEach(function (name) {
|
|
597
|
+
rewireData[name] = variableName[name];
|
|
598
|
+
});
|
|
599
|
+
return function () {
|
|
600
|
+
Object.keys(variableName).forEach(function (name) {
|
|
601
|
+
_reset__(variableName);
|
|
602
|
+
});
|
|
603
|
+
};
|
|
604
|
+
} else {
|
|
605
|
+
if (value === undefined) {
|
|
606
|
+
rewireData[variableName] = INTENTIONAL_UNDEFINED;
|
|
607
|
+
} else {
|
|
608
|
+
rewireData[variableName] = value;
|
|
609
|
+
}
|
|
610
|
+
return function () {
|
|
611
|
+
_reset__(variableName);
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
function _reset__(variableName) {
|
|
616
|
+
let rewireData = _getRewiredData__();
|
|
617
|
+
delete rewireData[variableName];
|
|
618
|
+
if (Object.keys(rewireData).length == 0) {
|
|
619
|
+
delete _getRewireRegistry__()[_getRewireModuleId__];
|
|
620
|
+
}
|
|
621
|
+
;
|
|
622
|
+
}
|
|
623
|
+
function _with__(object) {
|
|
624
|
+
let rewireData = _getRewiredData__();
|
|
625
|
+
var rewiredVariableNames = Object.keys(object);
|
|
626
|
+
var previousValues = {};
|
|
627
|
+
function reset() {
|
|
628
|
+
rewiredVariableNames.forEach(function (variableName) {
|
|
629
|
+
rewireData[variableName] = previousValues[variableName];
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
return function (callback) {
|
|
633
|
+
rewiredVariableNames.forEach(function (variableName) {
|
|
634
|
+
previousValues[variableName] = rewireData[variableName];
|
|
635
|
+
rewireData[variableName] = object[variableName];
|
|
636
|
+
});
|
|
637
|
+
let result = callback();
|
|
638
|
+
if (!!result && typeof result.then == 'function') {
|
|
639
|
+
result.then(reset).catch(reset);
|
|
640
|
+
} else {
|
|
641
|
+
reset();
|
|
642
|
+
}
|
|
643
|
+
return result;
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
let _typeOfOriginalExport = typeof module.exports;
|
|
647
|
+
function addNonEnumerableProperty(name, value) {
|
|
648
|
+
Object.defineProperty(module.exports, name, {
|
|
649
|
+
value: value,
|
|
650
|
+
enumerable: false,
|
|
651
|
+
configurable: true
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
if ((_typeOfOriginalExport === 'object' || _typeOfOriginalExport === 'function') && Object.isExtensible(module.exports)) {
|
|
655
|
+
addNonEnumerableProperty('__get__', _get__);
|
|
656
|
+
addNonEnumerableProperty('__GetDependency__', _get__);
|
|
657
|
+
addNonEnumerableProperty('__Rewire__', _set__);
|
|
658
|
+
addNonEnumerableProperty('__set__', _set__);
|
|
659
|
+
addNonEnumerableProperty('__reset__', _reset__);
|
|
660
|
+
addNonEnumerableProperty('__ResetDependency__', _reset__);
|
|
661
|
+
addNonEnumerableProperty('__with__', _with__);
|
|
662
|
+
addNonEnumerableProperty('__RewireAPI__', _RewireAPI__);
|
|
663
|
+
}
|