electrobun 0.0.18 → 0.0.19-beta.6

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.
@@ -1,48 +0,0 @@
1
- import { zigRPC } from "../proc/zig";
2
-
3
- // TODO: move this to a more appropriate namespace
4
- export const moveToTrash = (path: string) => {
5
- return zigRPC.request.moveToTrash({ path });
6
- };
7
-
8
- export const showItemInFolder = (path: string) => {
9
- return zigRPC.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 zigRPC.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.openFileDialogResponse.split(",");
45
-
46
- // todo: it's nested like this due to zig union types. needs a zig refactor and revisit
47
- return filePaths;
48
- };
@@ -1,14 +0,0 @@
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
- };
@@ -1,29 +0,0 @@
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
- }
@@ -1,45 +0,0 @@
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;
@@ -1,9 +0,0 @@
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
- };
@@ -1,19 +0,0 @@
1
- import ElectrobunEvent from "./event";
2
-
3
- export default {
4
- willNavigate: (data) =>
5
- new ElectrobunEvent<{ url: string; windowId: number }, { allow: boolean }>(
6
- "will-navigate",
7
- data
8
- ),
9
- didNavigate: (data) =>
10
- new ElectrobunEvent<{ detail: string }, {}>("did-navigate", data),
11
- didNavigateInPage: (data) =>
12
- new ElectrobunEvent<{ detail: string }, {}>("did-navigate-in-page", data),
13
- didCommitNavigation: (data) =>
14
- new ElectrobunEvent<{ detail: string }, {}>("did-commit-navigation", data),
15
- domReady: (data) =>
16
- new ElectrobunEvent<{ detail: string }, {}>("dom-ready", data),
17
- newWindowOpen: (data) =>
18
- new ElectrobunEvent<{ detail: string }, {}>("new-window-open", data),
19
- };
@@ -1,12 +0,0 @@
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
- };
@@ -1,45 +0,0 @@
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
-
14
- // Named Exports
15
- export {
16
- type RPCSchema,
17
- type ElectrobunEvent,
18
- createRPC,
19
- BrowserWindow,
20
- BrowserView,
21
- Tray,
22
- Updater,
23
- Utils,
24
- ApplicationMenu,
25
- ContextMenu,
26
- PATHS,
27
- Socket,
28
- };
29
-
30
- // Default Export
31
- const Electrobun = {
32
- BrowserWindow,
33
- BrowserView,
34
- Tray,
35
- Updater,
36
- Utils,
37
- ApplicationMenu,
38
- ContextMenu,
39
- events: electobunEventEmmitter,
40
- PATHS,
41
- Socket,
42
- };
43
-
44
- // Electrobun
45
- export default Electrobun;