-
-
Notifications
You must be signed in to change notification settings - Fork 401
/
Copy paththemedwindow.ts
156 lines (146 loc) · 4.58 KB
/
themedwindow.ts
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import { BrowserWindow } from 'electron';
import * as fs from 'fs';
import * as path from 'path';
import { DarkThemeBGColor, LightThemeBGColor } from '../utils';
export class ThemedWindow {
constructor(options: ThemedWindow.IOptions) {
this._isDarkTheme = options.isDarkTheme;
this._closable = options.closable !== false;
this._window = new BrowserWindow({
parent: options.parent,
modal: options.modal,
title: options.title,
width: options.width,
height: options.height,
show: false,
closable: this._closable,
resizable: options.resizable !== false,
titleBarStyle: 'hidden',
frame: process.platform === 'darwin',
backgroundColor: this._isDarkTheme ? DarkThemeBGColor : LightThemeBGColor,
webPreferences: {
preload: options.preload || path.join(__dirname, './preload.js')
}
});
// hide the traffic lights
if (process.platform === 'darwin') {
this._window.setWindowButtonVisibility(false);
}
this._window.setMenuBarVisibility(false);
this._window.webContents.on('did-finish-load', () => {
this._window.show();
});
}
get window(): BrowserWindow {
return this._window;
}
close() {
this._window.closable = true;
this._window.close();
}
loadDialogContent(bodyHtml: string) {
let toolkitJsSrc = fs
.readFileSync(
path.join(__dirname, '../../../jupyter-ui-toolkit/toolkit.js')
)
.toString();
toolkitJsSrc = `
${toolkitJsSrc};
{
const darkTheme = ${this._isDarkTheme.toString()};
document.body.dataset.jpThemeLight = !darkTheme;
document.body.dataset.jpThemeName = 'jlab-desktop-theme';
provideJupyterDesignSystem().register(allComponents);
addJupyterLabThemeChangeListener();
}
`;
const titlebarJsSrc = fs.readFileSync(
path.join(__dirname, './dialogtitlebar.js')
);
const pageSource = `
<html>
<head>
<style>
:root {
--jp-brand-color1: var(--md-blue-700);
--jp-border-width: 1px;
--jp-border-color1: var(--md-grey-400);
--jp-ui-font-size1: 13px;
--md-grey-400: #78909C;
--md-blue-700: #1976D2;
}
body {
margin: 0;
background: ${LightThemeBGColor};
color: #000000;
font-size: var(--type-ramp-base-font-size);
font-family: var(--body-font);
-webkit-user-select: none;
user-select: none;
}
body.app-ui-dark {
background: ${DarkThemeBGColor};
color: #ffffff;
}
.page-container {
display: flex;
flex-direction: column;
height: 100%;
}
.jlab-dialog-body {
visibility: hidden;
flex-grow: 1;
padding: 10px;
overflow-y: auto;
}
</style>
<script type="module">${toolkitJsSrc}</script>
<script type="module">${titlebarJsSrc}</script>
<script>
document.addEventListener("DOMContentLoaded", () => {
const platform = "${process.platform}";
document.body.dataset.appPlatform = platform;
document.body.classList.add('app-ui-' + platform);
});
window.addEventListener('load', () => {
document.getElementById('jlab-dialog-body').style.visibility = 'visible';
});
</script>
</head>
<body class="${this._isDarkTheme ? 'app-ui-dark' : ''}">
<div class="page-container">
<jlab-dialog-titlebar id="title-bar" data-title="${
this._window.title
}" data-closable="${this._closable ? 'true' : 'false'}" class="${
this._isDarkTheme ? 'app-ui-dark' : ''
}"></jlab-dialog-titlebar>
<div id="jlab-dialog-body" class="jlab-dialog-body">
${bodyHtml}
</div>
</div>
</body>
</html>
`;
this._window.loadURL(
`data:text/html;charset=utf-8,${encodeURIComponent(pageSource)}`
);
}
private _isDarkTheme: boolean;
private _closable: boolean;
private _window: BrowserWindow;
}
export namespace ThemedWindow {
export interface IOptions {
isDarkTheme: boolean;
parent?: BrowserWindow;
modal?: boolean;
title: string;
width: number;
height: number;
closable?: boolean;
resizable?: boolean;
preload?: string;
}
}