electrobun 0.0.19-beta.13 → 0.0.19-beta.130

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 (100) hide show
  1. package/BUILD.md +90 -0
  2. package/README.md +1 -1
  3. package/bin/electrobun.cjs +2 -9
  4. package/debug.js +5 -0
  5. package/dist/api/browser/builtinrpcSchema.ts +19 -0
  6. package/dist/api/browser/index.ts +409 -0
  7. package/dist/api/browser/rpc/webview.ts +79 -0
  8. package/dist/api/browser/stylesAndElements.ts +3 -0
  9. package/dist/api/browser/webviewtag.ts +586 -0
  10. package/dist/api/bun/ElectrobunConfig.ts +171 -0
  11. package/dist/api/bun/core/ApplicationMenu.ts +66 -0
  12. package/dist/api/bun/core/BrowserView.ts +349 -0
  13. package/dist/api/bun/core/BrowserWindow.ts +195 -0
  14. package/dist/api/bun/core/ContextMenu.ts +67 -0
  15. package/dist/api/bun/core/Paths.ts +5 -0
  16. package/dist/api/bun/core/Socket.ts +181 -0
  17. package/dist/api/bun/core/Tray.ts +121 -0
  18. package/dist/api/bun/core/Updater.ts +681 -0
  19. package/dist/api/bun/core/Utils.ts +48 -0
  20. package/dist/api/bun/events/ApplicationEvents.ts +14 -0
  21. package/dist/api/bun/events/event.ts +29 -0
  22. package/dist/api/bun/events/eventEmitter.ts +45 -0
  23. package/dist/api/bun/events/trayEvents.ts +9 -0
  24. package/dist/api/bun/events/webviewEvents.ts +16 -0
  25. package/dist/api/bun/events/windowEvents.ts +12 -0
  26. package/dist/api/bun/index.ts +47 -0
  27. package/dist/api/bun/proc/linux.md +43 -0
  28. package/dist/api/bun/proc/native.ts +1322 -0
  29. package/dist/api/shared/platform.ts +48 -0
  30. package/dist/main.js +54 -0
  31. package/package.json +11 -6
  32. package/src/cli/index.ts +1353 -239
  33. package/templates/hello-world/README.md +57 -0
  34. package/templates/hello-world/bun.lock +225 -0
  35. package/templates/hello-world/electrobun.config.ts +28 -0
  36. package/templates/hello-world/package.json +16 -0
  37. package/templates/hello-world/src/bun/index.ts +15 -0
  38. package/templates/hello-world/src/mainview/index.css +124 -0
  39. package/templates/hello-world/src/mainview/index.html +46 -0
  40. package/templates/hello-world/src/mainview/index.ts +1 -0
  41. package/templates/interactive-playground/README.md +26 -0
  42. package/templates/interactive-playground/assets/tray-icon.png +0 -0
  43. package/templates/interactive-playground/electrobun.config.ts +36 -0
  44. package/templates/interactive-playground/package-lock.json +36 -0
  45. package/templates/interactive-playground/package.json +15 -0
  46. package/templates/interactive-playground/src/bun/demos/files.ts +70 -0
  47. package/templates/interactive-playground/src/bun/demos/menus.ts +139 -0
  48. package/templates/interactive-playground/src/bun/demos/rpc.ts +83 -0
  49. package/templates/interactive-playground/src/bun/demos/system.ts +72 -0
  50. package/templates/interactive-playground/src/bun/demos/updates.ts +105 -0
  51. package/templates/interactive-playground/src/bun/demos/windows.ts +90 -0
  52. package/templates/interactive-playground/src/bun/index.ts +124 -0
  53. package/templates/interactive-playground/src/bun/types/rpc.ts +109 -0
  54. package/templates/interactive-playground/src/mainview/components/EventLog.ts +107 -0
  55. package/templates/interactive-playground/src/mainview/components/Sidebar.ts +65 -0
  56. package/templates/interactive-playground/src/mainview/components/Toast.ts +57 -0
  57. package/templates/interactive-playground/src/mainview/demos/FileDemo.ts +211 -0
  58. package/templates/interactive-playground/src/mainview/demos/MenuDemo.ts +102 -0
  59. package/templates/interactive-playground/src/mainview/demos/RPCDemo.ts +229 -0
  60. package/templates/interactive-playground/src/mainview/demos/TrayDemo.ts +132 -0
  61. package/templates/interactive-playground/src/mainview/demos/WebViewDemo.ts +411 -0
  62. package/templates/interactive-playground/src/mainview/demos/WindowDemo.ts +207 -0
  63. package/templates/interactive-playground/src/mainview/index.css +538 -0
  64. package/templates/interactive-playground/src/mainview/index.html +103 -0
  65. package/templates/interactive-playground/src/mainview/index.ts +238 -0
  66. package/templates/multitab-browser/README.md +34 -0
  67. package/templates/multitab-browser/bun.lock +224 -0
  68. package/templates/multitab-browser/electrobun.config.ts +32 -0
  69. package/templates/multitab-browser/package-lock.json +20 -0
  70. package/templates/multitab-browser/package.json +12 -0
  71. package/templates/multitab-browser/src/bun/index.ts +144 -0
  72. package/templates/multitab-browser/src/bun/tabManager.ts +200 -0
  73. package/templates/multitab-browser/src/bun/types/rpc.ts +78 -0
  74. package/templates/multitab-browser/src/mainview/index.css +487 -0
  75. package/templates/multitab-browser/src/mainview/index.html +94 -0
  76. package/templates/multitab-browser/src/mainview/index.ts +630 -0
  77. package/templates/photo-booth/README.md +108 -0
  78. package/templates/photo-booth/bun.lock +239 -0
  79. package/templates/photo-booth/electrobun.config.ts +28 -0
  80. package/templates/photo-booth/package.json +16 -0
  81. package/templates/photo-booth/src/bun/index.ts +92 -0
  82. package/templates/photo-booth/src/mainview/index.css +465 -0
  83. package/templates/photo-booth/src/mainview/index.html +124 -0
  84. package/templates/photo-booth/src/mainview/index.ts +499 -0
  85. package/tests/bun.lock +14 -0
  86. package/tests/electrobun.config.ts +45 -0
  87. package/tests/package-lock.json +36 -0
  88. package/tests/package.json +13 -0
  89. package/tests/src/bun/index.ts +100 -0
  90. package/tests/src/bun/test-runner.ts +508 -0
  91. package/tests/src/mainview/index.html +110 -0
  92. package/tests/src/mainview/index.ts +458 -0
  93. package/tests/src/mainview/styles/main.css +451 -0
  94. package/tests/src/testviews/tray-test.html +57 -0
  95. package/tests/src/testviews/webview-mask.html +114 -0
  96. package/tests/src/testviews/webview-navigation.html +36 -0
  97. package/tests/src/testviews/window-create.html +17 -0
  98. package/tests/src/testviews/window-events.html +29 -0
  99. package/tests/src/testviews/window-focus.html +37 -0
  100. package/tests/src/webviewtag/index.ts +11 -0
@@ -0,0 +1,48 @@
1
+ import { ffi } from "../proc/native";
2
+
3
+ // TODO: move this to a more appropriate namespace
4
+ export const moveToTrash = (path: string) => {
5
+ return ffi.request.moveToTrash({ path });
6
+ };
7
+
8
+ export const showItemInFolder = (path: string) => {
9
+ return ffi.request.showItemInFolder({ path });
10
+ };
11
+
12
+ export const openFileDialog = async (
13
+ opts: {
14
+ startingFolder?: string;
15
+ allowedFileTypes?: string;
16
+ canChooseFiles?: boolean;
17
+ canChooseDirectory?: boolean;
18
+ allowsMultipleSelection?: boolean;
19
+ } = {}
20
+ ): Promise<string[]> => {
21
+ const optsWithDefault = {
22
+ ...{
23
+ startingFolder: "~/",
24
+ allowedFileTypes: "*",
25
+ canChooseFiles: true,
26
+ canChooseDirectory: true,
27
+ allowsMultipleSelection: true,
28
+ },
29
+ ...opts,
30
+ };
31
+
32
+ // todo: extend the timeout for this one (this version of rpc-anywhere doesn't seem to be able to set custom timeouts per request)
33
+ // we really want it to be infinity since the open file dialog blocks everything anyway.
34
+ // todo: there's the timeout between bun and zig, and the timeout between browser and bun since user likely requests
35
+ // from a browser context
36
+ const result = await ffi.request.openFileDialog({
37
+ startingFolder: optsWithDefault.startingFolder,
38
+ allowedFileTypes: optsWithDefault.allowedFileTypes,
39
+ canChooseFiles: optsWithDefault.canChooseFiles,
40
+ canChooseDirectory: optsWithDefault.canChooseDirectory,
41
+ allowsMultipleSelection: optsWithDefault.allowsMultipleSelection,
42
+ });
43
+
44
+ const filePaths = result.split(",");
45
+
46
+ // todo: it's nested like this due to zig union types. needs a zig refactor and revisit
47
+ return filePaths;
48
+ };
@@ -0,0 +1,14 @@
1
+ import ElectrobunEvent from "./event";
2
+
3
+ export default {
4
+ applicationMenuClicked: (data) =>
5
+ new ElectrobunEvent<{ id: number; action: string }, { allow: boolean }>(
6
+ "application-menu-clicked",
7
+ data
8
+ ),
9
+ contextMenuClicked: (data) =>
10
+ new ElectrobunEvent<{ id: number; action: string }, { allow: boolean }>(
11
+ "context-menu-clicked",
12
+ data
13
+ ),
14
+ };
@@ -0,0 +1,29 @@
1
+ export default class ElectrobunEvent<DataType, ResponseType> {
2
+ // todo (yoav): make most of these readonly except for response
3
+ name: string;
4
+ data: DataType;
5
+ // todo (yoav): define getters and setters for response
6
+ _response: ResponseType | undefined;
7
+ responseWasSet: boolean = false;
8
+
9
+ constructor(name: string, data: DataType) {
10
+ this.name = name;
11
+ this.data = data;
12
+ }
13
+
14
+ // Getter for response
15
+ get response(): ResponseType | undefined {
16
+ return this._response;
17
+ }
18
+
19
+ // Setter for response
20
+ set response(value: ResponseType) {
21
+ this._response = value;
22
+ this.responseWasSet = true; // Update flag when response is set
23
+ }
24
+
25
+ clearResponse() {
26
+ this._response = undefined;
27
+ this.responseWasSet = false;
28
+ }
29
+ }
@@ -0,0 +1,45 @@
1
+ import EventEmitter from "events";
2
+ import windowEvents from "./windowEvents";
3
+ import webviewEvents from "./webviewEvents";
4
+ import trayEvents from "./trayEvents";
5
+ import applicationEvents from "./ApplicationEvents";
6
+ import ElectrobunEvent from "./event";
7
+
8
+ class ElectrobunEventEmitter extends EventEmitter {
9
+ constructor() {
10
+ super();
11
+ }
12
+
13
+ // optionally pass in a specifier to make the event name specific.
14
+ // eg: will-navigate is listened to globally for all webviews, but
15
+ // will-navigate-1 is listened to for a specific webview with id 1
16
+ emitEvent(
17
+ ElectrobunEvent: ElectrobunEvent<any, any>,
18
+ specifier?: number | string
19
+ ) {
20
+ if (specifier) {
21
+ this.emit(`${ElectrobunEvent.name}-${specifier}`, ElectrobunEvent);
22
+ } else {
23
+ this.emit(ElectrobunEvent.name, ElectrobunEvent);
24
+ }
25
+ }
26
+
27
+ events = {
28
+ window: {
29
+ ...windowEvents,
30
+ },
31
+ webview: {
32
+ ...webviewEvents,
33
+ },
34
+ tray: {
35
+ ...trayEvents,
36
+ },
37
+ app: {
38
+ ...applicationEvents,
39
+ },
40
+ };
41
+ }
42
+
43
+ export const electrobunEventEmitter = new ElectrobunEventEmitter();
44
+
45
+ export default electrobunEventEmitter;
@@ -0,0 +1,9 @@
1
+ import ElectrobunEvent from "./event";
2
+
3
+ export default {
4
+ trayClicked: (data) =>
5
+ new ElectrobunEvent<{ id: number; action: string }, { allow: boolean }>(
6
+ "tray-clicked",
7
+ data
8
+ ),
9
+ };
@@ -0,0 +1,16 @@
1
+ import ElectrobunEvent from "./event";
2
+
3
+ export default {
4
+ willNavigate: (data) =>
5
+ new ElectrobunEvent<{ detail: string }, {}>("will-navigate", data),
6
+ didNavigate: (data) =>
7
+ new ElectrobunEvent<{ detail: string }, {}>("did-navigate", data),
8
+ didNavigateInPage: (data) =>
9
+ new ElectrobunEvent<{ detail: string }, {}>("did-navigate-in-page", data),
10
+ didCommitNavigation: (data) =>
11
+ new ElectrobunEvent<{ detail: string }, {}>("did-commit-navigation", data),
12
+ domReady: (data) =>
13
+ new ElectrobunEvent<{ detail: string }, {}>("dom-ready", data),
14
+ newWindowOpen: (data) =>
15
+ new ElectrobunEvent<{ detail: string }, {}>("new-window-open", data),
16
+ };
@@ -0,0 +1,12 @@
1
+ import ElectrobunEvent from "./event";
2
+
3
+ export default {
4
+ close: (data) => new ElectrobunEvent<{ id: number }, {}>("close", data),
5
+ resize: (data) =>
6
+ new ElectrobunEvent<
7
+ { id: number; x: number; y: number; width: number; height: number },
8
+ {}
9
+ >("resize", data),
10
+ move: (data) =>
11
+ new ElectrobunEvent<{ id: number; x: number; y: number }, {}>("move", data),
12
+ };
@@ -0,0 +1,47 @@
1
+ import electobunEventEmmitter from "./events/eventEmitter";
2
+ import { BrowserWindow } from "./core/BrowserWindow";
3
+ import { BrowserView } from "./core/BrowserView";
4
+ import { Tray } from "./core/Tray";
5
+ import * as ApplicationMenu from "./core/ApplicationMenu";
6
+ import * as ContextMenu from "./core/ContextMenu";
7
+ import { Updater } from "./core/Updater";
8
+ import * as Utils from "./core/Utils";
9
+ import { type RPCSchema, createRPC } from "rpc-anywhere";
10
+ import type ElectrobunEvent from "./events/event";
11
+ import * as PATHS from "./core/Paths";
12
+ import * as Socket from "./core/Socket";
13
+ import type { ElectrobunConfig } from "./ElectrobunConfig";
14
+
15
+ // Named Exports
16
+ export {
17
+ type RPCSchema,
18
+ type ElectrobunEvent,
19
+ type ElectrobunConfig,
20
+ createRPC,
21
+ BrowserWindow,
22
+ BrowserView,
23
+ Tray,
24
+ Updater,
25
+ Utils,
26
+ ApplicationMenu,
27
+ ContextMenu,
28
+ PATHS,
29
+ Socket,
30
+ };
31
+
32
+ // Default Export
33
+ const Electrobun = {
34
+ BrowserWindow,
35
+ BrowserView,
36
+ Tray,
37
+ Updater,
38
+ Utils,
39
+ ApplicationMenu,
40
+ ContextMenu,
41
+ events: electobunEventEmmitter,
42
+ PATHS,
43
+ Socket,
44
+ };
45
+
46
+ // Electrobun
47
+ export default Electrobun;
@@ -0,0 +1,43 @@
1
+
2
+ ## Linux System Tray Support
3
+
4
+ System tray functionality on Linux requires a compatible desktop environment or additional packages. Many modern Linux distributions (especially those using GNOME 3.26+) don't display system trays by default.
5
+
6
+ ### Installation Instructions by Desktop Environment
7
+
8
+ You probably need to tell users to install whatever system tray thing works on their linux distro or whatever.
9
+
10
+ **For Unity:**
11
+ ```bash
12
+ # Install indicator support
13
+ sudo apt install indicator-application
14
+
15
+ ```
16
+
17
+ **For KDE Plasma, XFCE, MATE, Cinnamon:**
18
+ - System tray support works out of the box, no additional installation needed
19
+
20
+ ### Alternative Installation Method
21
+
22
+ You can also install the GNOME extension through your web browser:
23
+ 1. Visit https://extensions.gnome.org/extension/615/appindicator-support/
24
+ 2. Install the browser extension if prompted
25
+ 3. Click the toggle to enable the extension
26
+
27
+ ### Verifying Installation
28
+
29
+ After installation and restart, system tray icons should appear in your top panel (usually top-right corner). If the tray still doesn't appear, your application will continue to function normally without tray support.
30
+
31
+ ### Note for Application Developers
32
+
33
+ When distributing Electrobun applications that use system tray:
34
+ - Document the system tray requirements for GNOME users
35
+ - Consider providing alternative UI access to tray functionality
36
+ - The tray implementation gracefully handles environments where system tray is unavailable
37
+
38
+
39
+ ### Application menus
40
+ The standard file, edit, etc. menus are super jank and would complicated the complex OOPIF compositing we do on gtk windows and x11 so on linux they're not wired up. You can get the same functionality by just using html in your webview to make a menu like interface and rpc to bun.
41
+
42
+ ### Context menus
43
+ Likewise the showContextMenu functionality that works on mac to show an arbitrary context menu wherever the mouse is (regardless of what it's over or what app is focused) is just not a ux linux supports well so that's also a noop on linux