@wvb/bridge 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/CHANGELOG.md +1 -0
- package/README.md +1 -0
- package/dist/index-B2ggQzrN.d.cts +162 -0
- package/dist/index-B2ggQzrN.d.ts +162 -0
- package/dist/index.cjs +278 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +273 -0
- package/dist/platform-mock-BmiQzf2l.cjs +73 -0
- package/dist/platform-mock-Dh3dBF3P.js +50 -0
- package/dist/testing/index.cjs +117 -0
- package/dist/testing/index.d.cts +75 -0
- package/dist/testing/index.d.ts +75 -0
- package/dist/testing/index.js +113 -0
- package/package.json +53 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Changelog
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @wvb/bridge
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
//#region src/invoke.d.ts
|
|
2
|
+
interface InvokeParams {
|
|
3
|
+
[key: string | number]: any;
|
|
4
|
+
}
|
|
5
|
+
declare function invoke<T = unknown>(name: string, params?: InvokeParams): Promise<T>;
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/platform.d.ts
|
|
8
|
+
type PlatformType = "electron" | "tauri" | "android" | "ios";
|
|
9
|
+
declare const platform: {
|
|
10
|
+
type: PlatformType | undefined;
|
|
11
|
+
isElectron: boolean;
|
|
12
|
+
isTauri: boolean;
|
|
13
|
+
isAndroid: boolean;
|
|
14
|
+
isIos: boolean;
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/remote.d.ts
|
|
18
|
+
/** List item of remote bundles. */
|
|
19
|
+
interface ListRemoteBundleInfo {
|
|
20
|
+
/** The name of the bundle. */
|
|
21
|
+
name: string;
|
|
22
|
+
/** The version of the bundle. */
|
|
23
|
+
version: string;
|
|
24
|
+
}
|
|
25
|
+
declare function listBundles$1(channel?: string): Promise<ListRemoteBundleInfo[]>;
|
|
26
|
+
/** Information of a remote bundle. */
|
|
27
|
+
interface RemoteBundleInfo {
|
|
28
|
+
/** The name of the bundle. */
|
|
29
|
+
name: string;
|
|
30
|
+
/** The version of the bundle. */
|
|
31
|
+
version: string;
|
|
32
|
+
/** "ETag" header value. */
|
|
33
|
+
etag?: string;
|
|
34
|
+
/** Integrity value to verify the bundle. */
|
|
35
|
+
integrity?: string;
|
|
36
|
+
/** Signature value to verify the bundle. */
|
|
37
|
+
signature?: string;
|
|
38
|
+
/** Last modified timestamp. (uses GMT) */
|
|
39
|
+
lastModified?: string;
|
|
40
|
+
}
|
|
41
|
+
declare function getInfo(bundleName: string, channel?: string): Promise<RemoteBundleInfo>;
|
|
42
|
+
declare function download$1(bundleName: string, channel?: string): Promise<RemoteBundleInfo>;
|
|
43
|
+
declare function downloadVersion(bundleName: string, version: string): Promise<RemoteBundleInfo>;
|
|
44
|
+
interface RemoteApi {
|
|
45
|
+
listBundles: typeof listBundles$1;
|
|
46
|
+
getInfo: typeof getInfo;
|
|
47
|
+
download: typeof download$1;
|
|
48
|
+
downloadVersion: typeof downloadVersion;
|
|
49
|
+
}
|
|
50
|
+
declare const remote: RemoteApi;
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/source.d.ts
|
|
53
|
+
/**
|
|
54
|
+
* - builtin: Built-in bundle which is included in the application.
|
|
55
|
+
* - remote: Remote bundle which is downloaded from a remote server.
|
|
56
|
+
*/
|
|
57
|
+
type BundleSourceType = "builtin" | "remote";
|
|
58
|
+
/**
|
|
59
|
+
* Bundle manifest metadata.
|
|
60
|
+
*/
|
|
61
|
+
interface BundleManifestMetadata {
|
|
62
|
+
/** "ETag" header value. */
|
|
63
|
+
etag?: string;
|
|
64
|
+
/** Integrity value to verify the bundle. */
|
|
65
|
+
integrity?: string;
|
|
66
|
+
/** Signature value to verify the bundle. */
|
|
67
|
+
signature?: string;
|
|
68
|
+
/** Last modified timestamp. (uses GMT) */
|
|
69
|
+
lastModified?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* List item of bundle manifests.
|
|
73
|
+
*/
|
|
74
|
+
interface ListBundleManifestItem {
|
|
75
|
+
/** The name of the bundle. */
|
|
76
|
+
name: string;
|
|
77
|
+
/** The version of the bundle. */
|
|
78
|
+
version: string;
|
|
79
|
+
/** Whether the bundle is currently active. */
|
|
80
|
+
current: boolean;
|
|
81
|
+
/** Bundle manifest metadata. */
|
|
82
|
+
metadata: BundleManifestMetadata;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* List item of bundles.
|
|
86
|
+
*/
|
|
87
|
+
interface ListBundleItem {
|
|
88
|
+
/** The type of the bundle. */
|
|
89
|
+
type: BundleSourceType;
|
|
90
|
+
/** The bundle item. */
|
|
91
|
+
item: ListBundleManifestItem;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Bundle source version.
|
|
95
|
+
*/
|
|
96
|
+
interface BundleSourceVersion {
|
|
97
|
+
/** The type of the bundle source. */
|
|
98
|
+
type: BundleSourceType;
|
|
99
|
+
/** The version of the bundle. */
|
|
100
|
+
version: string;
|
|
101
|
+
}
|
|
102
|
+
declare function listBundles(): Promise<ListBundleItem[]>;
|
|
103
|
+
declare function loadVersion(bundleName: string): Promise<BundleSourceVersion | null>;
|
|
104
|
+
declare function updateVersion(bundleName: string, version: string): Promise<void>;
|
|
105
|
+
declare function resolveFilepath(bundleName: string): Promise<string>;
|
|
106
|
+
declare function getBuiltinBundleFilepath(bundleName: string, version: string): Promise<string>;
|
|
107
|
+
declare function getRemoteBundleFilepath(bundleName: string, version: string): Promise<string>;
|
|
108
|
+
declare function loadBuiltinMetadata(bundleName: string, version: string): Promise<BundleManifestMetadata | null>;
|
|
109
|
+
declare function loadRemoteMetadata(bundleName: string, version: string): Promise<BundleManifestMetadata | null>;
|
|
110
|
+
declare function unloadDescriptor(bundleName: string): Promise<boolean>;
|
|
111
|
+
declare function removeRemoteBundle(bundleName: string, version: string): Promise<boolean>;
|
|
112
|
+
declare function remoteRetainedVersions(bundleName: string): Promise<string[]>;
|
|
113
|
+
declare function pruneRemoteBundles(bundleName: string): Promise<string[]>;
|
|
114
|
+
interface SourceApi {
|
|
115
|
+
listBundles: typeof listBundles;
|
|
116
|
+
loadVersion: typeof loadVersion;
|
|
117
|
+
updateVersion: typeof updateVersion;
|
|
118
|
+
resolveFilepath: typeof resolveFilepath;
|
|
119
|
+
getBuiltinBundleFilepath: typeof getBuiltinBundleFilepath;
|
|
120
|
+
getRemoteBundleFilepath: typeof getRemoteBundleFilepath;
|
|
121
|
+
loadBuiltinMetadata: typeof loadBuiltinMetadata;
|
|
122
|
+
loadRemoteMetadata: typeof loadRemoteMetadata;
|
|
123
|
+
unloadDescriptor: typeof unloadDescriptor;
|
|
124
|
+
removeRemoteBundle: typeof removeRemoteBundle;
|
|
125
|
+
remoteRetainedVersions: typeof remoteRetainedVersions;
|
|
126
|
+
pruneRemoteBundles: typeof pruneRemoteBundles;
|
|
127
|
+
}
|
|
128
|
+
declare const source: SourceApi;
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/updater.d.ts
|
|
131
|
+
declare function listRemotes(): Promise<ListRemoteBundleInfo[]>;
|
|
132
|
+
/** Information of an available bundle update. */
|
|
133
|
+
interface BundleUpdateInfo {
|
|
134
|
+
/** The name of the bundle. */
|
|
135
|
+
name: string;
|
|
136
|
+
/** The latest version available from the remote. */
|
|
137
|
+
version: string;
|
|
138
|
+
/** The version of the bundle currently installed locally. */
|
|
139
|
+
localVersion?: string;
|
|
140
|
+
/** Whether a new update is available. */
|
|
141
|
+
isAvailable: boolean;
|
|
142
|
+
/** "ETag" header value. */
|
|
143
|
+
etag?: string;
|
|
144
|
+
/** Integrity value to verify the bundle. */
|
|
145
|
+
integrity?: string;
|
|
146
|
+
/** Signature value to verify the bundle. */
|
|
147
|
+
signature?: string;
|
|
148
|
+
/** Last modified timestamp. (uses GMT) */
|
|
149
|
+
lastModified?: string;
|
|
150
|
+
}
|
|
151
|
+
declare function getUpdate(bundleName: string): Promise<BundleUpdateInfo>;
|
|
152
|
+
declare function download(bundleName: string, version?: string): Promise<RemoteBundleInfo>;
|
|
153
|
+
declare function install(bundleName: string, version: string): Promise<void>;
|
|
154
|
+
interface UpdaterApi {
|
|
155
|
+
listRemotes: typeof listRemotes;
|
|
156
|
+
getUpdate: typeof getUpdate;
|
|
157
|
+
download: typeof download;
|
|
158
|
+
install: typeof install;
|
|
159
|
+
}
|
|
160
|
+
declare const updater: UpdaterApi;
|
|
161
|
+
//#endregion
|
|
162
|
+
export { InvokeParams as _, BundleSourceType as a, ListBundleManifestItem as c, ListRemoteBundleInfo as d, RemoteApi as f, platform as g, PlatformType as h, BundleManifestMetadata as i, SourceApi as l, remote as m, UpdaterApi as n, BundleSourceVersion as o, RemoteBundleInfo as p, updater as r, ListBundleItem as s, BundleUpdateInfo as t, source as u, invoke as v };
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
//#region src/invoke.d.ts
|
|
2
|
+
interface InvokeParams {
|
|
3
|
+
[key: string | number]: any;
|
|
4
|
+
}
|
|
5
|
+
declare function invoke<T = unknown>(name: string, params?: InvokeParams): Promise<T>;
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/platform.d.ts
|
|
8
|
+
type PlatformType = "electron" | "tauri" | "android" | "ios";
|
|
9
|
+
declare const platform: {
|
|
10
|
+
type: PlatformType | undefined;
|
|
11
|
+
isElectron: boolean;
|
|
12
|
+
isTauri: boolean;
|
|
13
|
+
isAndroid: boolean;
|
|
14
|
+
isIos: boolean;
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/remote.d.ts
|
|
18
|
+
/** List item of remote bundles. */
|
|
19
|
+
interface ListRemoteBundleInfo {
|
|
20
|
+
/** The name of the bundle. */
|
|
21
|
+
name: string;
|
|
22
|
+
/** The version of the bundle. */
|
|
23
|
+
version: string;
|
|
24
|
+
}
|
|
25
|
+
declare function listBundles$1(channel?: string): Promise<ListRemoteBundleInfo[]>;
|
|
26
|
+
/** Information of a remote bundle. */
|
|
27
|
+
interface RemoteBundleInfo {
|
|
28
|
+
/** The name of the bundle. */
|
|
29
|
+
name: string;
|
|
30
|
+
/** The version of the bundle. */
|
|
31
|
+
version: string;
|
|
32
|
+
/** "ETag" header value. */
|
|
33
|
+
etag?: string;
|
|
34
|
+
/** Integrity value to verify the bundle. */
|
|
35
|
+
integrity?: string;
|
|
36
|
+
/** Signature value to verify the bundle. */
|
|
37
|
+
signature?: string;
|
|
38
|
+
/** Last modified timestamp. (uses GMT) */
|
|
39
|
+
lastModified?: string;
|
|
40
|
+
}
|
|
41
|
+
declare function getInfo(bundleName: string, channel?: string): Promise<RemoteBundleInfo>;
|
|
42
|
+
declare function download$1(bundleName: string, channel?: string): Promise<RemoteBundleInfo>;
|
|
43
|
+
declare function downloadVersion(bundleName: string, version: string): Promise<RemoteBundleInfo>;
|
|
44
|
+
interface RemoteApi {
|
|
45
|
+
listBundles: typeof listBundles$1;
|
|
46
|
+
getInfo: typeof getInfo;
|
|
47
|
+
download: typeof download$1;
|
|
48
|
+
downloadVersion: typeof downloadVersion;
|
|
49
|
+
}
|
|
50
|
+
declare const remote: RemoteApi;
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/source.d.ts
|
|
53
|
+
/**
|
|
54
|
+
* - builtin: Built-in bundle which is included in the application.
|
|
55
|
+
* - remote: Remote bundle which is downloaded from a remote server.
|
|
56
|
+
*/
|
|
57
|
+
type BundleSourceType = "builtin" | "remote";
|
|
58
|
+
/**
|
|
59
|
+
* Bundle manifest metadata.
|
|
60
|
+
*/
|
|
61
|
+
interface BundleManifestMetadata {
|
|
62
|
+
/** "ETag" header value. */
|
|
63
|
+
etag?: string;
|
|
64
|
+
/** Integrity value to verify the bundle. */
|
|
65
|
+
integrity?: string;
|
|
66
|
+
/** Signature value to verify the bundle. */
|
|
67
|
+
signature?: string;
|
|
68
|
+
/** Last modified timestamp. (uses GMT) */
|
|
69
|
+
lastModified?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* List item of bundle manifests.
|
|
73
|
+
*/
|
|
74
|
+
interface ListBundleManifestItem {
|
|
75
|
+
/** The name of the bundle. */
|
|
76
|
+
name: string;
|
|
77
|
+
/** The version of the bundle. */
|
|
78
|
+
version: string;
|
|
79
|
+
/** Whether the bundle is currently active. */
|
|
80
|
+
current: boolean;
|
|
81
|
+
/** Bundle manifest metadata. */
|
|
82
|
+
metadata: BundleManifestMetadata;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* List item of bundles.
|
|
86
|
+
*/
|
|
87
|
+
interface ListBundleItem {
|
|
88
|
+
/** The type of the bundle. */
|
|
89
|
+
type: BundleSourceType;
|
|
90
|
+
/** The bundle item. */
|
|
91
|
+
item: ListBundleManifestItem;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Bundle source version.
|
|
95
|
+
*/
|
|
96
|
+
interface BundleSourceVersion {
|
|
97
|
+
/** The type of the bundle source. */
|
|
98
|
+
type: BundleSourceType;
|
|
99
|
+
/** The version of the bundle. */
|
|
100
|
+
version: string;
|
|
101
|
+
}
|
|
102
|
+
declare function listBundles(): Promise<ListBundleItem[]>;
|
|
103
|
+
declare function loadVersion(bundleName: string): Promise<BundleSourceVersion | null>;
|
|
104
|
+
declare function updateVersion(bundleName: string, version: string): Promise<void>;
|
|
105
|
+
declare function resolveFilepath(bundleName: string): Promise<string>;
|
|
106
|
+
declare function getBuiltinBundleFilepath(bundleName: string, version: string): Promise<string>;
|
|
107
|
+
declare function getRemoteBundleFilepath(bundleName: string, version: string): Promise<string>;
|
|
108
|
+
declare function loadBuiltinMetadata(bundleName: string, version: string): Promise<BundleManifestMetadata | null>;
|
|
109
|
+
declare function loadRemoteMetadata(bundleName: string, version: string): Promise<BundleManifestMetadata | null>;
|
|
110
|
+
declare function unloadDescriptor(bundleName: string): Promise<boolean>;
|
|
111
|
+
declare function removeRemoteBundle(bundleName: string, version: string): Promise<boolean>;
|
|
112
|
+
declare function remoteRetainedVersions(bundleName: string): Promise<string[]>;
|
|
113
|
+
declare function pruneRemoteBundles(bundleName: string): Promise<string[]>;
|
|
114
|
+
interface SourceApi {
|
|
115
|
+
listBundles: typeof listBundles;
|
|
116
|
+
loadVersion: typeof loadVersion;
|
|
117
|
+
updateVersion: typeof updateVersion;
|
|
118
|
+
resolveFilepath: typeof resolveFilepath;
|
|
119
|
+
getBuiltinBundleFilepath: typeof getBuiltinBundleFilepath;
|
|
120
|
+
getRemoteBundleFilepath: typeof getRemoteBundleFilepath;
|
|
121
|
+
loadBuiltinMetadata: typeof loadBuiltinMetadata;
|
|
122
|
+
loadRemoteMetadata: typeof loadRemoteMetadata;
|
|
123
|
+
unloadDescriptor: typeof unloadDescriptor;
|
|
124
|
+
removeRemoteBundle: typeof removeRemoteBundle;
|
|
125
|
+
remoteRetainedVersions: typeof remoteRetainedVersions;
|
|
126
|
+
pruneRemoteBundles: typeof pruneRemoteBundles;
|
|
127
|
+
}
|
|
128
|
+
declare const source: SourceApi;
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/updater.d.ts
|
|
131
|
+
declare function listRemotes(): Promise<ListRemoteBundleInfo[]>;
|
|
132
|
+
/** Information of an available bundle update. */
|
|
133
|
+
interface BundleUpdateInfo {
|
|
134
|
+
/** The name of the bundle. */
|
|
135
|
+
name: string;
|
|
136
|
+
/** The latest version available from the remote. */
|
|
137
|
+
version: string;
|
|
138
|
+
/** The version of the bundle currently installed locally. */
|
|
139
|
+
localVersion?: string;
|
|
140
|
+
/** Whether a new update is available. */
|
|
141
|
+
isAvailable: boolean;
|
|
142
|
+
/** "ETag" header value. */
|
|
143
|
+
etag?: string;
|
|
144
|
+
/** Integrity value to verify the bundle. */
|
|
145
|
+
integrity?: string;
|
|
146
|
+
/** Signature value to verify the bundle. */
|
|
147
|
+
signature?: string;
|
|
148
|
+
/** Last modified timestamp. (uses GMT) */
|
|
149
|
+
lastModified?: string;
|
|
150
|
+
}
|
|
151
|
+
declare function getUpdate(bundleName: string): Promise<BundleUpdateInfo>;
|
|
152
|
+
declare function download(bundleName: string, version?: string): Promise<RemoteBundleInfo>;
|
|
153
|
+
declare function install(bundleName: string, version: string): Promise<void>;
|
|
154
|
+
interface UpdaterApi {
|
|
155
|
+
listRemotes: typeof listRemotes;
|
|
156
|
+
getUpdate: typeof getUpdate;
|
|
157
|
+
download: typeof download;
|
|
158
|
+
install: typeof install;
|
|
159
|
+
}
|
|
160
|
+
declare const updater: UpdaterApi;
|
|
161
|
+
//#endregion
|
|
162
|
+
export { InvokeParams as _, BundleSourceType as a, ListBundleManifestItem as c, ListRemoteBundleInfo as d, RemoteApi as f, platform as g, PlatformType as h, BundleManifestMetadata as i, SourceApi as l, remote as m, UpdaterApi as n, BundleSourceVersion as o, RemoteBundleInfo as p, updater as r, ListBundleItem as s, BundleUpdateInfo as t, source as u, invoke as v };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_platform_mock = require("./platform-mock-BmiQzf2l.cjs");
|
|
3
|
+
let _tauri_apps_api_core = require("@tauri-apps/api/core");
|
|
4
|
+
//#region src/callback.ts
|
|
5
|
+
var CallbackBag = class {
|
|
6
|
+
constructor() {
|
|
7
|
+
require_platform_mock._defineProperty(this, "ids", []);
|
|
8
|
+
}
|
|
9
|
+
generate(callback) {
|
|
10
|
+
const w = require_platform_mock.getWindow();
|
|
11
|
+
w.__wvb_bridge_callbacks__ ?? (w.__wvb_bridge_callbacks__ = {});
|
|
12
|
+
const id = `cb_${generateId()}`;
|
|
13
|
+
w.__wvb_bridge_callbacks__[id] = callback;
|
|
14
|
+
this.ids.push(id);
|
|
15
|
+
return `(
|
|
16
|
+
function() {
|
|
17
|
+
var cb = __wvb_bridge_callbacks__ != null
|
|
18
|
+
? __wvb_bridge_callbacks__["${id}"]
|
|
19
|
+
: undefined;
|
|
20
|
+
if (cb == null) {
|
|
21
|
+
throw new Error("cannot find callback: ${id}");
|
|
22
|
+
}
|
|
23
|
+
return cb.apply(undefined, arguments);
|
|
24
|
+
}
|
|
25
|
+
)`.replace(/(\n|\s{2,})/g, " ");
|
|
26
|
+
}
|
|
27
|
+
clean() {
|
|
28
|
+
const w = require_platform_mock.getWindow();
|
|
29
|
+
for (const id of this.ids) if (w.__wvb_bridge_callbacks__ != null) Reflect.deleteProperty(w.__wvb_bridge_callbacks__, id);
|
|
30
|
+
this.ids = [];
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
function generateId() {
|
|
34
|
+
const w = require_platform_mock.getWindow();
|
|
35
|
+
if (typeof w?.crypto?.randomUUID === "function") return w.crypto.randomUUID().replace(/-/g, "");
|
|
36
|
+
const bytes = new Uint8Array(16);
|
|
37
|
+
if (typeof w?.crypto?.getRandomValues === "function") w.crypto.getRandomValues(bytes);
|
|
38
|
+
else for (let i = 0; i < bytes.length; i++) bytes[i] = Math.floor(Math.random() * 256);
|
|
39
|
+
bytes[6] = (bytes[6] ?? 0) & 15 | 64;
|
|
40
|
+
bytes[8] = (bytes[8] ?? 0) & 63 | 128;
|
|
41
|
+
let id = "";
|
|
42
|
+
for (const byte of bytes) id += byte.toString(16).padStart(2, "0");
|
|
43
|
+
return id;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/error.ts
|
|
47
|
+
function unknownPlatform() {
|
|
48
|
+
throw new Error("Unknown platform. Make sure native webview supports webview-bundle.");
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/platform.ts
|
|
52
|
+
function isElectron() {
|
|
53
|
+
return require_platform_mock.getWindow()?.wvbElectron != null;
|
|
54
|
+
}
|
|
55
|
+
function isAndroid() {
|
|
56
|
+
return require_platform_mock.getWindow()?.wvbAndroid != null;
|
|
57
|
+
}
|
|
58
|
+
function isIos() {
|
|
59
|
+
return require_platform_mock.getWindow()?.webkit?.messageHandlers?.wvbIos != null;
|
|
60
|
+
}
|
|
61
|
+
function resolveType() {
|
|
62
|
+
const mocked = require_platform_mock.getWindow()[require_platform_mock.PLATFORM_MOCK_KEY];
|
|
63
|
+
if (mocked != null) return mocked;
|
|
64
|
+
if (isElectron()) return "electron";
|
|
65
|
+
if ((0, _tauri_apps_api_core.isTauri)()) return "tauri";
|
|
66
|
+
if (isAndroid()) return "android";
|
|
67
|
+
if (isIos()) return "ios";
|
|
68
|
+
}
|
|
69
|
+
const platform = {
|
|
70
|
+
get type() {
|
|
71
|
+
return resolveType();
|
|
72
|
+
},
|
|
73
|
+
get isElectron() {
|
|
74
|
+
return resolveType() === "electron";
|
|
75
|
+
},
|
|
76
|
+
get isTauri() {
|
|
77
|
+
return resolveType() === "tauri";
|
|
78
|
+
},
|
|
79
|
+
get isAndroid() {
|
|
80
|
+
return resolveType() === "android";
|
|
81
|
+
},
|
|
82
|
+
get isIos() {
|
|
83
|
+
return resolveType() === "ios";
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/utils.ts
|
|
88
|
+
function snakeCase(str) {
|
|
89
|
+
return str.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/[^a-zA-Z0-9]+/g, " ").trim().replace(/ /g, "_").toLowerCase();
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/invoke.ts
|
|
93
|
+
function invoke(name, params) {
|
|
94
|
+
const mock = require_platform_mock.getWindow()[require_platform_mock.INVOKE_MOCK_KEY];
|
|
95
|
+
if (mock != null) return mock(name, params);
|
|
96
|
+
switch (platform.type) {
|
|
97
|
+
case "electron": return require_platform_mock.getWindow().wvbElectron.invoke(name, params);
|
|
98
|
+
case "tauri": return (0, _tauri_apps_api_core.invoke)(toTauriCommand(name), params);
|
|
99
|
+
case "android":
|
|
100
|
+
case "ios": {
|
|
101
|
+
const bridge = getMobileBridge(platform.type);
|
|
102
|
+
return new Promise((resolve, reject) => {
|
|
103
|
+
const bag = new CallbackBag();
|
|
104
|
+
const success = bag.generate((result) => {
|
|
105
|
+
resolve(result);
|
|
106
|
+
bag.clean();
|
|
107
|
+
});
|
|
108
|
+
const error = bag.generate((error) => {
|
|
109
|
+
reject(error);
|
|
110
|
+
bag.clean();
|
|
111
|
+
});
|
|
112
|
+
try {
|
|
113
|
+
bridge.postMessage(name, params, success, error);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
bag.clean();
|
|
116
|
+
reject(error);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
default: unknownPlatform();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function getMobileBridge(platform) {
|
|
124
|
+
switch (platform) {
|
|
125
|
+
case "android": {
|
|
126
|
+
const w = require_platform_mock.getWindow();
|
|
127
|
+
return { postMessage: (name, params, success, error) => w.wvbAndroid.postMessage(JSON.stringify({
|
|
128
|
+
name,
|
|
129
|
+
params,
|
|
130
|
+
success,
|
|
131
|
+
error
|
|
132
|
+
})) };
|
|
133
|
+
}
|
|
134
|
+
case "ios": {
|
|
135
|
+
const w = require_platform_mock.getWindow();
|
|
136
|
+
return { postMessage: (name, params, success, error) => w.webkit.messageHandlers.wvbIos.postMessage({
|
|
137
|
+
name,
|
|
138
|
+
params,
|
|
139
|
+
success,
|
|
140
|
+
error
|
|
141
|
+
}) };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function toTauriCommand(name) {
|
|
146
|
+
return `plugin:wvb-tauri|${snakeCase(name)}`;
|
|
147
|
+
}
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region src/remote.ts
|
|
150
|
+
async function listBundles$1(channel) {
|
|
151
|
+
return invoke("remoteListBundles", { channel });
|
|
152
|
+
}
|
|
153
|
+
async function getInfo(bundleName, channel) {
|
|
154
|
+
return invoke("remoteGetInfo", {
|
|
155
|
+
bundleName,
|
|
156
|
+
channel
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
async function download$1(bundleName, channel) {
|
|
160
|
+
return invoke("remoteDownload", {
|
|
161
|
+
bundleName,
|
|
162
|
+
channel
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
async function downloadVersion(bundleName, version) {
|
|
166
|
+
return invoke("remoteDownloadVersion", {
|
|
167
|
+
bundleName,
|
|
168
|
+
version
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
const remote = {
|
|
172
|
+
listBundles: listBundles$1,
|
|
173
|
+
getInfo,
|
|
174
|
+
download: download$1,
|
|
175
|
+
downloadVersion
|
|
176
|
+
};
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/source.ts
|
|
179
|
+
async function listBundles() {
|
|
180
|
+
return invoke("sourceListBundles");
|
|
181
|
+
}
|
|
182
|
+
async function loadVersion(bundleName) {
|
|
183
|
+
return invoke("sourceLoadVersion", { bundleName });
|
|
184
|
+
}
|
|
185
|
+
async function updateVersion(bundleName, version) {
|
|
186
|
+
return invoke("sourceUpdateVersion", {
|
|
187
|
+
bundleName,
|
|
188
|
+
version
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
async function resolveFilepath(bundleName) {
|
|
192
|
+
return invoke("sourceResolveFilepath", { bundleName });
|
|
193
|
+
}
|
|
194
|
+
async function getBuiltinBundleFilepath(bundleName, version) {
|
|
195
|
+
return invoke("sourceGetBuiltinBundleFilepath", {
|
|
196
|
+
bundleName,
|
|
197
|
+
version
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
async function getRemoteBundleFilepath(bundleName, version) {
|
|
201
|
+
return invoke("sourceGetRemoteBundleFilepath", {
|
|
202
|
+
bundleName,
|
|
203
|
+
version
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
async function loadBuiltinMetadata(bundleName, version) {
|
|
207
|
+
return invoke("sourceLoadBuiltinMetadata", {
|
|
208
|
+
bundleName,
|
|
209
|
+
version
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
async function loadRemoteMetadata(bundleName, version) {
|
|
213
|
+
return invoke("sourceLoadRemoteMetadata", {
|
|
214
|
+
bundleName,
|
|
215
|
+
version
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
async function unloadDescriptor(bundleName) {
|
|
219
|
+
return invoke("sourceUnloadDescriptor", { bundleName });
|
|
220
|
+
}
|
|
221
|
+
async function removeRemoteBundle(bundleName, version) {
|
|
222
|
+
return invoke("sourceRemoveRemoteBundle", {
|
|
223
|
+
bundleName,
|
|
224
|
+
version
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
async function remoteRetainedVersions(bundleName) {
|
|
228
|
+
return invoke("sourceRemoteRetainedVersions", { bundleName });
|
|
229
|
+
}
|
|
230
|
+
async function pruneRemoteBundles(bundleName) {
|
|
231
|
+
return invoke("sourcePruneRemoteBundles", { bundleName });
|
|
232
|
+
}
|
|
233
|
+
const source = {
|
|
234
|
+
listBundles,
|
|
235
|
+
loadVersion,
|
|
236
|
+
updateVersion,
|
|
237
|
+
resolveFilepath,
|
|
238
|
+
getBuiltinBundleFilepath,
|
|
239
|
+
getRemoteBundleFilepath,
|
|
240
|
+
loadBuiltinMetadata,
|
|
241
|
+
loadRemoteMetadata,
|
|
242
|
+
unloadDescriptor,
|
|
243
|
+
removeRemoteBundle,
|
|
244
|
+
remoteRetainedVersions,
|
|
245
|
+
pruneRemoteBundles
|
|
246
|
+
};
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region src/updater.ts
|
|
249
|
+
async function listRemotes() {
|
|
250
|
+
return invoke("updaterListRemotes");
|
|
251
|
+
}
|
|
252
|
+
async function getUpdate(bundleName) {
|
|
253
|
+
return invoke("updaterGetUpdate", { bundleName });
|
|
254
|
+
}
|
|
255
|
+
async function download(bundleName, version) {
|
|
256
|
+
return invoke("updaterDownload", {
|
|
257
|
+
bundleName,
|
|
258
|
+
version
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
async function install(bundleName, version) {
|
|
262
|
+
return invoke("updaterInstall", {
|
|
263
|
+
bundleName,
|
|
264
|
+
version
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
const updater = {
|
|
268
|
+
listRemotes,
|
|
269
|
+
getUpdate,
|
|
270
|
+
download,
|
|
271
|
+
install
|
|
272
|
+
};
|
|
273
|
+
//#endregion
|
|
274
|
+
exports.invoke = invoke;
|
|
275
|
+
exports.platform = platform;
|
|
276
|
+
exports.remote = remote;
|
|
277
|
+
exports.source = source;
|
|
278
|
+
exports.updater = updater;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { _ as InvokeParams, a as BundleSourceType, c as ListBundleManifestItem, d as ListRemoteBundleInfo, f as RemoteApi, g as platform, h as PlatformType, i as BundleManifestMetadata, l as SourceApi, m as remote, n as UpdaterApi, o as BundleSourceVersion, p as RemoteBundleInfo, r as updater, s as ListBundleItem, t as BundleUpdateInfo, u as source, v as invoke } from "./index-B2ggQzrN.cjs";
|
|
2
|
+
export { type BundleManifestMetadata, type BundleSourceType, type BundleSourceVersion, type BundleUpdateInfo, type InvokeParams, type ListBundleItem, type ListBundleManifestItem, type ListRemoteBundleInfo, type PlatformType, type RemoteApi, type RemoteBundleInfo, type SourceApi, type UpdaterApi, invoke, platform, remote, source, updater };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { _ as InvokeParams, a as BundleSourceType, c as ListBundleManifestItem, d as ListRemoteBundleInfo, f as RemoteApi, g as platform, h as PlatformType, i as BundleManifestMetadata, l as SourceApi, m as remote, n as UpdaterApi, o as BundleSourceVersion, p as RemoteBundleInfo, r as updater, s as ListBundleItem, t as BundleUpdateInfo, u as source, v as invoke } from "./index-B2ggQzrN.js";
|
|
2
|
+
export { type BundleManifestMetadata, type BundleSourceType, type BundleSourceVersion, type BundleUpdateInfo, type InvokeParams, type ListBundleItem, type ListBundleManifestItem, type ListRemoteBundleInfo, type PlatformType, type RemoteApi, type RemoteBundleInfo, type SourceApi, type UpdaterApi, invoke, platform, remote, source, updater };
|