@forgedesk/api 2.0.0
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/README.md +28 -0
- package/index.d.ts +100 -0
- package/index.js +47 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @forgedesk/api
|
|
2
|
+
|
|
3
|
+
Typed JavaScript bindings for the Forge runtime.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Forge runtime embedded in a Python 3.14+ free-threaded app
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @forgedesk/api
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import forge, { invoke, isForgeAvailable } from "@forgedesk/api";
|
|
19
|
+
|
|
20
|
+
if (isForgeAvailable()) {
|
|
21
|
+
const version = await forge.app.version();
|
|
22
|
+
const state = await forge.window.state();
|
|
23
|
+
const result = await invoke("greet", { name: "Forge" });
|
|
24
|
+
console.log(version, state, result);
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
This package expects the Forge runtime to inject `window.__forge__`.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forge Automatically Generated TypeScript API
|
|
3
|
+
* Do not edit this file manually.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface InvokeDetailedOptions {
|
|
7
|
+
detailed?: boolean;
|
|
8
|
+
trace?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ForgeClipboardApi {
|
|
12
|
+
clear(): Promise<Record<string, unknown>>;
|
|
13
|
+
read(): Promise<Record<string, unknown>>;
|
|
14
|
+
write(text: string): Promise<Record<string, unknown>>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ForgeMenuApi {
|
|
18
|
+
check(item_id: string, checked?: boolean): Promise<Record<string, unknown>>;
|
|
19
|
+
clear(): Promise<boolean>;
|
|
20
|
+
disable(item_id: string): Promise<Record<string, unknown>>;
|
|
21
|
+
enable(item_id: string): Promise<Record<string, unknown>>;
|
|
22
|
+
get(): Promise<any[]>;
|
|
23
|
+
set(items: any[]): Promise<any[]>;
|
|
24
|
+
trigger(item_id: string, payload?: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
25
|
+
uncheck(item_id: string): Promise<Record<string, unknown>>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ForgeApi {
|
|
29
|
+
invoke(command: string, args?: Record<string, unknown>): Promise<unknown>;
|
|
30
|
+
invokeDetailed(command: string, args?: Record<string, unknown>, options?: InvokeDetailedOptions): Promise<unknown>;
|
|
31
|
+
on(eventName: string, handler: (payload: unknown) => void): unknown;
|
|
32
|
+
once(eventName: string, handler: (payload: unknown) => void): unknown;
|
|
33
|
+
off(eventName: string, handler: (payload: unknown) => void): unknown;
|
|
34
|
+
clipboard: ForgeClipboardApi;
|
|
35
|
+
menu: ForgeMenuApi;
|
|
36
|
+
apply_native_selection(item_id: string, checked?: boolean): Promise<Record<string, unknown>>;
|
|
37
|
+
clear_user_attention(): Promise<void>;
|
|
38
|
+
confirm(title: string, message: string, level?: string): Promise<Record<string, unknown>>;
|
|
39
|
+
deep_link_open(url: string): Promise<Record<string, unknown>>;
|
|
40
|
+
deep_link_protocols(): Promise<Record<string, unknown>>;
|
|
41
|
+
deep_link_state(): Promise<Record<string, unknown>>;
|
|
42
|
+
delete(path: string, recursive?: boolean): Promise<void>;
|
|
43
|
+
disable(): Promise<boolean>;
|
|
44
|
+
enable(): Promise<boolean>;
|
|
45
|
+
exists(path: string): Promise<boolean>;
|
|
46
|
+
exit(): Promise<void>;
|
|
47
|
+
exit_app(): Promise<void>;
|
|
48
|
+
get_base_path(): Promise<unknown>;
|
|
49
|
+
get_battery_info(): Promise<Record<string, unknown>>;
|
|
50
|
+
get_cursor_screen_point(): Promise<Record<string, unknown>>;
|
|
51
|
+
get_cwd(): Promise<string>;
|
|
52
|
+
get_env(key: string, default?: string): Promise<string>;
|
|
53
|
+
get_info(): Promise<Record<string, unknown>>;
|
|
54
|
+
get_monitors(): Promise<any[]>;
|
|
55
|
+
get_platform(): Promise<string>;
|
|
56
|
+
get_primary_monitor(): Promise<Record<string, unknown>>;
|
|
57
|
+
get_version(): Promise<string>;
|
|
58
|
+
info(): Promise<Record<string, unknown>>;
|
|
59
|
+
is_dir(path: string): Promise<boolean>;
|
|
60
|
+
is_enabled(): Promise<boolean>;
|
|
61
|
+
is_file(path: string): Promise<boolean>;
|
|
62
|
+
list(path: string, include_hidden?: boolean): Promise<any[]>;
|
|
63
|
+
list_dir(path: string, include_hidden?: boolean): Promise<any[]>;
|
|
64
|
+
message(title: string, body: string, level?: string): Promise<Record<string, unknown>>;
|
|
65
|
+
mkdir(path: string, parents?: boolean): Promise<void>;
|
|
66
|
+
notification_history(limit?: number): Promise<any[]>;
|
|
67
|
+
notification_notify(title: string, body: string, icon?: string, app_name?: string, timeout?: number): Promise<Record<string, unknown>>;
|
|
68
|
+
notification_state(): Promise<Record<string, unknown>>;
|
|
69
|
+
on_resume(callback: unknown): Promise<void>;
|
|
70
|
+
on_suspend(callback: unknown): Promise<void>;
|
|
71
|
+
open(title?: string, filters?: any[], multiple?: boolean): Promise<Record<string, unknown>>;
|
|
72
|
+
open_directory(title?: string): Promise<Record<string, unknown>>;
|
|
73
|
+
open_file(title?: string, filters?: any[], multiple?: boolean): Promise<Record<string, unknown>>;
|
|
74
|
+
open_url(url: string): Promise<void>;
|
|
75
|
+
platform(): Promise<string>;
|
|
76
|
+
read(path: string, max_size?: number): Promise<string>;
|
|
77
|
+
read_binary(path: string, max_size?: number): Promise<unknown>;
|
|
78
|
+
register(accelerator: string, callback: unknown): Promise<boolean>;
|
|
79
|
+
relaunch(): Promise<void>;
|
|
80
|
+
request_single_instance_lock(instance_name?: string): Promise<boolean>;
|
|
81
|
+
request_user_attention(is_critical?: boolean): Promise<void>;
|
|
82
|
+
save(title?: string, default_path?: string, filters?: any[]): Promise<Record<string, unknown>>;
|
|
83
|
+
save_file(title?: string, default_path?: string, filters?: any[]): Promise<Record<string, unknown>>;
|
|
84
|
+
set_progress_bar(progress: number): Promise<void>;
|
|
85
|
+
unregister(accelerator: string): Promise<boolean>;
|
|
86
|
+
unregister_all(): Promise<boolean>;
|
|
87
|
+
version(): Promise<string>;
|
|
88
|
+
write(path: string, content: string): Promise<void>;
|
|
89
|
+
write_binary(path: string, content: unknown): Promise<void>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export declare function isForgeAvailable(): boolean;
|
|
93
|
+
export declare function getForge(): ForgeApi;
|
|
94
|
+
export declare function invoke(command: string, args?: Record<string, unknown>): Promise<unknown>;
|
|
95
|
+
export declare function invokeDetailed(command: string, args?: Record<string, unknown>, options?: InvokeDetailedOptions): Promise<unknown>;
|
|
96
|
+
export declare function on(eventName: string, handler: (payload: unknown) => void): unknown;
|
|
97
|
+
export declare function once(eventName: string, handler: (payload: unknown) => void): unknown;
|
|
98
|
+
export declare function off(eventName: string, handler: (payload: unknown) => void): unknown;
|
|
99
|
+
export declare const forge: ForgeApi;
|
|
100
|
+
export default forge;
|
package/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
function missingRuntimeError() {
|
|
2
|
+
return new Error(
|
|
3
|
+
"Forge runtime is not available. Load forge.js in a Forge window or run inside Forge dev/build output."
|
|
4
|
+
);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function isForgeAvailable() {
|
|
8
|
+
return typeof globalThis !== "undefined" && !!globalThis.__forge__;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function getForge() {
|
|
12
|
+
if (!isForgeAvailable()) {
|
|
13
|
+
throw missingRuntimeError();
|
|
14
|
+
}
|
|
15
|
+
return globalThis.__forge__;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function invoke(command, args = {}) {
|
|
19
|
+
return getForge().invoke(command, args);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function invokeDetailed(command, args = {}, options = {}) {
|
|
23
|
+
return getForge().invokeDetailed(command, args, options);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function on(eventName, handler) {
|
|
27
|
+
return getForge().on(eventName, handler);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function once(eventName, handler) {
|
|
31
|
+
return getForge().once(eventName, handler);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function off(eventName, handler) {
|
|
35
|
+
return getForge().off(eventName, handler);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const forge = new Proxy(
|
|
39
|
+
{},
|
|
40
|
+
{
|
|
41
|
+
get(_target, property) {
|
|
42
|
+
return getForge()[property];
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
export default forge;
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@forgedesk/api",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Typed JavaScript API bindings for Forge applications",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://forge-framework.dev",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/swadhinbiswas/Forge.git",
|
|
10
|
+
"directory": "packages/api"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/swadhinbiswas/Forge/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./index.js",
|
|
17
|
+
"types": "./index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./index.d.ts",
|
|
21
|
+
"default": "./index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"index.js",
|
|
26
|
+
"index.d.ts",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"forge",
|
|
34
|
+
"desktop",
|
|
35
|
+
"ipc",
|
|
36
|
+
"webview"
|
|
37
|
+
]
|
|
38
|
+
}
|