stage-browser 0.0.0-stage → 0.1.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.
Files changed (154) hide show
  1. package/README.md +136 -2
  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 +90 -0
  10. package/dist/main/main.js +279 -0
  11. package/dist/main/menu.js +140 -0
  12. package/dist/main/reveal.js +155 -0
  13. package/dist/main/selftest.js +490 -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/url.js +38 -0
  18. package/dist/main/window.js +68 -0
  19. package/dist/preload/extension-compat.js +163 -0
  20. package/dist/preload/ui-preload.js +33 -0
  21. package/dist/shared/contract.js +6 -0
  22. package/dist/ui/app.js +653 -0
  23. package/dist/ui/index.html +41 -0
  24. package/dist/ui/mock.js +479 -0
  25. package/dist/ui/newtab.html +69 -0
  26. package/dist/ui/styles.css +410 -0
  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 +64 -4
@@ -0,0 +1,279 @@
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 url_1 = require("./url");
17
+ const window_1 = require("./window");
18
+ const APP_ROOT = (0, node_path_1.resolve)(__dirname, '..', '..');
19
+ const SELFTEST = !!process.env.STAGE_SELFTEST;
20
+ const PUSH_MS = 16;
21
+ const SAVE_MS = 500;
22
+ const WEB_STORE_TIMEOUT_MS = 5000;
23
+ const ERROR_LOG_MAX_BYTES = 1_000_000;
24
+ electron_1.app.setName('Stage');
25
+ if (SELFTEST && !process.env.STAGE_USER_DATA)
26
+ process.env.STAGE_USER_DATA = (0, node_fs_1.mkdtempSync)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'stage-selftest-'));
27
+ electron_1.app.setPath('userData', process.env.STAGE_USER_DATA || (0, node_path_1.join)(electron_1.app.getPath('appData'), 'Stage'));
28
+ // Sites like Google and Okta reject "Electron" user agents as embedded browsers.
29
+ const cleanUA = (ua) => ua.replace(/\s(?:Electron|stage-browser|Stage)\/\S+/gi, '');
30
+ electron_1.app.userAgentFallback = cleanUA(electron_1.app.userAgentFallback);
31
+ function log(msg) {
32
+ const file = process.env.STAGE_LOG;
33
+ if (!file)
34
+ return;
35
+ try {
36
+ (0, node_fs_1.appendFileSync)(file, msg + '\n');
37
+ }
38
+ catch { }
39
+ }
40
+ // A modal error dialog in the middle of a live demo is worse than a lost click, so errors go to
41
+ // <userData>/stage.log. The selftest records its own.
42
+ if (!SELFTEST) {
43
+ const errorLog = (0, node_path_1.join)(electron_1.app.getPath('userData'), 'stage.log');
44
+ const record = (kind) => (err) => {
45
+ const line = `${new Date().toISOString()} ${kind} ${err instanceof Error ? err.stack : String(err)}\n`;
46
+ try {
47
+ if ((0, node_fs_1.existsSync)(errorLog) && (0, node_fs_1.statSync)(errorLog).size > ERROR_LOG_MAX_BYTES)
48
+ (0, node_fs_1.truncateSync)(errorLog, 0);
49
+ (0, node_fs_1.appendFileSync)(errorLog, line);
50
+ }
51
+ catch { }
52
+ if (process.stderr.isTTY)
53
+ process.stderr.write(line);
54
+ };
55
+ process.on('uncaughtException', record('uncaughtException'));
56
+ process.on('unhandledRejection', record('unhandledRejection'));
57
+ }
58
+ if (!SELFTEST && !electron_1.app.requestSingleInstanceLock())
59
+ electron_1.app.exit(0);
60
+ class Stage {
61
+ session;
62
+ win;
63
+ uiView;
64
+ tabs;
65
+ reveal;
66
+ ext;
67
+ bar = { visible: false, pinned: false, hover: false };
68
+ // Kept apart from session.json so --fresh doesn't reset them.
69
+ prefs = (0, store_1.readPrefs)();
70
+ overlay = null;
71
+ popupOpen = false;
72
+ quitting = false;
73
+ holdQuit = false;
74
+ endDrag;
75
+ pushTimer;
76
+ saveTimer;
77
+ lastSent = '';
78
+ constructor(session, saved, args) {
79
+ this.session = session;
80
+ const { win, uiView } = (0, window_1.createWindow)(saved.bounds, args.size);
81
+ this.win = win;
82
+ this.uiView = uiView;
83
+ this.bar.pinned = !!saved.pinned || args.pin;
84
+ this.tabs = new tabs_1.Tabs(this);
85
+ this.reveal = new reveal_1.Reveal(this);
86
+ this.ext = (0, extensions_1.createExtensions)(this);
87
+ this.endDrag = (0, ipc_1.setupIpc)(this);
88
+ this.rebuildMenu();
89
+ uiView.webContents.on('did-finish-load', () => {
90
+ this.lastSent = '';
91
+ this.flush();
92
+ });
93
+ uiView.webContents.loadFile((0, node_path_1.join)(__dirname, '..', 'ui', 'index.html')).catch((e) => console.error('[stage] UI load failed', e.message));
94
+ const relayout = () => {
95
+ if (this.quitting)
96
+ return;
97
+ this.layout();
98
+ this.push();
99
+ };
100
+ win.on('resize', () => {
101
+ relayout();
102
+ this.saveSession();
103
+ });
104
+ win.on('move', () => this.saveSession());
105
+ win.on('enter-full-screen', relayout);
106
+ win.on('leave-full-screen', relayout);
107
+ win.on('close', () => this.shutdown());
108
+ win.on('closed', () => !this.holdQuit && electron_1.app.quit());
109
+ this.layout();
110
+ }
111
+ get live() {
112
+ return !this.quitting && !this.win.isDestroyed();
113
+ }
114
+ tabBounds() {
115
+ return (0, window_1.tabBounds)(this.win, this.bar.pinned);
116
+ }
117
+ layout() {
118
+ if (this.win.isDestroyed() || this.uiView.webContents.isDestroyed())
119
+ return;
120
+ this.uiView.setBounds((0, window_1.uiBounds)(this.win, this.bar.pinned, this.overlay !== null));
121
+ this.tabs.layout();
122
+ }
123
+ getState() {
124
+ return {
125
+ ...this.tabs.snapshot(),
126
+ bar: { visible: this.bar.visible, pinned: this.bar.pinned },
127
+ hideExtensionIcons: this.prefs.hideExtensionIcons,
128
+ extensionActions: (0, extensions_1.actionCount)(this.session),
129
+ overlay: this.overlay,
130
+ barHeight: window_1.BAR_HEIGHT,
131
+ fullscreen: !this.win.isDestroyed() && this.win.isFullScreen(),
132
+ };
133
+ }
134
+ flush() {
135
+ clearTimeout(this.pushTimer);
136
+ this.pushTimer = undefined;
137
+ const wc = this.uiView.webContents;
138
+ if (!this.live || wc.isDestroyed() || wc.isLoading())
139
+ return;
140
+ const state = this.getState();
141
+ const json = JSON.stringify(state);
142
+ if (json === this.lastSent)
143
+ return;
144
+ this.lastSent = json;
145
+ wc.send((0, contract_1.channel)('state'), state);
146
+ }
147
+ push() {
148
+ if (this.pushTimer || this.quitting)
149
+ return;
150
+ this.pushTimer = setTimeout(() => this.flush(), PUSH_MS);
151
+ }
152
+ saveSession() {
153
+ if (!this.live)
154
+ return;
155
+ clearTimeout(this.saveTimer);
156
+ this.saveTimer = setTimeout(() => this.writeSessionNow(), SAVE_MS);
157
+ }
158
+ writeSessionNow() {
159
+ if (!this.live)
160
+ return;
161
+ const { list, activeId } = this.tabs;
162
+ const keepBounds = this.win.isFullScreen() || this.win.isMinimized();
163
+ (0, store_1.writeSession)({
164
+ tabs: list.map((t) => t.url),
165
+ active: Math.max(0, list.findIndex((t) => t.id === activeId)),
166
+ pinned: this.bar.pinned,
167
+ bounds: keepBounds ? (0, store_1.readSession)().bounds : this.win.getBounds(),
168
+ });
169
+ }
170
+ rebuildMenu() {
171
+ electron_1.Menu.setApplicationMenu((0, menu_1.buildMenu)(this));
172
+ }
173
+ setHideExtensionIcons(hide) {
174
+ this.prefs.hideExtensionIcons = hide;
175
+ (0, store_1.writePrefs)(this.prefs);
176
+ this.push();
177
+ this.rebuildMenu();
178
+ }
179
+ applyArgs(args, initial) {
180
+ log('args ' + JSON.stringify(args));
181
+ if (args.size && !initial) {
182
+ this.win.setContentSize(args.size.width, args.size.height);
183
+ this.win.center();
184
+ }
185
+ if (args.pin && !initial)
186
+ this.reveal.setPinned(true);
187
+ const urls = args.urls.map(url_1.resolveInput).filter((u) => u !== null);
188
+ // The first launch keeps the first tab active; later invocations jump to the newest.
189
+ urls.forEach((url, i) => this.tabs.create({ url, activate: initial ? i === 0 : i === urls.length - 1 }));
190
+ }
191
+ restore(saved, args) {
192
+ if (args.urls.some((u) => (0, url_1.resolveInput)(u)))
193
+ return this.applyArgs(args, true);
194
+ const urls = saved.tabs ?? [];
195
+ if (!urls.length)
196
+ return void this.tabs.create();
197
+ for (const url of urls)
198
+ this.tabs.create({ url: url || undefined, activate: false });
199
+ const { list } = this.tabs;
200
+ const target = list[Math.min(saved.active ?? 0, list.length - 1)];
201
+ if (target)
202
+ this.tabs.activate(target.id);
203
+ }
204
+ // Writes what must survive, then stops every timer so nothing touches the window afterwards.
205
+ shutdown() {
206
+ if (this.quitting)
207
+ return;
208
+ this.writeSessionNow();
209
+ (0, store_1.flushHistory)();
210
+ this.quitting = true;
211
+ clearTimeout(this.pushTimer);
212
+ clearTimeout(this.saveTimer);
213
+ this.endDrag();
214
+ this.reveal.stop();
215
+ }
216
+ }
217
+ function setupDownloads(session) {
218
+ session.on('will-download', (_e, item) => {
219
+ const dir = electron_1.app.getPath('downloads');
220
+ const name = item.getFilename();
221
+ const ext = (0, node_path_1.extname)(name);
222
+ const base = (0, node_path_1.basename)(name, ext);
223
+ let target = (0, node_path_1.join)(dir, name);
224
+ for (let n = 1; (0, node_fs_1.existsSync)(target); n++)
225
+ target = (0, node_path_1.join)(dir, `${base} (${n})${ext}`);
226
+ item.setSavePath(target);
227
+ item.once('done', (_ev, state) => {
228
+ if (state === 'completed')
229
+ electron_1.app.dock?.downloadFinished(target);
230
+ });
231
+ });
232
+ }
233
+ let stage;
234
+ async function boot() {
235
+ const session = electron_1.session.fromPartition('persist:stage');
236
+ session.setUserAgent(cleanUA(session.getUserAgent()));
237
+ setupDownloads(session);
238
+ const args = SELFTEST ? { urls: [], size: null, pin: false, fresh: true } : (0, cli_args_1.parseArgs)(process.argv, APP_ROOT);
239
+ const saved = args.fresh ? {} : (0, store_1.readSession)();
240
+ const icon = (0, node_path_1.join)(APP_ROOT, 'build', 'icon.png');
241
+ if (electron_1.app.dock && (0, node_fs_1.existsSync)(icon))
242
+ electron_1.app.dock.setIcon(electron_1.nativeImage.createFromPath(icon));
243
+ const s = new Stage(session, saved, args);
244
+ stage = s;
245
+ // Load installed extensions before the first page so content scripts attach to it.
246
+ const timeout = new Promise((r) => setTimeout(r, WEB_STORE_TIMEOUT_MS));
247
+ await Promise.race([(0, extensions_1.setupWebStore)(s).catch((e) => console.error('[stage] web store setup failed', e.message)), timeout]);
248
+ s.rebuildMenu();
249
+ s.win.show();
250
+ s.reveal.syncPolling();
251
+ if (s.bar.pinned) {
252
+ s.reveal.show();
253
+ s.rebuildMenu();
254
+ }
255
+ if (SELFTEST)
256
+ return void (0, selftest_1.run)(s);
257
+ s.restore(saved, args);
258
+ log('ready tabs=' + s.tabs.list.length);
259
+ }
260
+ electron_1.app.on('second-instance', (_e, argv) => {
261
+ if (!stage || stage.win.isDestroyed())
262
+ return;
263
+ const { win } = stage;
264
+ if (win.isMinimized())
265
+ win.restore();
266
+ win.show();
267
+ win.focus();
268
+ electron_1.app.focus({ steal: true });
269
+ stage.applyArgs((0, cli_args_1.parseArgs)(argv, APP_ROOT), false);
270
+ });
271
+ electron_1.app.on('before-quit', () => stage?.shutdown());
272
+ electron_1.app.on('window-all-closed', () => !stage?.holdQuit && electron_1.app.quit());
273
+ electron_1.app
274
+ .whenReady()
275
+ .then(boot)
276
+ .catch((e) => {
277
+ console.error('[stage] boot failed', e);
278
+ electron_1.app.exit(1);
279
+ });
@@ -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,155 @@
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
+ if (insideX && dy >= 0 && dy <= REVEAL_PX) {
51
+ this.awaySince = null;
52
+ return this.show();
53
+ }
54
+ if (!ctx.bar.visible)
55
+ return;
56
+ const away = !insideX || dy < 0 || dy > HIDE_BELOW;
57
+ if (this.keepOpen() || !away) {
58
+ this.awaySince = null;
59
+ return;
60
+ }
61
+ if (this.awaySince === null)
62
+ this.awaySince = Date.now();
63
+ else if (Date.now() - this.awaySince >= HIDE_DELAY)
64
+ this.hide();
65
+ }
66
+ cancelViewHide() {
67
+ clearTimeout(this.viewTimer);
68
+ this.viewTimer = undefined;
69
+ }
70
+ show() {
71
+ const { ctx } = this;
72
+ if (!this.live)
73
+ return;
74
+ this.cancelViewHide();
75
+ if (ctx.bar.visible && ctx.uiView.getVisible())
76
+ return;
77
+ ctx.bar.visible = true;
78
+ ctx.layout();
79
+ ctx.flush(); // state first, then the view
80
+ ctx.uiView.setVisible(true);
81
+ ctx.win.setWindowButtonVisibility(true);
82
+ }
83
+ hide() {
84
+ const { ctx } = this;
85
+ if (!this.live || !ctx.bar.visible)
86
+ return;
87
+ this.awaySince = null;
88
+ ctx.bar.visible = false;
89
+ ctx.flush();
90
+ ctx.win.setWindowButtonVisibility(false);
91
+ this.cancelViewHide();
92
+ this.viewTimer = setTimeout(() => {
93
+ this.viewTimer = undefined;
94
+ if (this.live && !ctx.bar.visible && !ctx.overlay)
95
+ ctx.uiView.setVisible(false);
96
+ }, VIEW_HIDE_DELAY);
97
+ }
98
+ // Hide without the exit animation, so the next mouse events go straight to the page.
99
+ hideNow() {
100
+ const { ctx } = this;
101
+ if (!this.live || ctx.overlay || ctx.bar.pinned)
102
+ return;
103
+ this.hide();
104
+ this.cancelViewHide();
105
+ ctx.uiView.setVisible(false);
106
+ }
107
+ setPinned(pinned) {
108
+ const { ctx } = this;
109
+ if (ctx.bar.pinned === pinned)
110
+ return;
111
+ ctx.bar.pinned = pinned;
112
+ if (pinned)
113
+ this.show();
114
+ ctx.layout();
115
+ ctx.push();
116
+ ctx.saveSession();
117
+ ctx.rebuildMenu();
118
+ }
119
+ setHover(hovering) {
120
+ this.ctx.bar.hover = hovering;
121
+ if (hovering)
122
+ this.awaySince = null;
123
+ }
124
+ setPopupOpen(open) {
125
+ this.ctx.popupOpen = open;
126
+ this.awaySince = null;
127
+ }
128
+ openOverlay(mode, initial) {
129
+ const { ctx } = this;
130
+ if (!this.live)
131
+ return;
132
+ ctx.overlay = { type: 'omnibox', mode, initial, nonce: Date.now() };
133
+ this.show();
134
+ ctx.layout();
135
+ ctx.flush();
136
+ ctx.uiView.setVisible(true);
137
+ ctx.uiView.webContents.focus();
138
+ }
139
+ closeOverlay(refocus = true) {
140
+ const { ctx } = this;
141
+ if (!ctx.overlay)
142
+ return;
143
+ ctx.overlay = null;
144
+ ctx.layout();
145
+ ctx.flush();
146
+ if (refocus)
147
+ ctx.tabs.focusActive();
148
+ }
149
+ stop() {
150
+ clearInterval(this.timer);
151
+ this.timer = undefined;
152
+ this.cancelViewHide();
153
+ }
154
+ }
155
+ exports.Reveal = Reveal;