@qpjoy/electron-plugin-sdk 0.1.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/dist/index.d.ts +108 -0
- package/dist/index.js +25 -0
- package/package.json +47 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @qpjoy/electron-plugin-sdk
|
|
3
|
+
*
|
|
4
|
+
* Public surface for plugin authors. Importing anything else from
|
|
5
|
+
* `@qpjoy/electron-market` directly is **not** part of the contract and may
|
|
6
|
+
* break across host versions.
|
|
7
|
+
*/
|
|
8
|
+
export declare const PLUGIN_SPEC_VERSION: 1;
|
|
9
|
+
/**
|
|
10
|
+
* Static permission strings. Anything that needs a parameter uses the
|
|
11
|
+
* `category:scope[:detail]` form so it can be parsed without changing the
|
|
12
|
+
* type for every new resource.
|
|
13
|
+
*/
|
|
14
|
+
export type Permission = 'fs:userData' | 'fs:any' | `net:listen:${number}` | `net:listen:${number}-${number}` | `net:fetch:${string}` | 'system:proxy' | `system:exec:${string}` | `ipc:${string}` | 'ipc:cross' | 'ui:adminPanel';
|
|
15
|
+
export type ActivationEvent = 'onStartup' | `onCommand:${string}` | `onSetting:${string}`;
|
|
16
|
+
export interface PluginManifest {
|
|
17
|
+
/** Stable id, reverse-DNS style. NOT the npm name. */
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
version: string;
|
|
21
|
+
author?: string;
|
|
22
|
+
description?: string;
|
|
23
|
+
homepage?: string;
|
|
24
|
+
engines: {
|
|
25
|
+
/** semver range against @qpjoy/electron-market (the host runtime). */
|
|
26
|
+
electronMarket?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Legacy alias for `electronMarket`. Accepted by hosts >= 0.2.0 so
|
|
29
|
+
* plugins published against the pre-rename spec still load.
|
|
30
|
+
* New plugins should use `electronMarket`.
|
|
31
|
+
* @deprecated Use `electronMarket`.
|
|
32
|
+
*/
|
|
33
|
+
electronPlugin?: string;
|
|
34
|
+
/** semver range against electron itself */
|
|
35
|
+
electron?: string;
|
|
36
|
+
};
|
|
37
|
+
permissions: Permission[];
|
|
38
|
+
activationEvents: ActivationEvent[];
|
|
39
|
+
contributes?: {
|
|
40
|
+
adminPanel?: {
|
|
41
|
+
url: string;
|
|
42
|
+
label?: string;
|
|
43
|
+
};
|
|
44
|
+
settings?: {
|
|
45
|
+
schema: string;
|
|
46
|
+
};
|
|
47
|
+
commands?: Array<{
|
|
48
|
+
id: string;
|
|
49
|
+
title: string;
|
|
50
|
+
}>;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export interface PluginHostBridge {
|
|
54
|
+
/** A reduced electron triple. The full one is gated behind permissions. */
|
|
55
|
+
app: import('electron').App;
|
|
56
|
+
ipcMain: import('electron').IpcMain;
|
|
57
|
+
session: import('electron').Session;
|
|
58
|
+
/** Ask the host to re-apply session proxy. Requires `system:proxy`. */
|
|
59
|
+
applyProxy(): Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
export interface PluginContext<S = unknown> {
|
|
62
|
+
readonly manifest: PluginManifest;
|
|
63
|
+
readonly host: PluginHostBridge;
|
|
64
|
+
/** Sandbox dir, always inside `userData/plugins/<id>/`. */
|
|
65
|
+
readonly userDataDir: string;
|
|
66
|
+
/** Persistent settings store. Schema is whatever the plugin wants. */
|
|
67
|
+
readonly settings: {
|
|
68
|
+
get(): S;
|
|
69
|
+
set(next: Partial<S>): void;
|
|
70
|
+
onChange(listener: (next: S) => void): () => void;
|
|
71
|
+
};
|
|
72
|
+
/** Convenience wrapper around `settings.onChange`. */
|
|
73
|
+
onConfigChange(listener: (next: S) => void): () => void;
|
|
74
|
+
/**
|
|
75
|
+
* Cross-plugin RPC. Requires `ipc:cross` on both sides.
|
|
76
|
+
*
|
|
77
|
+
* The function parameter type uses `any[]` rather than `unknown[]` so that
|
|
78
|
+
* authors can pass concretely-typed methods (e.g. `(id: number) => Promise<void>`)
|
|
79
|
+
* without casts. The runtime never inspects the signature; only the method
|
|
80
|
+
* names are dispatched.
|
|
81
|
+
*/
|
|
82
|
+
expose(api: Record<string, (...args: any[]) => any>): void;
|
|
83
|
+
call<T = unknown>(pluginId: string, method: string, ...args: unknown[]): Promise<T>;
|
|
84
|
+
/** Permission-gated helpers — throw `PermissionDeniedError` if not granted. */
|
|
85
|
+
spawn(bin: string, args: string[], opts?: {
|
|
86
|
+
cwd?: string;
|
|
87
|
+
}): import('child_process').ChildProcess;
|
|
88
|
+
fetch(url: string, init?: RequestInit): Promise<Response>;
|
|
89
|
+
/** Structured logger that surfaces in the 23455 admin panel. */
|
|
90
|
+
readonly log: {
|
|
91
|
+
info(msg: string, meta?: Record<string, unknown>): void;
|
|
92
|
+
warn(msg: string, meta?: Record<string, unknown>): void;
|
|
93
|
+
error(msg: string, meta?: Record<string, unknown>): void;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
export declare class PermissionDeniedError extends Error {
|
|
97
|
+
readonly permission: Permission;
|
|
98
|
+
constructor(permission: Permission);
|
|
99
|
+
}
|
|
100
|
+
/** A plugin returns a disposer; the host calls it on deactivate / uninstall. */
|
|
101
|
+
export type PluginDispose = () => void | Promise<void>;
|
|
102
|
+
export interface PluginModule<S = unknown> {
|
|
103
|
+
activate(ctx: PluginContext<S>): Promise<PluginDispose | void> | PluginDispose | void;
|
|
104
|
+
/** Optional; defaults to invoking the disposer returned by `activate`. */
|
|
105
|
+
deactivate?(ctx: PluginContext<S>): Promise<void> | void;
|
|
106
|
+
}
|
|
107
|
+
/** Identity function. Exists for typing and future codegen / static analysis. */
|
|
108
|
+
export declare function definePlugin<S = unknown>(mod: PluginModule<S>): PluginModule<S>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @qpjoy/electron-plugin-sdk
|
|
4
|
+
*
|
|
5
|
+
* Public surface for plugin authors. Importing anything else from
|
|
6
|
+
* `@qpjoy/electron-market` directly is **not** part of the contract and may
|
|
7
|
+
* break across host versions.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.PermissionDeniedError = exports.PLUGIN_SPEC_VERSION = void 0;
|
|
11
|
+
exports.definePlugin = definePlugin;
|
|
12
|
+
exports.PLUGIN_SPEC_VERSION = 1;
|
|
13
|
+
class PermissionDeniedError extends Error {
|
|
14
|
+
permission;
|
|
15
|
+
constructor(permission) {
|
|
16
|
+
super(`Permission denied: ${permission}`);
|
|
17
|
+
this.permission = permission;
|
|
18
|
+
this.name = 'PermissionDeniedError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.PermissionDeniedError = PermissionDeniedError;
|
|
22
|
+
/** Identity function. Exists for typing and future codegen / static analysis. */
|
|
23
|
+
function definePlugin(mod) {
|
|
24
|
+
return mod;
|
|
25
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@qpjoy/electron-plugin-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Types and helpers for authoring QPJoy electron plugins (definePlugin, Permission catalog, PluginContext).",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"keywords": [
|
|
14
|
+
"electron",
|
|
15
|
+
"plugin",
|
|
16
|
+
"sdk",
|
|
17
|
+
"qpjoy",
|
|
18
|
+
"marketplace"
|
|
19
|
+
],
|
|
20
|
+
"homepage": "https://github.com/qpjoy/electron-plugin",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/qpjoy/electron-plugin.git",
|
|
24
|
+
"directory": "packages/electron-plugin-sdk"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"electron": ">=28"
|
|
31
|
+
},
|
|
32
|
+
"peerDependenciesMeta": {
|
|
33
|
+
"electron": {
|
|
34
|
+
"optional": true
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^22.10.7",
|
|
39
|
+
"electron": "^34.0.0",
|
|
40
|
+
"typescript": "^5.7.3"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsc -p tsconfig.json",
|
|
44
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
45
|
+
"lint": "tsc -p tsconfig.json --noEmit"
|
|
46
|
+
}
|
|
47
|
+
}
|