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.
Files changed (72) hide show
  1. package/.colab.json +1 -0
  2. package/README.md +14 -12
  3. package/bun.lockb +0 -0
  4. package/dist/bsdiff +0 -0
  5. package/dist/bspatch +0 -0
  6. package/dist/webview +0 -0
  7. package/docs-old/architecture.md +46 -0
  8. package/documentation/README.md +41 -0
  9. package/documentation/babel.config.js +3 -0
  10. package/documentation/blog/2024-08-20-electrobun.md +22 -0
  11. package/documentation/blog/authors.yml +8 -0
  12. package/documentation/blog/tags.yml +0 -0
  13. package/documentation/docs/apis/Application Icons.md +9 -0
  14. package/documentation/docs/apis/Bundled Assets.md +95 -0
  15. package/documentation/docs/apis/browser/DraggableRegions.md +36 -0
  16. package/documentation/docs/apis/browser/Electrobun Webview Tag.md +200 -0
  17. package/documentation/docs/apis/browser/Electroview Class.md +158 -0
  18. package/documentation/docs/apis/browser/GlobalProperties.md +11 -0
  19. package/documentation/docs/apis/browser/index.md +25 -0
  20. package/documentation/docs/apis/bun/ApplicationMenu.md +141 -0
  21. package/documentation/docs/apis/bun/BrowserView.md +513 -0
  22. package/documentation/docs/apis/bun/BrowserWindow.md +423 -0
  23. package/documentation/docs/apis/bun/ContextMenu.md +50 -0
  24. package/documentation/docs/apis/bun/Events.md +50 -0
  25. package/documentation/docs/apis/bun/PATHS.md +17 -0
  26. package/documentation/docs/apis/bun/Tray.md +115 -0
  27. package/documentation/docs/apis/bun/Updater.md +74 -0
  28. package/documentation/docs/apis/bun/Utils.md +51 -0
  29. package/documentation/docs/apis/bun/index.md +26 -0
  30. package/documentation/docs/apis/cli/Electrobun.config.md +97 -0
  31. package/documentation/docs/apis/cli/cli args.md +76 -0
  32. package/documentation/docs/guides/Architecture/Events.md +19 -0
  33. package/documentation/docs/guides/Architecture/IPC and Isolation.md +20 -0
  34. package/documentation/docs/guides/Architecture/Overview.md +140 -0
  35. package/documentation/docs/guides/Architecture/Updates.md +7 -0
  36. package/documentation/docs/guides/Architecture/Webview Tag.md +5 -0
  37. package/documentation/docs/guides/Compatability.md +8 -0
  38. package/documentation/docs/guides/Getting Started/Creating UI.md +147 -0
  39. package/documentation/docs/guides/Getting Started/Distributing.md +116 -0
  40. package/documentation/docs/guides/Getting Started/Getting Started.md +7 -0
  41. package/documentation/docs/guides/Getting Started/Hello World.md +93 -0
  42. package/documentation/docs/guides/Getting Started/What is Electrobun.md +39 -0
  43. package/documentation/docs/guides/Guides/Build UI with React +0 -0
  44. package/documentation/docs/guides/Guides/Build UI with Solidjs +0 -0
  45. package/documentation/docs/guides/Guides/Build a Web Browser +0 -0
  46. package/documentation/docs/guides/Guides/Bun <-> Browser RPC +0 -0
  47. package/documentation/docs/guides/Guides/Using Tailwind +0 -0
  48. package/documentation/docusaurus.config.ts +153 -0
  49. package/documentation/package-lock.json +14530 -0
  50. package/documentation/package.json +47 -0
  51. package/documentation/sidebars.ts +32 -0
  52. package/documentation/src/components/HomepageFeatures/index.tsx +70 -0
  53. package/documentation/src/components/HomepageFeatures/styles.module.css +11 -0
  54. package/documentation/src/css/custom.css +30 -0
  55. package/documentation/src/pages/index.module.css +23 -0
  56. package/documentation/src/pages/index.tsx +137 -0
  57. package/documentation/static/.nojekyll +0 -0
  58. package/documentation/static/img/electrobun-logo-256.png +0 -0
  59. package/documentation/static/img/electrobun-logo-32.png +0 -0
  60. package/documentation/tsconfig.json +7 -0
  61. package/package.json +11 -6
  62. package/src/browser/index.ts +2 -2
  63. package/src/bun/core/BrowserView.ts +14 -1
  64. package/src/cli/build/electrobun +0 -0
  65. package/src/cli/index.ts +3 -1
  66. package/docs/architecture.md +0 -84
  67. /package/{docs → docs-old}/api/bun-api.md +0 -0
  68. /package/{docs → docs-old}/api/view-api.md +0 -0
  69. /package/{docs → docs-old}/electrobun-config.md +0 -0
  70. /package/{docs → docs-old}/getting-started.md +0 -0
  71. /package/{docs → docs-old}/node_modules/.cache/webpack/client-development-en/0.pack +0 -0
  72. /package/{docs → docs-old}/node_modules/.cache/webpack/client-development-en/index.pack +0 -0
@@ -0,0 +1,147 @@
1
+ ---
2
+ sidebar_position: 3
3
+ title: Creating UI
4
+ sidebar_label: 3. Creating UI
5
+ ---
6
+
7
+ :::info
8
+ Continuing on from the [Hello World](/docs/guides/Getting%20Started/Hello%20World) Guide we're going to add some UI.
9
+ :::
10
+
11
+ Currently our app is opening a browser window and just loading a url. Let's make a simple web browser.
12
+
13
+ Let's create a new folder `src/main-ui/` and add an index file. This is where our browser code will go. The Electrobun cli will automatically transpile this into javascript and make it available at the url `views://main-ui/index.js`
14
+
15
+ ```typescript title="src/main-ui/index.ts
16
+ import { Electroview } from "electrobun/view";
17
+
18
+ // Instantiate the electrobun browser api
19
+ const electrobun = new Electroview({ rpc: null });
20
+
21
+ window.loadPage = () => {
22
+ const newUrl = document.querySelector("#urlInput").value;
23
+ const webview = document.querySelector(".webview");
24
+
25
+ webview.src = newUrl;
26
+ };
27
+
28
+ window.goBack = () => {
29
+ const webview = document.querySelector(".webview");
30
+ webview.goBack();
31
+ };
32
+
33
+ window.goForward = () => {
34
+ const webview = document.querySelector(".webview");
35
+ webview.goForward();
36
+ };
37
+ ```
38
+
39
+ Let's create an html file to load into the BrowserView that will load the transpiled javascript above:
40
+
41
+ ```html title="src/main-ui/index.html
42
+ <!DOCTYPE html>
43
+ <html lang="en">
44
+ <head>
45
+ <meta charset="UTF-8">
46
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
47
+ <title>My Web Browser</title>
48
+ <script src="views://main-ui/index.js"></script>
49
+ </head>
50
+ <body>
51
+ <h1>My Web Browser</h1>
52
+ <input type="text" id="urlInput" placeholder="Enter URL">
53
+ <button onclick="loadPage()">Go</button>
54
+ <button onclick="goBack()">Back</button>
55
+ <button onclick="goForward()">Forward</button>
56
+
57
+ <electrobun-webview class="webview" width="100%" height="100%" src="https://electrobun.dev">
58
+
59
+ </body>
60
+ </html>
61
+ ```
62
+
63
+ Now let's update our `electrobun.config` file so that it knows to transpile the new typescript and html files for our main-ui:
64
+
65
+ ```javascript title="electrobun.config"
66
+ {
67
+ "app": {
68
+ "name": "My App",
69
+ "identifier": "dev.my.app",
70
+ "version": "0.0.1"
71
+ },
72
+ "build": {
73
+ "bun": {
74
+ "entrypoint": "src/bun/index.ts"
75
+ },
76
+ "views": {
77
+ "main-ui": {
78
+ "entrypoint": "src/main-ui/index.ts"
79
+ }
80
+ },
81
+ "copy": {
82
+ "src/main-ui/index.html": "views/main-ui/index.html"
83
+ }
84
+ }
85
+ }
86
+ ```
87
+
88
+ And finally let's update our bun process code to load the new html file:
89
+
90
+ ```typescript title="src/bun/index.ts"
91
+ import { BrowserWindow } from "electrobun/bun";
92
+
93
+ const win = new BrowserWindow({
94
+ title: "Hello Electrobun",
95
+ url: "views://main-ui/index.html",
96
+ });
97
+ ```
98
+
99
+ Now back in terminal `ctrl+c` if it was running and then `bun start` to rebuild and launch. You should now see a window with an input, type in `https://google.com` and hit go, then try the back and forward buttons.
100
+
101
+ You'll notice that while you can right click on the text input and choose copy and paste from the default context menu. `cmd+c` and `cmd+v` as well as `cmd+a` to select all don't work. Let's update our main bun file to set up an Application Edit menu to enable those keyboard shortcuts.
102
+
103
+ ```typescript title="src/bun/index.ts"
104
+ import { BrowserWindow, ApplicationMenu } from "electrobun/bun";
105
+
106
+ ApplicationMenu.setApplicationMenu([
107
+ {
108
+ submenu: [{ label: "Quit", role: "quit" }],
109
+ },
110
+ {
111
+ label: "Edit",
112
+ submenu: [
113
+ { role: "undo" },
114
+ { role: "redo" },
115
+ { type: "separator" },
116
+ {
117
+ label: "Custom Menu Item 🚀",
118
+ action: "custom-action-1",
119
+ tooltip: "I'm a tooltip",
120
+ },
121
+ {
122
+ label: "Custom menu disabled",
123
+ enabled: false,
124
+ action: "custom-action-2",
125
+ },
126
+ { type: "separator" },
127
+ { role: "cut" },
128
+ { role: "copy" },
129
+ { role: "paste" },
130
+ { role: "pasteAndMatchStyle" },
131
+ { role: "delete" },
132
+ { role: "selectAll" },
133
+ ],
134
+ },
135
+ ]);
136
+
137
+ const win = new BrowserWindow({
138
+ title: "Hello Electrobun",
139
+ url: "views://main-ui/index.html",
140
+ });
141
+ ```
142
+
143
+ You'll notice now that when the app is focused your app now has an Edit menu, and because we used `role:` for the `cut`, `copy`, `paste`, and `selectAll` menu items those global keyboard shortcuts will now work in your app's url input.
144
+
145
+ :::info Congratulations
146
+ You just built a simple web browser in Electrobun!
147
+ :::
@@ -0,0 +1,116 @@
1
+ ---
2
+ sidebar_position: 4
3
+ title: Distributing
4
+ sidebar_label: 4. Distributing
5
+ ---
6
+
7
+ :::info
8
+ Continuing on from the [Creating UI](/docs/guides/Getting%20Started/Creating%20UI) Guide.
9
+ :::
10
+
11
+ Let's add two more scripts to our `package.json` file to get our app ready for distribution. `build:canary` and `build:stable`:
12
+
13
+ ```json title="package.json
14
+ {
15
+ "name": "my-app",
16
+ "devDependencies": {
17
+ "@types/bun": "latest"
18
+ },
19
+ "peerDependencies": {
20
+ "typescript": "^5.0.0"
21
+ },
22
+ "dependencies": {
23
+ "electrobun": "^0.0.1"
24
+ },
25
+ "scripts": {
26
+ "start": "bun run build:dev && electrobun dev",
27
+ "build:dev": "bun install && electrobun build",
28
+ "build:canary": "electrobun build env=canary",
29
+ "build:stable": "electrobun build env=stable"
30
+ }
31
+ }
32
+ ```
33
+
34
+ In your terminal you can now run
35
+
36
+ ```
37
+ bun run build:canary
38
+
39
+ // or
40
+
41
+ bun run build:stable
42
+ ```
43
+
44
+ Both of these non-dev builds will:
45
+
46
+ - build an optimized MacOS app bundle
47
+ - tar and compress it using state of the art compression
48
+ - generate another self-extracting app bundle
49
+ - create an `artifacts` folder for distribution
50
+
51
+ :::info
52
+ All you need to distribute your app is a static file host like S3 or Google Cloud Storage. There's no need to run a server beyond that.
53
+ :::
54
+
55
+ Let's assume you've set up a Google Cloud Storage bucket with a subfolder for this application and add it to `electrobun.config`:
56
+
57
+ ```json title="electrobun.config"
58
+ {
59
+ "app": {
60
+ "name": "My App",
61
+ "identifier": "dev.my.app",
62
+ "version": "0.0.1"
63
+ },
64
+ "build": {
65
+ "bun": {
66
+ "entrypoint": "src/bun/index.ts"
67
+ },
68
+ "views": {
69
+ "main-ui": {
70
+ "entrypoint": "src/main-ui/index.ts"
71
+ }
72
+ },
73
+ "copy": {
74
+ "src/main-ui/index.html": "views/main-ui/index.html"
75
+ }
76
+ },
77
+ "release": {
78
+ "bucketUrl": "https://storage.googleapis.com/mybucketname/myapp/"
79
+ }
80
+ }
81
+ ```
82
+
83
+ You can make your app available by simply uploading the contents of the `artifacts` folder into the `myapp` folder of your bucket. The artifacts folder will have two subfolders, one for `canary` and one for `stable`.
84
+
85
+ Once you've uploaded the artifacts to your bucket when your run a non-dev build command again like `bun run build:canary` the Electrobun cli will automatically download the current version of your app, use our custom optimize BSDIFF implementation to generate a patch file and add the patch file to your artifacts folder.
86
+
87
+ Visit the [Updater API docs](/docs/apis/bun/Updater) to learn how to make your app check for and install updates.
88
+
89
+ ### What are all the files in the artifacts folder
90
+
91
+ ```
92
+ // Assuming your app's name is MyApp and you did a canary build you'll have the following files:
93
+
94
+ // This file contains metadata for the version of your app you just built
95
+ /artifacts/canary/update.json
96
+
97
+ // This is the file you would link to on your marketing site for users to download
98
+ // when first installing your app. It's a dmg that contains your app in its
99
+ // self-extracting form
100
+ /artifacts/canary/MyApp-canary.dmg
101
+
102
+ // This is a copy of the compressed tar file of your app bundle. There's a copy
103
+ // of this inside the self-extracting bundle. When your app updates itself if there
104
+ // are no patch files available it will download this to update your app.
105
+ /artifacts/canary/MyApp-canary.app.tar.zst
106
+
107
+ // These files are named <hash>.patch. The Electrobun cli generates patch files
108
+ // from the current version on your static cloud hosting to the version your just
109
+ // built.
110
+
111
+ // When replacing the contents of your static file host you can keep as many old
112
+ // patch files as you like. Users with older versions of your app will keep downloading
113
+ // the next patch automatically when updating.
114
+ /artifacts/canary/jsf87yasf.patch
115
+
116
+ ```
@@ -0,0 +1,7 @@
1
+ ---
2
+ sidebar_position: 1
3
+ ---
4
+
5
+ This Getting Started guide will give you an overview of Electrobun.
6
+
7
+ It'll guide you through creating a simple hello world app all the way from setting up your project to distributing it.
@@ -0,0 +1,93 @@
1
+ ---
2
+ sidebar_position: 2
3
+ title: Hello World
4
+ sidebar_label: 2. Hello World
5
+ ---
6
+
7
+ :::info
8
+ Electrobun will install a specific version of bun as a dependency in `node_modules`.
9
+ :::
10
+
11
+ :::info
12
+ This guide assumes you have bun installed globally, if you're using node.js or another package manager then you may need to adjust the terminal commands and package.json scripts accordingly.
13
+ :::
14
+
15
+ ## Step 1: Initialize your project folder
16
+
17
+ Create a new folder for your project. Let's call it `/electrobun-test`.
18
+
19
+ In your `electrobun-test` folder run `bun init .` You'll be prompted to enter a package name, let's use `my-app` and an entrypoint which we don't need so just hit enter.
20
+
21
+ ## Step 2: Install Electrobun as a dependency
22
+
23
+ Let's install electrobun. Just run: `bun install electrobun` to add it as a dependency.
24
+
25
+ ## Step 3: Add package.json scripts to build and run your app
26
+
27
+ Open your `package.json` in a code editor and add a build:dev script and a start script so that your `package.json` looks like this:
28
+
29
+ ```json title="package.json"
30
+ {
31
+ "name": "my-app",
32
+ "devDependencies": {
33
+ "@types/bun": "latest"
34
+ },
35
+ "peerDependencies": {
36
+ "typescript": "^5.0.0"
37
+ },
38
+ "dependencies": {
39
+ "electrobun": "^0.0.1"
40
+ },
41
+ "scripts": {
42
+ "start": "bun run build:dev && electrobun dev",
43
+ "build:dev": "bun install && electrobun build"
44
+ }
45
+ }
46
+ ```
47
+
48
+ :::note
49
+ That we've modified the default package.json that bun creates
50
+
51
+ - Removed the "type": "module" and "module": "index.ts" properties since we don't need them.
52
+ - Added two npm scripts that will use the electrobun cli that should now be in your node_modules/.bin folder.
53
+ :::
54
+
55
+ ## Step 4: Hello World
56
+
57
+ We now have electrobun installed and a way to build and run our hello world app, let's add some code.
58
+
59
+ Create a file in `src/bun/index.ts` with the following contents:
60
+
61
+ ```typescript title="src/bun/index.ts"
62
+ import { BrowserWindow } from "electrobun/bun";
63
+
64
+ const win = new BrowserWindow({
65
+ title: "Hello Electrobun",
66
+ url: "https://electrobun.dev",
67
+ });
68
+ ```
69
+
70
+ ## Step 5: Configure Electrobun
71
+
72
+ One last thing, we need to a way to let the Electrobun cli know where our bun entrypoint file is and how to build it. We do that by creating an electrobun.config file in the root of the project.
73
+
74
+ ```json title="electrobun.config"
75
+ {
76
+ "app": {
77
+ "name": "My App",
78
+ "identifier": "dev.my.app",
79
+ "version": "0.0.1"
80
+ },
81
+ "build": {
82
+ "bun": {
83
+ "entrypoint": "src/bun/index.ts"
84
+ }
85
+ }
86
+ }
87
+ ```
88
+
89
+ ## Step 6: Run your app
90
+
91
+ With this we can now go back to our terminal and run `bun start` and you should see a window pop up and load the site.
92
+
93
+ To stop running the app just hit `cmd+c`
@@ -0,0 +1,39 @@
1
+ ---
2
+ sidebar_position: 1
3
+ title: What is Electrobun
4
+ sidebar_label: 1. What is Electrobun
5
+ ---
6
+
7
+ Electrobun aims to be a batteries included framework for building desktop apps with Typescript.
8
+
9
+ ## Priorities
10
+
11
+ What makes electrobun different, aside from our approach to achitecture are our project goals:
12
+
13
+ ### Batteries included
14
+
15
+ - Write typescript without waisting time on devops
16
+ - Everything needed to build, test, codesign, update
17
+
18
+ ### Iteration speed
19
+
20
+ - Building your app as fast as possible so you can iterate on features and fixes as fast as possible
21
+ - Enabling you to ship small, cost effective updates (as small as 14KB) so you can ship new features and fixes to your end users and get feedback as fast and often as possible
22
+
23
+ ### Affordable to maintain
24
+
25
+ - MIT open source
26
+ - Ship updates to your users that are tiny
27
+ - All you need is a file server (eg: S3) to distribute your app
28
+
29
+ ### Flexible
30
+
31
+ - Use any modern framework for UI (from plain HTML, to Preact, SolidJS, and more)
32
+ - Use the built-in system Webview (or bundle a 3rd party webview like Chromium: _coming soon..._)
33
+
34
+ ### Security and Performance
35
+
36
+ - Bun and Zig under the hood
37
+ - The main process and browser processes are isolated from each other
38
+ - Opt-in to enable fast, typed, and easy to extend RPC between main and browser processes
39
+ - A custom webview tag implementation for OOPIFs so you can build a web browser
@@ -0,0 +1,153 @@
1
+ import { themes as prismThemes } from "prism-react-renderer";
2
+ import type { Config } from "@docusaurus/types";
3
+ import type * as Preset from "@docusaurus/preset-classic";
4
+
5
+ const config: Config = {
6
+ title: "Electrobun",
7
+ tagline:
8
+ "Build ultra fast, tiny, and cross-platform desktop apps with Typescript",
9
+ favicon: "img/electrobun-logo-32.png",
10
+
11
+ // Set the production url of your site here
12
+ url: "https://electrobun.dev",
13
+ // Set the /<baseUrl>/ pathname under which your site is served
14
+ // For GitHub pages deployment, it is often '/<projectName>/'
15
+ baseUrl: "/",
16
+
17
+ onBrokenLinks: "throw",
18
+ onBrokenMarkdownLinks: "warn",
19
+
20
+ // Even if you don't use internationalization, you can use this field to set
21
+ // useful metadata like html lang. For example, if your site is Chinese, you
22
+ // may want to replace "en" with "zh-Hans".
23
+ i18n: {
24
+ defaultLocale: "en",
25
+ locales: ["en"],
26
+ },
27
+
28
+ presets: [
29
+ [
30
+ "classic",
31
+ {
32
+ docs: {
33
+ sidebarPath: "./sidebars.ts",
34
+ },
35
+ blog: {
36
+ showReadingTime: true,
37
+ feedOptions: {
38
+ type: ["rss", "atom"],
39
+ xslt: true,
40
+ },
41
+ },
42
+ theme: {
43
+ customCss: "./src/css/custom.css",
44
+ },
45
+ } satisfies Preset.Options,
46
+ ],
47
+ ],
48
+
49
+ themeConfig: {
50
+ colorMode: {
51
+ defaultMode: "dark",
52
+ disableSwitch: false,
53
+ respectPrefersColorScheme: true,
54
+ },
55
+ announcementBar: {
56
+ id: "alpha",
57
+ content:
58
+ "Electrobun is just getting started. The API is likely to change as we build toward a stable v1",
59
+ backgroundColor: "#1160af",
60
+ textColor: "#efefef",
61
+ isCloseable: true,
62
+ },
63
+ // Replace with your project's social card
64
+ // image: "img/social-card.jpg",
65
+ navbar: {
66
+ title: "Electrobun",
67
+ logo: {
68
+ alt: "Electrobun Logo",
69
+ src: "img/electrobun-logo-256.png",
70
+ },
71
+ items: [
72
+ {
73
+ type: "docSidebar",
74
+ sidebarId: "guidesSidebar",
75
+ position: "left",
76
+ label: "Docs",
77
+ },
78
+ {
79
+ type: "docSidebar",
80
+ sidebarId: "apiSidebar",
81
+ position: "left",
82
+ label: "API Reference",
83
+ },
84
+ { to: "/blog", label: "Updates", position: "left" },
85
+ {
86
+ href: "https://github.com/blackboardsh/electrobun",
87
+ label: "GitHub",
88
+ position: "right",
89
+ },
90
+ ],
91
+ },
92
+ footer: {
93
+ style: "dark",
94
+ links: [
95
+ {
96
+ title: "Docs",
97
+ items: [
98
+ {
99
+ label: "Getting Started",
100
+ to: "/docs/guides/Getting%20Started/",
101
+ },
102
+ {
103
+ label: "What is Electrobun?",
104
+ to: "/docs/guides/Getting%20Started/What%20is%20Electrobun",
105
+ },
106
+ {
107
+ label: "Hello World",
108
+ to: "/docs/guides/Getting%20Started/Hello%20World",
109
+ },
110
+ ],
111
+ },
112
+ {
113
+ title: "Community",
114
+ items: [
115
+ {
116
+ label: "GitHub",
117
+ href: "https://github.com/blackboardsh/electrobun/issues",
118
+ },
119
+ {
120
+ label: "Discord",
121
+ href: "https://www.electrobun.dev/#",
122
+ },
123
+ {
124
+ label: "Twitter",
125
+ href: "https://x.com/BlackboardTech",
126
+ },
127
+ {
128
+ label: "Blog",
129
+ to: "/blog",
130
+ },
131
+ ],
132
+ },
133
+ {
134
+ title: "Sponsors",
135
+ items: [
136
+ {
137
+ label: "Blackboard Technologies Inc.",
138
+ href: "https://blackboard.sh",
139
+ },
140
+ ],
141
+ },
142
+ ],
143
+ },
144
+ prism: {
145
+ theme: prismThemes.github,
146
+ darkTheme: prismThemes.dracula,
147
+ additionalLanguages: ["json", "typescript"],
148
+ defaultLanguage: "typescript",
149
+ },
150
+ } satisfies Preset.ThemeConfig,
151
+ };
152
+
153
+ export default config;