-
-
Notifications
You must be signed in to change notification settings - Fork 474
Expand file tree
/
Copy pathtitlebarview.ts
More file actions
88 lines (74 loc) · 2.15 KB
/
Copy pathtitlebarview.ts
File metadata and controls
88 lines (74 loc) · 2.15 KB
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
84
85
86
87
88
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import { BrowserView } from 'electron';
import * as path from 'path';
import * as fs from 'fs';
import * as ejs from 'ejs';
import {
DarkThemeBGColor,
hardenedWebPreferences,
LightThemeBGColor
} from '../utils';
import { EventTypeRenderer } from '../eventtypes';
export class TitleBarView {
constructor(options: TitleBarView.IOptions) {
this._isDarkTheme = options.isDarkTheme;
this._view = new BrowserView({
webPreferences: hardenedWebPreferences({
preload: path.join(__dirname, './preload.js'),
devTools: process.env.NODE_ENV === 'development'
})
});
this._view.setBackgroundColor(
this._isDarkTheme ? DarkThemeBGColor : LightThemeBGColor
);
// prevent Ctrl +/- zoom
this._view.webContents.on('before-input-event', (event, input) => {
if (input.control && ['+', '-'].includes(input.key)) {
event.preventDefault();
}
});
}
get view(): BrowserView {
return this._view;
}
setTitle(title: string) {
this._view.webContents.send(EventTypeRenderer.SetTitle, title);
}
activate() {
this._view.webContents.send(EventTypeRenderer.SetActive, true);
}
deactivate() {
this._view.webContents.send(EventTypeRenderer.SetActive, false);
}
load() {
let pageSource = fs
.readFileSync(
path.join(__dirname, '../../../app-assets/titlebarview/titlebar.html')
)
.toString();
pageSource = ejs.render(pageSource, {
isDarkTheme: this._isDarkTheme,
platform: process.platform
});
this._view.webContents.loadURL(
`data:text/html;charset=utf-8,${encodeURIComponent(pageSource)}`
);
}
showServerStatus(show: boolean) {
this._view.webContents.send(EventTypeRenderer.ShowServerStatus, show);
}
showServerNotificationBadge(show: boolean) {
this._view.webContents.send(
EventTypeRenderer.ShowServerNotificationBadge,
show
);
}
private _view: BrowserView;
private _isDarkTheme: boolean;
}
export namespace TitleBarView {
export interface IOptions {
isDarkTheme: boolean;
}
}