electrobun 0.0.2 → 0.0.3
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.
- package/.colab.json +1 -0
- package/README.md +14 -12
- package/bun.lockb +0 -0
- package/dist/bsdiff +0 -0
- package/dist/bspatch +0 -0
- package/dist/webview +0 -0
- package/docs-old/architecture.md +46 -0
- package/documentation/README.md +41 -0
- package/documentation/babel.config.js +3 -0
- package/documentation/blog/2024-08-20-electrobun.md +22 -0
- package/documentation/blog/authors.yml +8 -0
- package/documentation/blog/tags.yml +0 -0
- package/documentation/docs/apis/Application Icons.md +9 -0
- package/documentation/docs/apis/Bundled Assets.md +95 -0
- package/documentation/docs/apis/browser/DraggableRegions.md +36 -0
- package/documentation/docs/apis/browser/Electrobun Webview Tag.md +200 -0
- package/documentation/docs/apis/browser/Electroview Class.md +158 -0
- package/documentation/docs/apis/browser/GlobalProperties.md +11 -0
- package/documentation/docs/apis/browser/index.md +25 -0
- package/documentation/docs/apis/bun/ApplicationMenu.md +141 -0
- package/documentation/docs/apis/bun/BrowserView.md +513 -0
- package/documentation/docs/apis/bun/BrowserWindow.md +423 -0
- package/documentation/docs/apis/bun/ContextMenu.md +50 -0
- package/documentation/docs/apis/bun/Events.md +50 -0
- package/documentation/docs/apis/bun/PATHS.md +17 -0
- package/documentation/docs/apis/bun/Tray.md +115 -0
- package/documentation/docs/apis/bun/Updater.md +74 -0
- package/documentation/docs/apis/bun/Utils.md +51 -0
- package/documentation/docs/apis/bun/index.md +26 -0
- package/documentation/docs/apis/cli/Electrobun.config.md +97 -0
- package/documentation/docs/apis/cli/cli args.md +76 -0
- package/documentation/docs/guides/Architecture/Events.md +19 -0
- package/documentation/docs/guides/Architecture/IPC and Isolation.md +20 -0
- package/documentation/docs/guides/Architecture/Overview.md +140 -0
- package/documentation/docs/guides/Architecture/Updates.md +7 -0
- package/documentation/docs/guides/Architecture/Webview Tag.md +5 -0
- package/documentation/docs/guides/Compatability.md +8 -0
- package/documentation/docs/guides/Getting Started/Creating UI.md +147 -0
- package/documentation/docs/guides/Getting Started/Distributing.md +116 -0
- package/documentation/docs/guides/Getting Started/Getting Started.md +7 -0
- package/documentation/docs/guides/Getting Started/Hello World.md +93 -0
- package/documentation/docs/guides/Getting Started/What is Electrobun.md +39 -0
- package/documentation/docs/guides/Guides/Build UI with React +0 -0
- package/documentation/docs/guides/Guides/Build UI with Solidjs +0 -0
- package/documentation/docs/guides/Guides/Build a Web Browser +0 -0
- package/documentation/docs/guides/Guides/Bun <-> Browser RPC +0 -0
- package/documentation/docs/guides/Guides/Using Tailwind +0 -0
- package/documentation/docusaurus.config.ts +153 -0
- package/documentation/package-lock.json +14530 -0
- package/documentation/package.json +47 -0
- package/documentation/sidebars.ts +32 -0
- package/documentation/src/components/HomepageFeatures/index.tsx +70 -0
- package/documentation/src/components/HomepageFeatures/styles.module.css +11 -0
- package/documentation/src/css/custom.css +30 -0
- package/documentation/src/pages/index.module.css +23 -0
- package/documentation/src/pages/index.tsx +137 -0
- package/documentation/static/.nojekyll +0 -0
- package/documentation/static/img/electrobun-logo-256.png +0 -0
- package/documentation/static/img/electrobun-logo-32.png +0 -0
- package/documentation/tsconfig.json +7 -0
- package/package.json +11 -6
- package/src/browser/index.ts +2 -2
- package/src/bun/core/BrowserView.ts +14 -1
- package/src/cli/build/electrobun +0 -0
- package/src/cli/index.ts +3 -1
- package/docs/architecture.md +0 -84
- /package/{docs → docs-old}/api/bun-api.md +0 -0
- /package/{docs → docs-old}/api/view-api.md +0 -0
- /package/{docs → docs-old}/electrobun-config.md +0 -0
- /package/{docs → docs-old}/getting-started.md +0 -0
- /package/{docs → docs-old}/node_modules/.cache/webpack/client-development-en/0.pack +0 -0
- /package/{docs → docs-old}/node_modules/.cache/webpack/client-development-en/index.pack +0 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_position: 1
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
> Instantiate Electrobun apis in the browser.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import {Electroview} from "electrobun/view";
|
|
9
|
+
|
|
10
|
+
const electrobun = new Electroview({ ...options })
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Constructor Options
|
|
15
|
+
|
|
16
|
+
### rpc
|
|
17
|
+
|
|
18
|
+
This is the browser side of creating typed RPC between the main bun process and a given BrowserView's context.
|
|
19
|
+
|
|
20
|
+
```typescript title="src/shared/types.ts"
|
|
21
|
+
export type MyWebviewRPCType = {
|
|
22
|
+
// functions that execute in the main process
|
|
23
|
+
bun: RPCSchema<{
|
|
24
|
+
requests: {
|
|
25
|
+
someBunFunction: {
|
|
26
|
+
params: {
|
|
27
|
+
a: number;
|
|
28
|
+
b: number;
|
|
29
|
+
};
|
|
30
|
+
response: number;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
messages: {
|
|
34
|
+
logToBun: {
|
|
35
|
+
msg: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}>;
|
|
39
|
+
// functions that execute in the browser context
|
|
40
|
+
webview: RPCSchema<{
|
|
41
|
+
requests: {
|
|
42
|
+
someWebviewFunction: {
|
|
43
|
+
params: {
|
|
44
|
+
a: number;
|
|
45
|
+
b: number;
|
|
46
|
+
};
|
|
47
|
+
response: number;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
messages: {
|
|
51
|
+
logToWebview: {
|
|
52
|
+
msg: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
}>;
|
|
56
|
+
};
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```typescript title="/src/myview/index.ts"
|
|
60
|
+
import { Electroview } from "electrobun/view";
|
|
61
|
+
import { type MyWebviewRPCType } from "../shared/types";
|
|
62
|
+
|
|
63
|
+
const rpc = Electroview.defineRPC<MyWebviewRPC>({
|
|
64
|
+
handlers: {
|
|
65
|
+
requests: {
|
|
66
|
+
someWebviewFunction: ({ a, b }) => {
|
|
67
|
+
document.body.innerHTML += `bun asked me to do math with ${a} and ${b}\n`;
|
|
68
|
+
return a + b;
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
messages: {
|
|
72
|
+
logToWebview: ({ msg }) => {
|
|
73
|
+
// this will appear in the inspect element devtools console
|
|
74
|
+
console.log(`bun asked me to logToWebview: ${msg}`);
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
const electroview = new ElectrobunView.Electroview({ rpc });
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Assuming you've wired up rpc on the bun side when creating the [BrowserWindow](/docs/apis/bun/BrowserWindow) you'll be able to call those bun functions from the browser.
|
|
83
|
+
|
|
84
|
+
```typescript title="/src/myview/index.ts"
|
|
85
|
+
electroview.rpc.request.someBunFunction({ a: 9, b: 8 }).then((result) => {
|
|
86
|
+
console.log("result: ", result);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// or
|
|
90
|
+
electroview.rpc.send.logToBun({ msg: "hi from browser" });
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Static Methods
|
|
94
|
+
|
|
95
|
+
### defineRPC
|
|
96
|
+
|
|
97
|
+
Pass `Electroview.defineRPC` the shared rpc type to generate the typed rpc and message functions you can call from the browser and to set up types for the browser handlers for functions handled in the browser.
|
|
98
|
+
|
|
99
|
+
## Methods
|
|
100
|
+
|
|
101
|
+
### syncRPC
|
|
102
|
+
|
|
103
|
+
Regular Electrobun rpc between the bun and browser process is async and non-blocking. There may be times when you want the BrowserView process to halt while the bun process asynchronously responds as a way to simulate a synchronous api. This will also halt the zig and objc processes while waiting for a response.
|
|
104
|
+
|
|
105
|
+
Internally Electrobun uses this mechanism for things that require synchronous response like when waiting for the bun process to make a `will-navigate` decision for a BrowserView to allow or block the navigation.
|
|
106
|
+
|
|
107
|
+
You may want to use the synchronous api when migrating from Electron to Electrobun if you made heavy use of Electron's nodeIntegration as a way to break up the migration and simplify the steps to refactor to an asynchronous architecture.
|
|
108
|
+
|
|
109
|
+
:::warning
|
|
110
|
+
Since the syncRPC is blocking we currently don't provide automatic typing for functions and strongly discourage usage unless you really know what you're doing.
|
|
111
|
+
:::
|
|
112
|
+
|
|
113
|
+
Assuming you've defined syncRPC bun handlers
|
|
114
|
+
|
|
115
|
+
```typescript title="/src/bun/index.ts"
|
|
116
|
+
const win = new BrowserWindow({
|
|
117
|
+
title: "my url window",
|
|
118
|
+
url: "views://mainview/index.html",
|
|
119
|
+
frame: {
|
|
120
|
+
width: 1800,
|
|
121
|
+
height: 600,
|
|
122
|
+
x: 2000,
|
|
123
|
+
y: 2000,
|
|
124
|
+
},
|
|
125
|
+
rpc: myWebviewRPC,
|
|
126
|
+
// define syncRPC handlers
|
|
127
|
+
syncRpc: {
|
|
128
|
+
doSyncMathInBun: ({ a, b }) => {
|
|
129
|
+
console.log("doing sync math in bun", a, b);
|
|
130
|
+
return a + b;
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
:::note
|
|
137
|
+
You'll notice when using the syncRPC api you don't need to use async/await since the entire browser thread will freeze while waiting for bun to return the result.
|
|
138
|
+
:::
|
|
139
|
+
|
|
140
|
+
```typescript title="/src/mainview/index.ts"
|
|
141
|
+
const electrobun = new Electroview();
|
|
142
|
+
|
|
143
|
+
// The entire thread will halt while waiting for bun to respond
|
|
144
|
+
const syncMathResult = electrobun.syncRpc({
|
|
145
|
+
// These method signatures are not currently typed to discourage usage
|
|
146
|
+
// of the syncRPC api
|
|
147
|
+
method: "doSyncMath",
|
|
148
|
+
params: { a: 5, b: 9 },
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
document.body.innerHTML += `<br> \nsync result: ${syncMathResult}\n`;
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Browser to Browser RPC
|
|
155
|
+
|
|
156
|
+
Electrobun doesn't provide browser to browser RPC out of the box as we favour isolation between browser contexts for greater security.
|
|
157
|
+
|
|
158
|
+
There's nothing stopping you from creating bun to browser rpc for two different BrowserViews and passing messages between them via bun. You can also establish any number of other web-based mechanisms to communicated between browser contexts from localstorage to webRTC or via a server.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
## Global Properties
|
|
2
|
+
|
|
3
|
+
These global properties are injected into the browser context regardless of whether you've instantiated the `Electroview`.
|
|
4
|
+
|
|
5
|
+
### window.\_\_electrobunWebviewId
|
|
6
|
+
|
|
7
|
+
The id of the webview
|
|
8
|
+
|
|
9
|
+
### window.\_\_electrobunWindowId
|
|
10
|
+
|
|
11
|
+
The id of the window
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_position: 2
|
|
3
|
+
title: "Browser API"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
These are apis you can use in the BrowserView browser context. If you're just starting to look around take a look at the [Getting Started Guide](/docs/guides/Getting%20Started/) first to learn how to set up your first project.
|
|
7
|
+
|
|
8
|
+
The Electrobun Browser api is not injected into browser contexts automatically. Instead you'll configure your `electrobun.config` file to use bun to build browser typescript code where you can write typescript. The cli will bundle the transpiled code with your app, and then you can use the `views://` scheme to load html and that bundled javascript or load it as `preload` script in a BrowserView.
|
|
9
|
+
|
|
10
|
+
While there's no need to use the Browser API at all in your BrowserViews if you want to establish rpc between browserview and bun or use other Electrobun apis in the browser you'll need to use it.
|
|
11
|
+
|
|
12
|
+
You should explicitly import the `electrobun/view` api in browser processes:
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import Electrobun from "electrobun/view";
|
|
16
|
+
|
|
17
|
+
// or
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
Electroview,
|
|
21
|
+
// other specified imports
|
|
22
|
+
} from "electrobun/view";
|
|
23
|
+
|
|
24
|
+
const electrobun = new Electroview(/*...*/);
|
|
25
|
+
```
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
> Create and control an application menu. In MacOS this is the menu in the top-left with File, Edit, and so on.
|
|
2
|
+
|
|
3
|
+
```
|
|
4
|
+
import {ApplicationMenu} from "electrobun/bun";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
ApplicationMenu.setApplicationMenu([
|
|
8
|
+
{
|
|
9
|
+
submenu: [{ label: "Quit", role: "quit" }],
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
label: "Edit",
|
|
13
|
+
submenu: [
|
|
14
|
+
{ role: "undo" },
|
|
15
|
+
{ role: "redo" },
|
|
16
|
+
{ type: "separator" },
|
|
17
|
+
{
|
|
18
|
+
label: "Custom Menu Item 🚀",
|
|
19
|
+
action: "custom-action-1",
|
|
20
|
+
tooltip: "I'm a tooltip",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
label: "Custom menu disabled",
|
|
24
|
+
enabled: false,
|
|
25
|
+
action: "custom-action-2",
|
|
26
|
+
},
|
|
27
|
+
{ type: "separator" },
|
|
28
|
+
{ role: "cut" },
|
|
29
|
+
{ role: "copy" },
|
|
30
|
+
{ role: "paste" },
|
|
31
|
+
{ role: "pasteAndMatchStyle" },
|
|
32
|
+
{ role: "delete" },
|
|
33
|
+
{ role: "selectAll" },
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
Electrobun.events.on("application-menu-clicked", (e) => {
|
|
39
|
+
console.log("application menu clicked", e.data.action); // custom-actino
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### setApplicationMenu
|
|
45
|
+
|
|
46
|
+
This function takes an array of menu items. Here are some example menu items:
|
|
47
|
+
|
|
48
|
+
### Menu dividers
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
// menu dividers
|
|
52
|
+
{type: "divider"}
|
|
53
|
+
// or
|
|
54
|
+
{type: "separator"}
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Default Roles
|
|
59
|
+
|
|
60
|
+
Menu items can specify a role instead of an action. Use menu item roles to access built-in OS functionality and enable their corresponding keyboard shortcuts.
|
|
61
|
+
|
|
62
|
+
If you want to enable keyboard shortcuts like `cmd+q` to quit your application, `cmd+c` and `cmd+v` for copy and paste then you need to specify menu items with the corresponding roles.
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
// example Edit menu
|
|
66
|
+
{
|
|
67
|
+
label: "Edit",
|
|
68
|
+
submenu: [
|
|
69
|
+
// Corresponding keyboard shotcuts will automatically
|
|
70
|
+
// be bound when a valid role is set.
|
|
71
|
+
{ role: "undo" },
|
|
72
|
+
{ role: "redo" },
|
|
73
|
+
{ type: "separator" },
|
|
74
|
+
{ role: "cut" },
|
|
75
|
+
{ role: "copy" },
|
|
76
|
+
{ role: "paste" },
|
|
77
|
+
{ role: "pasteAndMatchStyle" },
|
|
78
|
+
{ role: "delete" },
|
|
79
|
+
{ role: "selectAll" },
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
List of supported roles
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
quit: "Quit",
|
|
88
|
+
hide: "Hide",
|
|
89
|
+
hideOthers: "Hide Others",
|
|
90
|
+
showAll: "Show All",
|
|
91
|
+
undo: "Undo",
|
|
92
|
+
redo: "Redo",
|
|
93
|
+
cut: "Cut",
|
|
94
|
+
copy: "Copy",
|
|
95
|
+
paste: "Paste",
|
|
96
|
+
pasteAndMatchStyle: "Paste And Match Style",
|
|
97
|
+
delete: "Delete",
|
|
98
|
+
selectAll: "Select All",
|
|
99
|
+
startSpeaking: "Start Speaking",
|
|
100
|
+
stopSpeaking: "Stop Speaking",
|
|
101
|
+
enterFullScreen: "Enter FullScreen",
|
|
102
|
+
exitFullScreen: "Exit FullScreen",
|
|
103
|
+
toggleFullScreen: "Toggle Full Screen",
|
|
104
|
+
minimize: "Minimize",
|
|
105
|
+
zoom: "Zoom",
|
|
106
|
+
bringAllToFront: "Bring All To Front",
|
|
107
|
+
close: "Close",
|
|
108
|
+
cycleThroughWindows: "Cycle Through Windows",
|
|
109
|
+
showHelp: "Show Help",
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Custom Menu Items
|
|
113
|
+
|
|
114
|
+
Instead of a role you can specify and action, you can then listen for that action in the 'application-menu-clicked' event.
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
// basic menu item
|
|
118
|
+
{label: "I am a menu item", action: 'some-action'}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Optionaly properties
|
|
122
|
+
|
|
123
|
+
### enabled
|
|
124
|
+
|
|
125
|
+
Set to false to show the menu item as disabled
|
|
126
|
+
|
|
127
|
+
### checked
|
|
128
|
+
|
|
129
|
+
Set to true to show a checkbox next to the menu item.
|
|
130
|
+
|
|
131
|
+
### hidden
|
|
132
|
+
|
|
133
|
+
Set to true to hide
|
|
134
|
+
|
|
135
|
+
### tooltip
|
|
136
|
+
|
|
137
|
+
Will show this tooltip when hovering over the menu item
|
|
138
|
+
|
|
139
|
+
### submenu
|
|
140
|
+
|
|
141
|
+
The top-level menu corresponds to the menu items you see when the app is focused, eg: File, Edit, View, etc. You can add actions to those if you want and treat them like buttons, but you can also add nested submenus.
|