stage-browser 0.1.0 → 0.2.0

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.
Files changed (172) hide show
  1. package/README.md +92 -45
  2. package/build/icon.icns +0 -0
  3. package/build/icon.png +0 -0
  4. package/dist/bin/stage.js +111 -0
  5. package/dist/main/cli-args.js +28 -0
  6. package/dist/main/context-menu.js +68 -0
  7. package/dist/main/context.js +2 -0
  8. package/dist/main/extensions.js +78 -0
  9. package/dist/main/ipc.js +73 -0
  10. package/dist/main/main.js +282 -0
  11. package/dist/main/menu.js +140 -0
  12. package/dist/main/reveal.js +170 -0
  13. package/dist/main/selftest.js +570 -0
  14. package/dist/main/store.js +85 -0
  15. package/dist/main/suggest.js +43 -0
  16. package/dist/main/tabs.js +324 -0
  17. package/dist/main/ui-window.js +133 -0
  18. package/dist/main/url.js +38 -0
  19. package/dist/main/window.js +133 -0
  20. package/dist/preload/extension-compat.js +163 -0
  21. package/dist/preload/ui-preload.js +34 -0
  22. package/dist/shared/contract.js +6 -0
  23. package/dist/ui/app.js +692 -0
  24. package/{src → dist}/ui/index.html +15 -5
  25. package/dist/ui/mock.js +500 -0
  26. package/{src → dist}/ui/styles.css +55 -14
  27. package/node_modules/@types/chrome/LICENSE +21 -0
  28. package/node_modules/@types/chrome/README.md +15 -0
  29. package/node_modules/@types/chrome/chrome-cast/index.d.ts +1156 -0
  30. package/node_modules/@types/chrome/har-format/index.d.ts +6 -0
  31. package/node_modules/@types/chrome/index.d.ts +13786 -0
  32. package/node_modules/@types/chrome/package.json +99 -0
  33. package/node_modules/@types/filesystem/LICENSE +21 -0
  34. package/node_modules/@types/filesystem/README.md +15 -0
  35. package/node_modules/@types/filesystem/index.d.ts +564 -0
  36. package/node_modules/@types/filesystem/package.json +26 -0
  37. package/node_modules/@types/filewriter/LICENSE +21 -0
  38. package/node_modules/@types/filewriter/README.md +15 -0
  39. package/node_modules/@types/filewriter/index.d.ts +166 -0
  40. package/node_modules/@types/filewriter/package.json +25 -0
  41. package/node_modules/@types/har-format/LICENSE +21 -0
  42. package/node_modules/@types/har-format/README.md +15 -0
  43. package/node_modules/@types/har-format/index.d.ts +938 -0
  44. package/node_modules/@types/har-format/package.json +31 -0
  45. package/node_modules/adm-zip/LICENSE +21 -0
  46. package/node_modules/adm-zip/README.md +90 -0
  47. package/node_modules/adm-zip/adm-zip.js +1020 -0
  48. package/node_modules/adm-zip/headers/entryHeader.js +396 -0
  49. package/node_modules/adm-zip/headers/index.js +2 -0
  50. package/node_modules/adm-zip/headers/mainHeader.js +177 -0
  51. package/node_modules/adm-zip/methods/deflater.js +33 -0
  52. package/node_modules/adm-zip/methods/index.js +3 -0
  53. package/node_modules/adm-zip/methods/inflater.js +64 -0
  54. package/node_modules/adm-zip/methods/zipcrypto.js +175 -0
  55. package/node_modules/adm-zip/package.json +56 -0
  56. package/node_modules/adm-zip/types.d.ts +223 -0
  57. package/node_modules/adm-zip/util/constants.js +142 -0
  58. package/node_modules/adm-zip/util/decoder.js +5 -0
  59. package/node_modules/adm-zip/util/errors.js +66 -0
  60. package/node_modules/adm-zip/util/fattr.js +76 -0
  61. package/node_modules/adm-zip/util/index.js +5 -0
  62. package/node_modules/adm-zip/util/utils.js +481 -0
  63. package/node_modules/adm-zip/zipEntry.js +415 -0
  64. package/node_modules/adm-zip/zipFile.js +466 -0
  65. package/node_modules/debug/LICENSE +20 -0
  66. package/node_modules/debug/README.md +481 -0
  67. package/node_modules/debug/package.json +64 -0
  68. package/node_modules/debug/src/browser.js +272 -0
  69. package/node_modules/debug/src/common.js +292 -0
  70. package/node_modules/debug/src/index.js +10 -0
  71. package/node_modules/debug/src/node.js +263 -0
  72. package/node_modules/electron-chrome-web-store/README.md +143 -0
  73. package/node_modules/electron-chrome-web-store/dist/chrome-web-store.preload.js +299 -0
  74. package/node_modules/electron-chrome-web-store/dist/cjs/browser/index.js +1674 -0
  75. package/node_modules/electron-chrome-web-store/dist/esm/browser/index.mjs +950 -0
  76. package/node_modules/electron-chrome-web-store/dist/types/browser/api.d.ts +2 -0
  77. package/node_modules/electron-chrome-web-store/dist/types/browser/crx3.d.ts +20 -0
  78. package/node_modules/electron-chrome-web-store/dist/types/browser/id.d.ts +9 -0
  79. package/node_modules/electron-chrome-web-store/dist/types/browser/index.d.ts +62 -0
  80. package/node_modules/electron-chrome-web-store/dist/types/browser/installer.d.ts +29 -0
  81. package/node_modules/electron-chrome-web-store/dist/types/browser/loader.d.ts +18 -0
  82. package/node_modules/electron-chrome-web-store/dist/types/browser/types.d.ts +21 -0
  83. package/node_modules/electron-chrome-web-store/dist/types/browser/updater.d.ts +6 -0
  84. package/node_modules/electron-chrome-web-store/dist/types/browser/utils.d.ts +4 -0
  85. package/node_modules/electron-chrome-web-store/dist/types/common/constants.d.ts +44 -0
  86. package/node_modules/electron-chrome-web-store/dist/types/renderer/chrome-web-store.preload.d.ts +1 -0
  87. package/node_modules/electron-chrome-web-store/package.json +43 -0
  88. package/node_modules/ms/index.js +162 -0
  89. package/node_modules/ms/license.md +21 -0
  90. package/node_modules/ms/package.json +38 -0
  91. package/node_modules/ms/readme.md +59 -0
  92. package/node_modules/pbf/LICENSE +27 -0
  93. package/node_modules/pbf/README.md +293 -0
  94. package/node_modules/pbf/bin/pbf +17 -0
  95. package/node_modules/pbf/compile.js +441 -0
  96. package/node_modules/pbf/dist/pbf-dev.js +838 -0
  97. package/node_modules/pbf/dist/pbf.js +1 -0
  98. package/node_modules/pbf/index.d.ts +206 -0
  99. package/node_modules/pbf/index.js +830 -0
  100. package/node_modules/pbf/package.json +63 -0
  101. package/node_modules/protocol-buffers-schema/.travis.yml +7 -0
  102. package/node_modules/protocol-buffers-schema/LICENSE +21 -0
  103. package/node_modules/protocol-buffers-schema/README.md +122 -0
  104. package/node_modules/protocol-buffers-schema/example.js +11 -0
  105. package/node_modules/protocol-buffers-schema/example.proto +13 -0
  106. package/node_modules/protocol-buffers-schema/index.js +6 -0
  107. package/node_modules/protocol-buffers-schema/package.json +31 -0
  108. package/node_modules/protocol-buffers-schema/parse.js +769 -0
  109. package/node_modules/protocol-buffers-schema/stringify.js +206 -0
  110. package/node_modules/protocol-buffers-schema/test/fixtures/basic.json +90 -0
  111. package/node_modules/protocol-buffers-schema/test/fixtures/basic.proto +11 -0
  112. package/node_modules/protocol-buffers-schema/test/fixtures/comments.json +99 -0
  113. package/node_modules/protocol-buffers-schema/test/fixtures/comments.proto +19 -0
  114. package/node_modules/protocol-buffers-schema/test/fixtures/complex.json +125 -0
  115. package/node_modules/protocol-buffers-schema/test/fixtures/complex.proto +30 -0
  116. package/node_modules/protocol-buffers-schema/test/fixtures/enum.json +42 -0
  117. package/node_modules/protocol-buffers-schema/test/fixtures/enum.proto +8 -0
  118. package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.json +32 -0
  119. package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.proto +3 -0
  120. package/node_modules/protocol-buffers-schema/test/fixtures/extend.json +167 -0
  121. package/node_modules/protocol-buffers-schema/test/fixtures/extend.proto +19 -0
  122. package/node_modules/protocol-buffers-schema/test/fixtures/import.json +30 -0
  123. package/node_modules/protocol-buffers-schema/test/fixtures/import.proto +6 -0
  124. package/node_modules/protocol-buffers-schema/test/fixtures/map.json +33 -0
  125. package/node_modules/protocol-buffers-schema/test/fixtures/map.proto +3 -0
  126. package/node_modules/protocol-buffers-schema/test/fixtures/no-tags.proto +8 -0
  127. package/node_modules/protocol-buffers-schema/test/fixtures/oneof.json +41 -0
  128. package/node_modules/protocol-buffers-schema/test/fixtures/oneof.proto +6 -0
  129. package/node_modules/protocol-buffers-schema/test/fixtures/option.json +364 -0
  130. package/node_modules/protocol-buffers-schema/test/fixtures/option.proto +72 -0
  131. package/node_modules/protocol-buffers-schema/test/fixtures/options.json +47 -0
  132. package/node_modules/protocol-buffers-schema/test/fixtures/options.proto +8 -0
  133. package/node_modules/protocol-buffers-schema/test/fixtures/pheromon-trajectories.proto +8 -0
  134. package/node_modules/protocol-buffers-schema/test/fixtures/reserved.json +55 -0
  135. package/node_modules/protocol-buffers-schema/test/fixtures/reserved.proto +17 -0
  136. package/node_modules/protocol-buffers-schema/test/fixtures/search.json +30 -0
  137. package/node_modules/protocol-buffers-schema/test/fixtures/search.proto +5 -0
  138. package/node_modules/protocol-buffers-schema/test/fixtures/service.json +108 -0
  139. package/node_modules/protocol-buffers-schema/test/fixtures/service.proto +30 -0
  140. package/node_modules/protocol-buffers-schema/test/fixtures/valid-packed.proto +35 -0
  141. package/node_modules/protocol-buffers-schema/test/fixtures/version.json +90 -0
  142. package/node_modules/protocol-buffers-schema/test/fixtures/version.proto +13 -0
  143. package/node_modules/protocol-buffers-schema/test/index.js +157 -0
  144. package/node_modules/protocol-buffers-schema/tokenize.js +56 -0
  145. package/node_modules/resolve-protobuf-schema/.travis.yml +3 -0
  146. package/node_modules/resolve-protobuf-schema/LICENSE +21 -0
  147. package/node_modules/resolve-protobuf-schema/README.md +49 -0
  148. package/node_modules/resolve-protobuf-schema/index.js +50 -0
  149. package/node_modules/resolve-protobuf-schema/package.json +25 -0
  150. package/node_modules/resolve-protobuf-schema/test/a.proto +5 -0
  151. package/node_modules/resolve-protobuf-schema/test/b.proto +5 -0
  152. package/node_modules/resolve-protobuf-schema/test/c.proto +3 -0
  153. package/node_modules/resolve-protobuf-schema/test/index.js +49 -0
  154. package/package.json +35 -11
  155. package/bin/stage.js +0 -52
  156. package/src/main/cli-args.js +0 -28
  157. package/src/main/context-menu.js +0 -64
  158. package/src/main/extensions.js +0 -61
  159. package/src/main/main.js +0 -310
  160. package/src/main/menu.js +0 -171
  161. package/src/main/reveal.js +0 -141
  162. package/src/main/selftest.js +0 -383
  163. package/src/main/store.js +0 -77
  164. package/src/main/suggest.js +0 -50
  165. package/src/main/tabs.js +0 -351
  166. package/src/main/url.js +0 -37
  167. package/src/main/window.js +0 -71
  168. package/src/preload/extension-compat.js +0 -34
  169. package/src/preload/ui-preload.js +0 -40
  170. package/src/ui/app.js +0 -588
  171. package/src/ui/mock.js +0 -455
  172. /package/{src → dist}/ui/newtab.html +0 -0
@@ -0,0 +1,282 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const electron_1 = require("electron");
4
+ const node_fs_1 = require("node:fs");
5
+ const node_os_1 = require("node:os");
6
+ const node_path_1 = require("node:path");
7
+ const contract_1 = require("../shared/contract");
8
+ const cli_args_1 = require("./cli-args");
9
+ const extensions_1 = require("./extensions");
10
+ const ipc_1 = require("./ipc");
11
+ const menu_1 = require("./menu");
12
+ const reveal_1 = require("./reveal");
13
+ const selftest_1 = require("./selftest");
14
+ const store_1 = require("./store");
15
+ const tabs_1 = require("./tabs");
16
+ const ui_window_1 = require("./ui-window");
17
+ const url_1 = require("./url");
18
+ const window_1 = require("./window");
19
+ const APP_ROOT = (0, node_path_1.resolve)(__dirname, '..', '..');
20
+ const SELFTEST = !!process.env.STAGE_SELFTEST;
21
+ const PUSH_MS = 16;
22
+ const SAVE_MS = 500;
23
+ const WEB_STORE_TIMEOUT_MS = 5000;
24
+ const ERROR_LOG_MAX_BYTES = 1_000_000;
25
+ electron_1.app.setName('Stage');
26
+ if (SELFTEST && !process.env.STAGE_USER_DATA)
27
+ process.env.STAGE_USER_DATA = (0, node_fs_1.mkdtempSync)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'stage-selftest-'));
28
+ electron_1.app.setPath('userData', process.env.STAGE_USER_DATA || (0, node_path_1.join)(electron_1.app.getPath('appData'), 'Stage'));
29
+ // Sites like Google and Okta reject "Electron" user agents as embedded browsers.
30
+ const cleanUA = (ua) => ua.replace(/\s(?:Electron|stage-browser|Stage)\/\S+/gi, '');
31
+ electron_1.app.userAgentFallback = cleanUA(electron_1.app.userAgentFallback);
32
+ function log(msg) {
33
+ const file = process.env.STAGE_LOG;
34
+ if (!file)
35
+ return;
36
+ try {
37
+ (0, node_fs_1.appendFileSync)(file, msg + '\n');
38
+ }
39
+ catch { }
40
+ }
41
+ // A modal error dialog in the middle of a live demo is worse than a lost click, so errors go to
42
+ // <userData>/stage.log. The selftest records its own.
43
+ if (!SELFTEST) {
44
+ const errorLog = (0, node_path_1.join)(electron_1.app.getPath('userData'), 'stage.log');
45
+ const record = (kind) => (err) => {
46
+ const line = `${new Date().toISOString()} ${kind} ${err instanceof Error ? err.stack : String(err)}\n`;
47
+ try {
48
+ if ((0, node_fs_1.existsSync)(errorLog) && (0, node_fs_1.statSync)(errorLog).size > ERROR_LOG_MAX_BYTES)
49
+ (0, node_fs_1.truncateSync)(errorLog, 0);
50
+ (0, node_fs_1.appendFileSync)(errorLog, line);
51
+ }
52
+ catch { }
53
+ if (process.stderr.isTTY)
54
+ process.stderr.write(line);
55
+ };
56
+ process.on('uncaughtException', record('uncaughtException'));
57
+ process.on('unhandledRejection', record('unhandledRejection'));
58
+ }
59
+ if (!SELFTEST && !electron_1.app.requestSingleInstanceLock())
60
+ electron_1.app.exit(0);
61
+ class Stage {
62
+ session;
63
+ win;
64
+ ui;
65
+ drag;
66
+ tabs;
67
+ reveal;
68
+ ext;
69
+ bar = { visible: false, pinned: false, hover: false };
70
+ // Kept apart from session.json so --fresh doesn't reset them.
71
+ prefs = (0, store_1.readPrefs)();
72
+ overlay = null;
73
+ popupOpen = false;
74
+ quitting = false;
75
+ holdQuit = false;
76
+ pushTimer;
77
+ saveTimer;
78
+ lastSent = '';
79
+ constructor(session, saved, args) {
80
+ this.session = session;
81
+ const win = (0, window_1.createWindow)(saved.bounds, args.size);
82
+ this.win = win;
83
+ this.ui = new ui_window_1.UiWindow(win);
84
+ this.drag = new window_1.WindowDrag(win);
85
+ this.bar.pinned = !!saved.pinned || args.pin;
86
+ this.tabs = new tabs_1.Tabs(this);
87
+ this.reveal = new reveal_1.Reveal(this);
88
+ this.ext = (0, extensions_1.createExtensions)(this);
89
+ (0, ipc_1.setupIpc)(this);
90
+ this.rebuildMenu();
91
+ const ui = this.ui.view.webContents;
92
+ ui.on('did-finish-load', () => {
93
+ this.lastSent = '';
94
+ this.flush();
95
+ });
96
+ ui.loadFile((0, node_path_1.join)(__dirname, '..', 'ui', 'index.html')).catch((e) => console.error('[stage] UI load failed', e.message));
97
+ const relayout = () => {
98
+ if (this.quitting)
99
+ return;
100
+ this.layout();
101
+ this.push();
102
+ };
103
+ win.on('resize', () => {
104
+ relayout();
105
+ this.saveSession();
106
+ });
107
+ win.on('move', () => this.saveSession());
108
+ win.on('enter-full-screen', relayout);
109
+ win.on('leave-full-screen', relayout);
110
+ win.on('close', () => this.shutdown());
111
+ win.on('closed', () => !this.holdQuit && electron_1.app.quit());
112
+ this.layout();
113
+ }
114
+ get live() {
115
+ return !this.quitting && !this.win.isDestroyed();
116
+ }
117
+ tabBounds() {
118
+ return (0, window_1.tabBounds)(this.win);
119
+ }
120
+ layout() {
121
+ if (this.win.isDestroyed() || this.ui.win.isDestroyed())
122
+ return;
123
+ this.ui.setBounds((0, window_1.uiBounds)(this.win, this.bar.pinned, this.overlay !== null));
124
+ this.tabs.layout();
125
+ }
126
+ getState() {
127
+ return {
128
+ ...this.tabs.snapshot(),
129
+ bar: { visible: this.bar.visible, pinned: this.bar.pinned },
130
+ hideExtensionIcons: this.prefs.hideExtensionIcons,
131
+ extensionActions: (0, extensions_1.actionCount)(this.session),
132
+ overlay: this.overlay,
133
+ barHeight: window_1.BAR_HEIGHT,
134
+ fullscreen: !this.win.isDestroyed() && this.win.isFullScreen(),
135
+ };
136
+ }
137
+ flush() {
138
+ clearTimeout(this.pushTimer);
139
+ this.pushTimer = undefined;
140
+ const wc = this.ui.view.webContents;
141
+ if (!this.live || wc.isDestroyed() || wc.isLoading())
142
+ return;
143
+ const state = this.getState();
144
+ const json = JSON.stringify(state);
145
+ if (json === this.lastSent)
146
+ return;
147
+ this.lastSent = json;
148
+ wc.send((0, contract_1.channel)('state'), state);
149
+ }
150
+ push() {
151
+ if (this.pushTimer || this.quitting)
152
+ return;
153
+ this.pushTimer = setTimeout(() => this.flush(), PUSH_MS);
154
+ }
155
+ saveSession() {
156
+ if (!this.live)
157
+ return;
158
+ clearTimeout(this.saveTimer);
159
+ this.saveTimer = setTimeout(() => this.writeSessionNow(), SAVE_MS);
160
+ }
161
+ writeSessionNow() {
162
+ if (!this.live)
163
+ return;
164
+ const { list, activeId } = this.tabs;
165
+ const keepBounds = this.win.isFullScreen() || this.win.isMinimized();
166
+ (0, store_1.writeSession)({
167
+ tabs: list.map((t) => t.url),
168
+ active: Math.max(0, list.findIndex((t) => t.id === activeId)),
169
+ pinned: this.bar.pinned,
170
+ bounds: keepBounds ? (0, store_1.readSession)().bounds : this.win.getBounds(),
171
+ });
172
+ }
173
+ rebuildMenu() {
174
+ electron_1.Menu.setApplicationMenu((0, menu_1.buildMenu)(this));
175
+ }
176
+ setHideExtensionIcons(hide) {
177
+ this.prefs.hideExtensionIcons = hide;
178
+ (0, store_1.writePrefs)(this.prefs);
179
+ this.push();
180
+ this.rebuildMenu();
181
+ }
182
+ applyArgs(args, initial) {
183
+ log('args ' + JSON.stringify(args));
184
+ if (args.size && !initial) {
185
+ this.win.setContentSize(args.size.width, args.size.height);
186
+ this.win.center();
187
+ }
188
+ if (args.pin && !initial)
189
+ this.reveal.setPinned(true);
190
+ const urls = args.urls.map(url_1.resolveInput).filter((u) => u !== null);
191
+ // The first launch keeps the first tab active; later invocations jump to the newest.
192
+ urls.forEach((url, i) => this.tabs.create({ url, activate: initial ? i === 0 : i === urls.length - 1 }));
193
+ }
194
+ restore(saved, args) {
195
+ if (args.urls.some((u) => (0, url_1.resolveInput)(u)))
196
+ return this.applyArgs(args, true);
197
+ const urls = saved.tabs ?? [];
198
+ if (!urls.length)
199
+ return void this.tabs.create();
200
+ for (const url of urls)
201
+ this.tabs.create({ url: url || undefined, activate: false });
202
+ const { list } = this.tabs;
203
+ const target = list[Math.min(saved.active ?? 0, list.length - 1)];
204
+ if (target)
205
+ this.tabs.activate(target.id);
206
+ }
207
+ // Writes what must survive, then stops every timer so nothing touches the window afterwards.
208
+ shutdown() {
209
+ if (this.quitting)
210
+ return;
211
+ this.writeSessionNow();
212
+ (0, store_1.flushHistory)();
213
+ this.quitting = true;
214
+ clearTimeout(this.pushTimer);
215
+ clearTimeout(this.saveTimer);
216
+ this.drag.end();
217
+ this.reveal.stop();
218
+ }
219
+ }
220
+ function setupDownloads(session) {
221
+ session.on('will-download', (_e, item) => {
222
+ const dir = electron_1.app.getPath('downloads');
223
+ const name = item.getFilename();
224
+ const ext = (0, node_path_1.extname)(name);
225
+ const base = (0, node_path_1.basename)(name, ext);
226
+ let target = (0, node_path_1.join)(dir, name);
227
+ for (let n = 1; (0, node_fs_1.existsSync)(target); n++)
228
+ target = (0, node_path_1.join)(dir, `${base} (${n})${ext}`);
229
+ item.setSavePath(target);
230
+ item.once('done', (_ev, state) => {
231
+ if (state === 'completed')
232
+ electron_1.app.dock?.downloadFinished(target);
233
+ });
234
+ });
235
+ }
236
+ let stage;
237
+ async function boot() {
238
+ const session = electron_1.session.fromPartition('persist:stage');
239
+ session.setUserAgent(cleanUA(session.getUserAgent()));
240
+ setupDownloads(session);
241
+ const args = SELFTEST ? { urls: [], size: null, pin: false, fresh: true } : (0, cli_args_1.parseArgs)(process.argv, APP_ROOT);
242
+ const saved = args.fresh ? {} : (0, store_1.readSession)();
243
+ const icon = (0, node_path_1.join)(APP_ROOT, 'build', 'icon.png');
244
+ if (electron_1.app.dock && (0, node_fs_1.existsSync)(icon))
245
+ electron_1.app.dock.setIcon(electron_1.nativeImage.createFromPath(icon));
246
+ const s = new Stage(session, saved, args);
247
+ stage = s;
248
+ // Load installed extensions before the first page so content scripts attach to it.
249
+ const timeout = new Promise((r) => setTimeout(r, WEB_STORE_TIMEOUT_MS));
250
+ await Promise.race([(0, extensions_1.setupWebStore)(s).catch((e) => console.error('[stage] web store setup failed', e.message)), timeout]);
251
+ s.rebuildMenu();
252
+ s.win.show();
253
+ s.reveal.syncPolling();
254
+ if (s.bar.pinned) {
255
+ s.reveal.show();
256
+ s.rebuildMenu();
257
+ }
258
+ if (SELFTEST)
259
+ return void (0, selftest_1.run)(s);
260
+ s.restore(saved, args);
261
+ log('ready tabs=' + s.tabs.list.length);
262
+ }
263
+ electron_1.app.on('second-instance', (_e, argv) => {
264
+ if (!stage || stage.win.isDestroyed())
265
+ return;
266
+ const { win } = stage;
267
+ if (win.isMinimized())
268
+ win.restore();
269
+ win.show();
270
+ win.focus();
271
+ electron_1.app.focus({ steal: true });
272
+ stage.applyArgs((0, cli_args_1.parseArgs)(argv, APP_ROOT), false);
273
+ });
274
+ electron_1.app.on('before-quit', () => stage?.shutdown());
275
+ electron_1.app.on('window-all-closed', () => !stage?.holdQuit && electron_1.app.quit());
276
+ electron_1.app
277
+ .whenReady()
278
+ .then(boot)
279
+ .catch((e) => {
280
+ console.error('[stage] boot failed', e);
281
+ electron_1.app.exit(1);
282
+ });
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildMenu = buildMenu;
4
+ const electron_1 = require("electron");
5
+ const node_child_process_1 = require("node:child_process");
6
+ const extensions_1 = require("./extensions");
7
+ const SIZES = [
8
+ [1280, 720],
9
+ [1440, 900],
10
+ [1600, 900],
11
+ [1920, 1080],
12
+ ];
13
+ const hidden = (accelerator, click) => ({ label: accelerator, accelerator, click, visible: false });
14
+ function buildMenu(ctx) {
15
+ const { tabs, reveal, win } = ctx;
16
+ const withActive = (fn) => () => {
17
+ const t = tabs.active;
18
+ if (t)
19
+ fn(t.wc);
20
+ };
21
+ const openInChrome = () => {
22
+ const url = tabs.active?.url;
23
+ if (url)
24
+ (0, node_child_process_1.execFile)('open', ['-a', 'Google Chrome', url], () => { });
25
+ };
26
+ const extItems = (0, extensions_1.installed)(ctx.session).map((e) => ({
27
+ label: `${e.name} ${e.version}`,
28
+ submenu: [
29
+ {
30
+ label: 'Remove',
31
+ click: async () => {
32
+ await (0, extensions_1.remove)(ctx.session, e.id).catch((err) => console.error('[stage] remove failed', err.message));
33
+ ctx.rebuildMenu();
34
+ },
35
+ },
36
+ ],
37
+ }));
38
+ return electron_1.Menu.buildFromTemplate([
39
+ {
40
+ label: 'Stage',
41
+ submenu: [
42
+ { role: 'about', label: 'About Stage' },
43
+ { type: 'separator' },
44
+ { role: 'hide', label: 'Hide Stage' },
45
+ { role: 'hideOthers' },
46
+ { role: 'unhide' },
47
+ { type: 'separator' },
48
+ { role: 'quit', label: 'Quit Stage' },
49
+ ],
50
+ },
51
+ {
52
+ label: 'File',
53
+ submenu: [
54
+ { label: 'New Tab', accelerator: 'CmdOrCtrl+T', click: () => reveal.openOverlay('new', '') },
55
+ { label: 'Open Location…', accelerator: 'CmdOrCtrl+L', click: () => reveal.openOverlay('edit', tabs.active?.url ?? '') },
56
+ { label: 'Reopen Closed Tab', accelerator: 'CmdOrCtrl+Shift+T', click: () => tabs.reopenClosed() },
57
+ { label: 'Close Tab', accelerator: 'CmdOrCtrl+W', click: () => tabs.active && tabs.close(tabs.active.id) },
58
+ { type: 'separator' },
59
+ { label: 'Open in Google Chrome', accelerator: 'CmdOrCtrl+Shift+O', click: openInChrome },
60
+ ],
61
+ },
62
+ {
63
+ label: 'Edit',
64
+ submenu: [
65
+ { role: 'undo' },
66
+ { role: 'redo' },
67
+ { type: 'separator' },
68
+ { role: 'cut' },
69
+ { role: 'copy' },
70
+ { role: 'paste' },
71
+ { role: 'pasteAndMatchStyle' },
72
+ { role: 'selectAll' },
73
+ ],
74
+ },
75
+ {
76
+ label: 'View',
77
+ submenu: [
78
+ { label: 'Reload', accelerator: 'CmdOrCtrl+R', click: withActive((wc) => wc.reload()) },
79
+ { label: 'Hard Reload', accelerator: 'CmdOrCtrl+Shift+R', click: withActive((wc) => wc.reloadIgnoringCache()) },
80
+ { type: 'separator' },
81
+ { label: 'Pin Tab Bar', type: 'checkbox', checked: ctx.bar.pinned, accelerator: 'CmdOrCtrl+Shift+B', click: () => reveal.setPinned(!ctx.bar.pinned) },
82
+ { type: 'separator' },
83
+ { label: 'Zoom In', accelerator: 'CmdOrCtrl+=', click: () => tabs.zoom(0.1) },
84
+ hidden('CmdOrCtrl+Plus', () => tabs.zoom(0.1)),
85
+ { label: 'Zoom Out', accelerator: 'CmdOrCtrl+-', click: () => tabs.zoom(-0.1) },
86
+ { label: 'Actual Size', accelerator: 'CmdOrCtrl+0', click: () => tabs.zoom(0) },
87
+ { type: 'separator' },
88
+ {
89
+ label: 'Window Size',
90
+ submenu: SIZES.map(([w, h]) => ({
91
+ label: `${w} × ${h}`,
92
+ click: () => {
93
+ if (win.isFullScreen())
94
+ return;
95
+ win.setContentSize(w, h);
96
+ win.center();
97
+ },
98
+ })),
99
+ },
100
+ { label: 'Enter Full Screen', accelerator: 'Ctrl+Command+F', click: () => win.setFullScreen(!win.isFullScreen()) },
101
+ { type: 'separator' },
102
+ {
103
+ label: 'Developer Tools',
104
+ accelerator: 'CmdOrCtrl+Alt+I',
105
+ click: withActive((wc) => (wc.isDevToolsOpened() ? wc.closeDevTools() : wc.openDevTools({ mode: 'detach' }))),
106
+ },
107
+ ],
108
+ },
109
+ {
110
+ label: 'History',
111
+ submenu: [
112
+ { label: 'Back', accelerator: 'CmdOrCtrl+[', click: withActive((wc) => wc.navigationHistory.goBack()) },
113
+ { label: 'Forward', accelerator: 'CmdOrCtrl+]', click: withActive((wc) => wc.navigationHistory.goForward()) },
114
+ ],
115
+ },
116
+ {
117
+ label: 'Tab',
118
+ submenu: [
119
+ { label: 'Next Tab', accelerator: 'Ctrl+Tab', click: () => tabs.step(1) },
120
+ { label: 'Previous Tab', accelerator: 'Ctrl+Shift+Tab', click: () => tabs.step(-1) },
121
+ hidden('CmdOrCtrl+Shift+]', () => tabs.step(1)),
122
+ hidden('CmdOrCtrl+Shift+[', () => tabs.step(-1)),
123
+ hidden('CmdOrCtrl+Alt+Right', () => tabs.step(1)),
124
+ hidden('CmdOrCtrl+Alt+Left', () => tabs.step(-1)),
125
+ { type: 'separator' },
126
+ ...[1, 2, 3, 4, 5, 6, 7, 8, 9].map((n) => ({ label: n === 9 ? 'Last Tab' : `Tab ${n}`, accelerator: `CmdOrCtrl+${n}`, click: () => tabs.goTo(n) })),
127
+ ],
128
+ },
129
+ {
130
+ label: 'Extensions',
131
+ submenu: [
132
+ { label: 'Open Chrome Web Store', click: () => void tabs.create({ url: extensions_1.WEB_STORE_URL, index: tabs.insertIndexAfterActive() }) },
133
+ { label: 'Hide Icons in Tab Bar', type: 'checkbox', checked: ctx.prefs.hideExtensionIcons, click: (item) => ctx.setHideExtensionIcons(item.checked) },
134
+ { type: 'separator' },
135
+ ...(extItems.length ? extItems : [{ label: 'No extensions installed', enabled: false }]),
136
+ ],
137
+ },
138
+ { role: 'windowMenu' },
139
+ ]);
140
+ }
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Reveal = void 0;
4
+ const electron_1 = require("electron");
5
+ const window_1 = require("./window");
6
+ const POLL_MS = 60;
7
+ const REVEAL_PX = 6;
8
+ const HIDE_BELOW = window_1.BAR_HEIGHT + 24;
9
+ const HIDE_DELAY = 350;
10
+ const VIEW_HIDE_DELAY = 180;
11
+ // Shows the tab bar when the cursor touches the top edge and hides it once the cursor leaves.
12
+ class Reveal {
13
+ ctx;
14
+ timer;
15
+ viewTimer;
16
+ awaySince = null;
17
+ constructor(ctx) {
18
+ this.ctx = ctx;
19
+ const sync = () => this.syncPolling();
20
+ ctx.win.on('show', sync);
21
+ ctx.win.on('hide', sync);
22
+ ctx.win.on('minimize', sync);
23
+ ctx.win.on('restore', sync);
24
+ }
25
+ get live() {
26
+ return !this.ctx.quitting && !this.ctx.win.isDestroyed();
27
+ }
28
+ syncPolling() {
29
+ const { win } = this.ctx;
30
+ const should = this.live && win.isVisible() && !win.isMinimized();
31
+ if (should && !this.timer)
32
+ this.timer = setInterval(() => this.tick(), POLL_MS);
33
+ else if (!should && this.timer) {
34
+ clearInterval(this.timer);
35
+ this.timer = undefined;
36
+ }
37
+ }
38
+ keepOpen() {
39
+ const { bar, overlay, popupOpen } = this.ctx;
40
+ return bar.pinned || overlay !== null || bar.hover || popupOpen;
41
+ }
42
+ tick() {
43
+ const { ctx } = this;
44
+ if (!this.live)
45
+ return this.stop();
46
+ const pt = electron_1.screen.getCursorScreenPoint();
47
+ const b = ctx.win.getContentBounds();
48
+ const insideX = pt.x >= b.x && pt.x < b.x + b.width;
49
+ const dy = pt.y - b.y;
50
+ this.syncPointer(insideX && dy >= 0 && dy < window_1.BAR_HEIGHT);
51
+ if (insideX && dy >= 0 && dy <= REVEAL_PX) {
52
+ this.awaySince = null;
53
+ return this.show();
54
+ }
55
+ if (!ctx.bar.visible)
56
+ return;
57
+ const away = !insideX || dy < 0 || dy > HIDE_BELOW;
58
+ if (this.keepOpen() || !away) {
59
+ this.awaySince = null;
60
+ return;
61
+ }
62
+ if (this.awaySince === null)
63
+ this.awaySince = Date.now();
64
+ else if (Date.now() - this.awaySince >= HIDE_DELAY)
65
+ this.hide();
66
+ }
67
+ // The UI window takes the mouse over the strip and lets it through to the page below it. The
68
+ // window can't tell the two apart itself, so this follows the polled cursor; a click that lands
69
+ // in the shadow room before the next tick is passed on by the UI (passClick).
70
+ syncPointer(overStrip) {
71
+ const { ctx } = this;
72
+ ctx.ui.setInteractive(ctx.overlay !== null || ctx.drag.active || overStrip);
73
+ }
74
+ cancelViewHide() {
75
+ clearTimeout(this.viewTimer);
76
+ this.viewTimer = undefined;
77
+ }
78
+ show() {
79
+ const { ctx } = this;
80
+ if (!this.live)
81
+ return;
82
+ this.cancelViewHide();
83
+ if (ctx.bar.visible && ctx.ui.shown)
84
+ return;
85
+ ctx.bar.visible = true;
86
+ ctx.layout();
87
+ ctx.flush(); // state first, then the window
88
+ ctx.ui.setShown(true);
89
+ }
90
+ hide() {
91
+ const { ctx } = this;
92
+ if (!this.live || !ctx.bar.visible)
93
+ return;
94
+ this.awaySince = null;
95
+ ctx.bar.visible = false;
96
+ ctx.flush();
97
+ this.cancelViewHide();
98
+ this.viewTimer = setTimeout(() => {
99
+ this.viewTimer = undefined;
100
+ if (this.live && !ctx.bar.visible && !ctx.overlay)
101
+ this.hideWindow();
102
+ }, VIEW_HIDE_DELAY);
103
+ }
104
+ // Hide without the exit animation, so the next mouse events go straight to the page.
105
+ hideNow() {
106
+ const { ctx } = this;
107
+ if (!this.live || ctx.overlay || ctx.bar.pinned)
108
+ return;
109
+ this.hide();
110
+ this.cancelViewHide();
111
+ this.hideWindow();
112
+ }
113
+ hideWindow() {
114
+ const { ctx } = this;
115
+ ctx.ui.setShown(false);
116
+ // No mouseleave arrives once the window is gone.
117
+ ctx.bar.hover = false;
118
+ }
119
+ setPinned(pinned) {
120
+ const { ctx } = this;
121
+ if (ctx.bar.pinned === pinned)
122
+ return;
123
+ ctx.bar.pinned = pinned;
124
+ if (pinned)
125
+ this.show();
126
+ ctx.layout();
127
+ ctx.push();
128
+ ctx.saveSession();
129
+ ctx.rebuildMenu();
130
+ }
131
+ setHover(hovering) {
132
+ this.ctx.bar.hover = hovering;
133
+ if (hovering)
134
+ this.awaySince = null;
135
+ }
136
+ setPopupOpen(open) {
137
+ this.ctx.popupOpen = open;
138
+ this.awaySince = null;
139
+ }
140
+ openOverlay(mode, initial) {
141
+ const { ctx } = this;
142
+ if (!this.live)
143
+ return;
144
+ ctx.overlay = { type: 'omnibox', mode, initial, nonce: Date.now() };
145
+ this.show();
146
+ ctx.layout();
147
+ ctx.flush();
148
+ ctx.ui.setShown(true);
149
+ ctx.ui.setInteractive(true);
150
+ ctx.ui.focus();
151
+ }
152
+ closeOverlay(refocus = true) {
153
+ const { ctx } = this;
154
+ if (!ctx.overlay)
155
+ return;
156
+ ctx.overlay = null;
157
+ ctx.layout();
158
+ ctx.flush();
159
+ ctx.ui.release();
160
+ this.syncPointer(false);
161
+ if (refocus)
162
+ ctx.tabs.focusActive();
163
+ }
164
+ stop() {
165
+ clearInterval(this.timer);
166
+ this.timer = undefined;
167
+ this.cancelViewHide();
168
+ }
169
+ }
170
+ exports.Reveal = Reveal;