tauri-remote-ui 0.22.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/LICENSE +21 -0
- package/README.md +35 -0
- package/api/app/index.cjs +206 -0
- package/api/app/index.d.ts +168 -0
- package/api/app/index.js +193 -0
- package/api/core/index.cjs +65 -0
- package/api/core/index.d.ts +7 -0
- package/api/core/index.js +63 -0
- package/api/event/index.cjs +60 -0
- package/api/event/index.d.ts +15 -0
- package/api/event/index.js +58 -0
- package/index.cjs +11 -0
- package/index.d.ts +3 -0
- package/index.js +6 -0
- package/package.json +49 -0
- package/socket.cjs +72 -0
- package/socket.d.ts +17 -0
- package/socket.js +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 - DraviaVemal
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Tauri Remote UI
|
|
2
|
+
|
|
3
|
+
**Tauri Remote UI** is a plugin that allows you to expose your Tauri application's UI to any web browser, enabling seamless remote interaction and end-to-end testing. The plugin bridges your native app and commercial browsers, letting you use standard web automation tools for testing and debugging—without modifying your app's core logic.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Remote UI Exposure:** Interact with your Tauri app from any browser.
|
|
8
|
+
- **Seamless E2E Testing:** Use existing web automation/testing tools.
|
|
9
|
+
- **Automatic Transport Switching:** IPC for WebView, WebSocket for browsers—handled transparently.
|
|
10
|
+
- **Customizable Security:** Control and secure remote access as needed.
|
|
11
|
+
- **Zero App Changes:** No additional changes required to your app after plugin setup.
|
|
12
|
+
- **Future Compatibility:** When [CEF-RS](https://github.com/cef-rs/cef) becomes available, the same E2E tests (e.g., written with Playwright or similar tools that use the Chromium debug port) will work seamlessly in debug mode, ensuring long-term support for modern testing workflows.
|
|
13
|
+
|
|
14
|
+
## Operation Flow
|
|
15
|
+
|
|
16
|
+
- **WebView:** Uses IPC for communication between frontend and backend.
|
|
17
|
+
- **Commercial Browser:** Uses WebSocket (WS) for remote frontend-backend communication.
|
|
18
|
+
- **Automatic Switching:** The Rust backend plugin and npm frontend wrapper handle transport selection automatically.
|
|
19
|
+
- **Security:** The exposure of the web app can be secured and customized by the end user.
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
1. **Install the Rust plugin** in your Tauri project.
|
|
24
|
+
2. **Install the NPM plugin** in your frontend.
|
|
25
|
+
3. **Access the UI remotely** via the provided web interface when activated.
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
- Build Rust: `cargo build`
|
|
30
|
+
- Build JS: `pnpm build` (from the root)
|
|
31
|
+
- Example app: See `examples/tauri-app/`
|
|
32
|
+
|
|
33
|
+
## License
|
|
34
|
+
|
|
35
|
+
MIT
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var index = require('../core/index.cjs');
|
|
4
|
+
var image = require('@tauri-apps/api/image');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Application metadata and related APIs.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Gets the application version.
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { getVersion } from '@tauri-apps/api/app';
|
|
16
|
+
* const appVersion = await getVersion();
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @since 1.0.0
|
|
20
|
+
*/
|
|
21
|
+
async function getVersion() {
|
|
22
|
+
return index.invoke('plugin:app|version');
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Gets the application name.
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { getName } from '@tauri-apps/api/app';
|
|
29
|
+
* const appName = await getName();
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @since 1.0.0
|
|
33
|
+
*/
|
|
34
|
+
async function getName() {
|
|
35
|
+
return index.invoke('plugin:app|name');
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Gets the Tauri framework version used by this application.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* import { getTauriVersion } from '@tauri-apps/api/app';
|
|
43
|
+
* const tauriVersion = await getTauriVersion();
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @since 1.0.0
|
|
47
|
+
*/
|
|
48
|
+
async function getTauriVersion() {
|
|
49
|
+
return index.invoke('plugin:app|tauri_version');
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Gets the application identifier.
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* import { getIdentifier } from '@tauri-apps/api/app';
|
|
56
|
+
* const identifier = await getIdentifier();
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @returns The application identifier as configured in `tauri.conf.json`.
|
|
60
|
+
*
|
|
61
|
+
* @since 2.4.0
|
|
62
|
+
*/
|
|
63
|
+
async function getIdentifier() {
|
|
64
|
+
return index.invoke('plugin:app|identifier');
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Shows the application on macOS. This function does not automatically
|
|
68
|
+
* focus any specific app window.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* import { show } from '@tauri-apps/api/app';
|
|
73
|
+
* await show();
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @since 1.2.0
|
|
77
|
+
*/
|
|
78
|
+
async function show() {
|
|
79
|
+
return index.invoke('plugin:app|app_show');
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Hides the application on macOS.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* import { hide } from '@tauri-apps/api/app';
|
|
87
|
+
* await hide();
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @since 1.2.0
|
|
91
|
+
*/
|
|
92
|
+
async function hide() {
|
|
93
|
+
return index.invoke('plugin:app|app_hide');
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Fetches the data store identifiers on macOS and iOS.
|
|
97
|
+
*
|
|
98
|
+
* See https://developer.apple.com/documentation/webkit/wkwebsitedatastore for more information.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* import { fetchDataStoreIdentifiers } from '@tauri-apps/api/app';
|
|
103
|
+
* const ids = await fetchDataStoreIdentifiers();
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @since 2.4.0
|
|
107
|
+
*/
|
|
108
|
+
async function fetchDataStoreIdentifiers() {
|
|
109
|
+
return index.invoke('plugin:app|fetch_data_store_identifiers');
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Removes the data store with the given identifier.
|
|
113
|
+
*
|
|
114
|
+
* Note that any webview using this data store should be closed before running this API.
|
|
115
|
+
*
|
|
116
|
+
* See https://developer.apple.com/documentation/webkit/wkwebsitedatastore for more information.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* import { fetchDataStoreIdentifiers, removeDataStore } from '@tauri-apps/api/app';
|
|
121
|
+
* for (const id of (await fetchDataStoreIdentifiers())) {
|
|
122
|
+
* await removeDataStore(id);
|
|
123
|
+
* }
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @since 2.4.0
|
|
127
|
+
*/
|
|
128
|
+
async function removeDataStore(uuid) {
|
|
129
|
+
return index.invoke('plugin:app|remove_data_store', { uuid });
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Gets the default window icon.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* import { defaultWindowIcon } from '@tauri-apps/api/app';
|
|
137
|
+
* const icon = await defaultWindowIcon();
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @since 2.0.0
|
|
141
|
+
*/
|
|
142
|
+
async function defaultWindowIcon() {
|
|
143
|
+
return index.invoke('plugin:app|default_window_icon').then((rid) => rid ? new image.Image(rid) : null);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Sets the application's theme. Pass in `null` or `undefined` to follow
|
|
147
|
+
* the system theme.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* import { setTheme } from '@tauri-apps/api/app';
|
|
152
|
+
* await setTheme('dark');
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* #### Platform-specific
|
|
156
|
+
*
|
|
157
|
+
* - **iOS / Android:** Unsupported.
|
|
158
|
+
*
|
|
159
|
+
* @since 2.0.0
|
|
160
|
+
*/
|
|
161
|
+
async function setTheme(theme) {
|
|
162
|
+
return index.invoke('plugin:app|set_app_theme', { theme });
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Sets the dock visibility for the application on macOS.
|
|
166
|
+
*
|
|
167
|
+
* @param visible - Whether the dock should be visible or not.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* import { setDockVisibility } from '@tauri-apps/api/app';
|
|
172
|
+
* await setDockVisibility(false);
|
|
173
|
+
* ```
|
|
174
|
+
*
|
|
175
|
+
* @since 2.5.0
|
|
176
|
+
*/
|
|
177
|
+
async function setDockVisibility(visible) {
|
|
178
|
+
return index.invoke('plugin:app|set_dock_visibility', { visible });
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Gets the application bundle type.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* import { getBundleType } from '@tauri-apps/api/app';
|
|
186
|
+
* const type = await getBundleType();
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* @since 2.5.0
|
|
190
|
+
*/
|
|
191
|
+
async function getBundleType() {
|
|
192
|
+
return index.invoke('plugin:app|bundle_type');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
exports.defaultWindowIcon = defaultWindowIcon;
|
|
196
|
+
exports.fetchDataStoreIdentifiers = fetchDataStoreIdentifiers;
|
|
197
|
+
exports.getBundleType = getBundleType;
|
|
198
|
+
exports.getIdentifier = getIdentifier;
|
|
199
|
+
exports.getName = getName;
|
|
200
|
+
exports.getTauriVersion = getTauriVersion;
|
|
201
|
+
exports.getVersion = getVersion;
|
|
202
|
+
exports.hide = hide;
|
|
203
|
+
exports.removeDataStore = removeDataStore;
|
|
204
|
+
exports.setDockVisibility = setDockVisibility;
|
|
205
|
+
exports.setTheme = setTheme;
|
|
206
|
+
exports.show = show;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { BundleType, DataStoreIdentifier } from "@tauri-apps/api/app";
|
|
2
|
+
import { Image } from "@tauri-apps/api/image";
|
|
3
|
+
import { Theme } from "@tauri-apps/api/window";
|
|
4
|
+
/**
|
|
5
|
+
* Application metadata and related APIs.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Gets the application version.
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { getVersion } from '@tauri-apps/api/app';
|
|
14
|
+
* const appVersion = await getVersion();
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @since 1.0.0
|
|
18
|
+
*/
|
|
19
|
+
declare function getVersion(): Promise<string>;
|
|
20
|
+
/**
|
|
21
|
+
* Gets the application name.
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { getName } from '@tauri-apps/api/app';
|
|
25
|
+
* const appName = await getName();
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @since 1.0.0
|
|
29
|
+
*/
|
|
30
|
+
declare function getName(): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Gets the Tauri framework version used by this application.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { getTauriVersion } from '@tauri-apps/api/app';
|
|
37
|
+
* const tauriVersion = await getTauriVersion();
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @since 1.0.0
|
|
41
|
+
*/
|
|
42
|
+
declare function getTauriVersion(): Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Gets the application identifier.
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { getIdentifier } from '@tauri-apps/api/app';
|
|
48
|
+
* const identifier = await getIdentifier();
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @returns The application identifier as configured in `tauri.conf.json`.
|
|
52
|
+
*
|
|
53
|
+
* @since 2.4.0
|
|
54
|
+
*/
|
|
55
|
+
declare function getIdentifier(): Promise<string>;
|
|
56
|
+
/**
|
|
57
|
+
* Shows the application on macOS. This function does not automatically
|
|
58
|
+
* focus any specific app window.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* import { show } from '@tauri-apps/api/app';
|
|
63
|
+
* await show();
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @since 1.2.0
|
|
67
|
+
*/
|
|
68
|
+
declare function show(): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Hides the application on macOS.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* import { hide } from '@tauri-apps/api/app';
|
|
75
|
+
* await hide();
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @since 1.2.0
|
|
79
|
+
*/
|
|
80
|
+
declare function hide(): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Fetches the data store identifiers on macOS and iOS.
|
|
83
|
+
*
|
|
84
|
+
* See https://developer.apple.com/documentation/webkit/wkwebsitedatastore for more information.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* import { fetchDataStoreIdentifiers } from '@tauri-apps/api/app';
|
|
89
|
+
* const ids = await fetchDataStoreIdentifiers();
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @since 2.4.0
|
|
93
|
+
*/
|
|
94
|
+
declare function fetchDataStoreIdentifiers(): Promise<DataStoreIdentifier[]>;
|
|
95
|
+
/**
|
|
96
|
+
* Removes the data store with the given identifier.
|
|
97
|
+
*
|
|
98
|
+
* Note that any webview using this data store should be closed before running this API.
|
|
99
|
+
*
|
|
100
|
+
* See https://developer.apple.com/documentation/webkit/wkwebsitedatastore for more information.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* import { fetchDataStoreIdentifiers, removeDataStore } from '@tauri-apps/api/app';
|
|
105
|
+
* for (const id of (await fetchDataStoreIdentifiers())) {
|
|
106
|
+
* await removeDataStore(id);
|
|
107
|
+
* }
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @since 2.4.0
|
|
111
|
+
*/
|
|
112
|
+
declare function removeDataStore(uuid: DataStoreIdentifier): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Gets the default window icon.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* import { defaultWindowIcon } from '@tauri-apps/api/app';
|
|
119
|
+
* const icon = await defaultWindowIcon();
|
|
120
|
+
* ```
|
|
121
|
+
*
|
|
122
|
+
* @since 2.0.0
|
|
123
|
+
*/
|
|
124
|
+
declare function defaultWindowIcon(): Promise<Image | null>;
|
|
125
|
+
/**
|
|
126
|
+
* Sets the application's theme. Pass in `null` or `undefined` to follow
|
|
127
|
+
* the system theme.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* import { setTheme } from '@tauri-apps/api/app';
|
|
132
|
+
* await setTheme('dark');
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
135
|
+
* #### Platform-specific
|
|
136
|
+
*
|
|
137
|
+
* - **iOS / Android:** Unsupported.
|
|
138
|
+
*
|
|
139
|
+
* @since 2.0.0
|
|
140
|
+
*/
|
|
141
|
+
declare function setTheme(theme?: Theme | null): Promise<void>;
|
|
142
|
+
/**
|
|
143
|
+
* Sets the dock visibility for the application on macOS.
|
|
144
|
+
*
|
|
145
|
+
* @param visible - Whether the dock should be visible or not.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* import { setDockVisibility } from '@tauri-apps/api/app';
|
|
150
|
+
* await setDockVisibility(false);
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
* @since 2.5.0
|
|
154
|
+
*/
|
|
155
|
+
declare function setDockVisibility(visible: boolean): Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Gets the application bundle type.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* import { getBundleType } from '@tauri-apps/api/app';
|
|
162
|
+
* const type = await getBundleType();
|
|
163
|
+
* ```
|
|
164
|
+
*
|
|
165
|
+
* @since 2.5.0
|
|
166
|
+
*/
|
|
167
|
+
declare function getBundleType(): Promise<BundleType>;
|
|
168
|
+
export { getName, getVersion, getTauriVersion, getIdentifier, show, hide, defaultWindowIcon, setTheme, fetchDataStoreIdentifiers, removeDataStore, setDockVisibility, getBundleType };
|
package/api/app/index.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { invoke } from '../core/index.js';
|
|
2
|
+
import { Image } from '@tauri-apps/api/image';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Application metadata and related APIs.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Gets the application version.
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { getVersion } from '@tauri-apps/api/app';
|
|
14
|
+
* const appVersion = await getVersion();
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @since 1.0.0
|
|
18
|
+
*/
|
|
19
|
+
async function getVersion() {
|
|
20
|
+
return invoke('plugin:app|version');
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Gets the application name.
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { getName } from '@tauri-apps/api/app';
|
|
27
|
+
* const appName = await getName();
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @since 1.0.0
|
|
31
|
+
*/
|
|
32
|
+
async function getName() {
|
|
33
|
+
return invoke('plugin:app|name');
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Gets the Tauri framework version used by this application.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* import { getTauriVersion } from '@tauri-apps/api/app';
|
|
41
|
+
* const tauriVersion = await getTauriVersion();
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @since 1.0.0
|
|
45
|
+
*/
|
|
46
|
+
async function getTauriVersion() {
|
|
47
|
+
return invoke('plugin:app|tauri_version');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Gets the application identifier.
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* import { getIdentifier } from '@tauri-apps/api/app';
|
|
54
|
+
* const identifier = await getIdentifier();
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @returns The application identifier as configured in `tauri.conf.json`.
|
|
58
|
+
*
|
|
59
|
+
* @since 2.4.0
|
|
60
|
+
*/
|
|
61
|
+
async function getIdentifier() {
|
|
62
|
+
return invoke('plugin:app|identifier');
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Shows the application on macOS. This function does not automatically
|
|
66
|
+
* focus any specific app window.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* import { show } from '@tauri-apps/api/app';
|
|
71
|
+
* await show();
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @since 1.2.0
|
|
75
|
+
*/
|
|
76
|
+
async function show() {
|
|
77
|
+
return invoke('plugin:app|app_show');
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Hides the application on macOS.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* import { hide } from '@tauri-apps/api/app';
|
|
85
|
+
* await hide();
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @since 1.2.0
|
|
89
|
+
*/
|
|
90
|
+
async function hide() {
|
|
91
|
+
return invoke('plugin:app|app_hide');
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Fetches the data store identifiers on macOS and iOS.
|
|
95
|
+
*
|
|
96
|
+
* See https://developer.apple.com/documentation/webkit/wkwebsitedatastore for more information.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* import { fetchDataStoreIdentifiers } from '@tauri-apps/api/app';
|
|
101
|
+
* const ids = await fetchDataStoreIdentifiers();
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @since 2.4.0
|
|
105
|
+
*/
|
|
106
|
+
async function fetchDataStoreIdentifiers() {
|
|
107
|
+
return invoke('plugin:app|fetch_data_store_identifiers');
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Removes the data store with the given identifier.
|
|
111
|
+
*
|
|
112
|
+
* Note that any webview using this data store should be closed before running this API.
|
|
113
|
+
*
|
|
114
|
+
* See https://developer.apple.com/documentation/webkit/wkwebsitedatastore for more information.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* import { fetchDataStoreIdentifiers, removeDataStore } from '@tauri-apps/api/app';
|
|
119
|
+
* for (const id of (await fetchDataStoreIdentifiers())) {
|
|
120
|
+
* await removeDataStore(id);
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @since 2.4.0
|
|
125
|
+
*/
|
|
126
|
+
async function removeDataStore(uuid) {
|
|
127
|
+
return invoke('plugin:app|remove_data_store', { uuid });
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Gets the default window icon.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* import { defaultWindowIcon } from '@tauri-apps/api/app';
|
|
135
|
+
* const icon = await defaultWindowIcon();
|
|
136
|
+
* ```
|
|
137
|
+
*
|
|
138
|
+
* @since 2.0.0
|
|
139
|
+
*/
|
|
140
|
+
async function defaultWindowIcon() {
|
|
141
|
+
return invoke('plugin:app|default_window_icon').then((rid) => rid ? new Image(rid) : null);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Sets the application's theme. Pass in `null` or `undefined` to follow
|
|
145
|
+
* the system theme.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* import { setTheme } from '@tauri-apps/api/app';
|
|
150
|
+
* await setTheme('dark');
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
* #### Platform-specific
|
|
154
|
+
*
|
|
155
|
+
* - **iOS / Android:** Unsupported.
|
|
156
|
+
*
|
|
157
|
+
* @since 2.0.0
|
|
158
|
+
*/
|
|
159
|
+
async function setTheme(theme) {
|
|
160
|
+
return invoke('plugin:app|set_app_theme', { theme });
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Sets the dock visibility for the application on macOS.
|
|
164
|
+
*
|
|
165
|
+
* @param visible - Whether the dock should be visible or not.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* import { setDockVisibility } from '@tauri-apps/api/app';
|
|
170
|
+
* await setDockVisibility(false);
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* @since 2.5.0
|
|
174
|
+
*/
|
|
175
|
+
async function setDockVisibility(visible) {
|
|
176
|
+
return invoke('plugin:app|set_dock_visibility', { visible });
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Gets the application bundle type.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* import { getBundleType } from '@tauri-apps/api/app';
|
|
184
|
+
* const type = await getBundleType();
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* @since 2.5.0
|
|
188
|
+
*/
|
|
189
|
+
async function getBundleType() {
|
|
190
|
+
return invoke('plugin:app|bundle_type');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export { defaultWindowIcon, fetchDataStoreIdentifiers, getBundleType, getIdentifier, getName, getTauriVersion, getVersion, hide, removeDataStore, setDockVisibility, setTheme, show };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@tauri-apps/api/core');
|
|
4
|
+
var socket = require('../../socket.cjs');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Core API module for Tauri Remote UI
|
|
8
|
+
*
|
|
9
|
+
* This module handles sending messages to the Tauri application via WebSocket
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Invoke a command on the Tauri application
|
|
13
|
+
* Falls back to WebSocket if Tauri IPC is not available
|
|
14
|
+
*
|
|
15
|
+
* @param cmd - The command name to invoke
|
|
16
|
+
* @param args - Arguments to pass to the command
|
|
17
|
+
* @param options - Options for the command
|
|
18
|
+
*/
|
|
19
|
+
let msg_id = 0;
|
|
20
|
+
async function invoke(cmd, args, options) {
|
|
21
|
+
socket.initWebSocket();
|
|
22
|
+
// Tauri IPC
|
|
23
|
+
try {
|
|
24
|
+
if ((window.__TAURI_INTERNALS__ && window.__TAURI_INTERNALS__.invoke) ||
|
|
25
|
+
window.__TAURI__ && window.__TAURI__.invoke) {
|
|
26
|
+
return await core.invoke(cmd, args, options);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
throw new Error("Failed to Find Tauri handle");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
// If WebSocket is connecting, wait for it
|
|
34
|
+
if (socket.wsReady) {
|
|
35
|
+
await socket.wsReady;
|
|
36
|
+
}
|
|
37
|
+
if (socket.ws && socket.ws.readyState === WebSocket.OPEN) {
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
const msg = {
|
|
40
|
+
id: ++msg_id,
|
|
41
|
+
cmd, args, options
|
|
42
|
+
};
|
|
43
|
+
let clear = setTimeout(() => {
|
|
44
|
+
delete socket.filterCollection[msg_id];
|
|
45
|
+
reject(`Invoke Timeout. cmd : ${cmd}`);
|
|
46
|
+
}, 30000);
|
|
47
|
+
socket.filterCollection[msg_id] = ({ status, payload }) => {
|
|
48
|
+
clearTimeout(clear);
|
|
49
|
+
if (status = "success") {
|
|
50
|
+
resolve(payload);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
reject(payload);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
socket.ws.send(JSON.stringify(msg));
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
throw new Error('No WebSocket or Tauri IPC available to invoke');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
exports.invoke = invoke;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core API module for Tauri Remote UI
|
|
3
|
+
*
|
|
4
|
+
* This module handles sending messages to the Tauri application via WebSocket
|
|
5
|
+
*/
|
|
6
|
+
import { InvokeArgs, InvokeOptions } from '@tauri-apps/api/core';
|
|
7
|
+
export declare function invoke<T>(cmd: string, args?: InvokeArgs, options?: InvokeOptions): Promise<T>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { invoke as invoke$1 } from '@tauri-apps/api/core';
|
|
2
|
+
import { initWebSocket, wsReady, ws, filterCollection } from '../../socket.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Core API module for Tauri Remote UI
|
|
6
|
+
*
|
|
7
|
+
* This module handles sending messages to the Tauri application via WebSocket
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Invoke a command on the Tauri application
|
|
11
|
+
* Falls back to WebSocket if Tauri IPC is not available
|
|
12
|
+
*
|
|
13
|
+
* @param cmd - The command name to invoke
|
|
14
|
+
* @param args - Arguments to pass to the command
|
|
15
|
+
* @param options - Options for the command
|
|
16
|
+
*/
|
|
17
|
+
let msg_id = 0;
|
|
18
|
+
async function invoke(cmd, args, options) {
|
|
19
|
+
initWebSocket();
|
|
20
|
+
// Tauri IPC
|
|
21
|
+
try {
|
|
22
|
+
if ((window.__TAURI_INTERNALS__ && window.__TAURI_INTERNALS__.invoke) ||
|
|
23
|
+
window.__TAURI__ && window.__TAURI__.invoke) {
|
|
24
|
+
return await invoke$1(cmd, args, options);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
throw new Error("Failed to Find Tauri handle");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
// If WebSocket is connecting, wait for it
|
|
32
|
+
if (wsReady) {
|
|
33
|
+
await wsReady;
|
|
34
|
+
}
|
|
35
|
+
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
const msg = {
|
|
38
|
+
id: ++msg_id,
|
|
39
|
+
cmd, args, options
|
|
40
|
+
};
|
|
41
|
+
let clear = setTimeout(() => {
|
|
42
|
+
delete filterCollection[msg_id];
|
|
43
|
+
reject(`Invoke Timeout. cmd : ${cmd}`);
|
|
44
|
+
}, 30000);
|
|
45
|
+
filterCollection[msg_id] = ({ status, payload }) => {
|
|
46
|
+
clearTimeout(clear);
|
|
47
|
+
if (status = "success") {
|
|
48
|
+
resolve(payload);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
reject(payload);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
ws.send(JSON.stringify(msg));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
throw new Error('No WebSocket or Tauri IPC available to invoke');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { invoke };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var event = require('@tauri-apps/api/event');
|
|
4
|
+
var socket = require('../../socket.cjs');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Event API module for Tauri Remote UI
|
|
8
|
+
*
|
|
9
|
+
* This module handles listening to events from the Tauri application via WebSocket
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Listen to events from the Tauri application
|
|
13
|
+
* Falls back to WebSocket if Tauri Event API is not available
|
|
14
|
+
*
|
|
15
|
+
* @param event - The event name to listen for
|
|
16
|
+
* @param handler - Callback to handle the event
|
|
17
|
+
* @param options - Options for the event listener
|
|
18
|
+
*/
|
|
19
|
+
async function listen(event$1, handler, options) {
|
|
20
|
+
socket.initWebSocket();
|
|
21
|
+
try {
|
|
22
|
+
if ((window.__TAURI_INTERNALS__ && window.__TAURI_INTERNALS__.invoke) ||
|
|
23
|
+
window.__TAURI__ && window.__TAURI__.invoke) {
|
|
24
|
+
return await event.listen(event$1, handler, options);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
throw new Error("Failed to Find Tauri handle");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
// If WebSocket is connecting, wait for it
|
|
32
|
+
if (socket.wsReady) {
|
|
33
|
+
await socket.wsReady;
|
|
34
|
+
}
|
|
35
|
+
if (socket.ws && socket.ws.readyState === WebSocket.OPEN) {
|
|
36
|
+
// Handle WebSocket messages for events
|
|
37
|
+
const messageHandler = (wsEvent) => {
|
|
38
|
+
try {
|
|
39
|
+
const data = JSON.parse(wsEvent.data);
|
|
40
|
+
if (data.event === event$1) {
|
|
41
|
+
handler(data);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
console.error('Error handling WebSocket event', err);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
socket.ws.addEventListener('message', messageHandler);
|
|
49
|
+
// Return an unlisten function
|
|
50
|
+
return () => {
|
|
51
|
+
socket.ws === null || socket.ws === void 0 ? void 0 : socket.ws.removeEventListener('message', messageHandler);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
throw new Error('No WebSocket or Tauri IPC available to invoke');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
exports.listen = listen;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event API module for Tauri Remote UI
|
|
3
|
+
*
|
|
4
|
+
* This module handles listening to events from the Tauri application via WebSocket
|
|
5
|
+
*/
|
|
6
|
+
import { EventCallback, EventName, Options, UnlistenFn } from '@tauri-apps/api/event';
|
|
7
|
+
/**
|
|
8
|
+
* Listen to events from the Tauri application
|
|
9
|
+
* Falls back to WebSocket if Tauri Event API is not available
|
|
10
|
+
*
|
|
11
|
+
* @param event - The event name to listen for
|
|
12
|
+
* @param handler - Callback to handle the event
|
|
13
|
+
* @param options - Options for the event listener
|
|
14
|
+
*/
|
|
15
|
+
export declare function listen<T>(event: EventName, handler: EventCallback<T>, options?: Options): Promise<UnlistenFn>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { listen as listen$1 } from '@tauri-apps/api/event';
|
|
2
|
+
import { initWebSocket, wsReady, ws } from '../../socket.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Event API module for Tauri Remote UI
|
|
6
|
+
*
|
|
7
|
+
* This module handles listening to events from the Tauri application via WebSocket
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Listen to events from the Tauri application
|
|
11
|
+
* Falls back to WebSocket if Tauri Event API is not available
|
|
12
|
+
*
|
|
13
|
+
* @param event - The event name to listen for
|
|
14
|
+
* @param handler - Callback to handle the event
|
|
15
|
+
* @param options - Options for the event listener
|
|
16
|
+
*/
|
|
17
|
+
async function listen(event, handler, options) {
|
|
18
|
+
initWebSocket();
|
|
19
|
+
try {
|
|
20
|
+
if ((window.__TAURI_INTERNALS__ && window.__TAURI_INTERNALS__.invoke) ||
|
|
21
|
+
window.__TAURI__ && window.__TAURI__.invoke) {
|
|
22
|
+
return await listen$1(event, handler, options);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
throw new Error("Failed to Find Tauri handle");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
// If WebSocket is connecting, wait for it
|
|
30
|
+
if (wsReady) {
|
|
31
|
+
await wsReady;
|
|
32
|
+
}
|
|
33
|
+
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
34
|
+
// Handle WebSocket messages for events
|
|
35
|
+
const messageHandler = (wsEvent) => {
|
|
36
|
+
try {
|
|
37
|
+
const data = JSON.parse(wsEvent.data);
|
|
38
|
+
if (data.event === event) {
|
|
39
|
+
handler(data);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
console.error('Error handling WebSocket event', err);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
ws.addEventListener('message', messageHandler);
|
|
47
|
+
// Return an unlisten function
|
|
48
|
+
return () => {
|
|
49
|
+
ws === null || ws === void 0 ? void 0 : ws.removeEventListener('message', messageHandler);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
throw new Error('No WebSocket or Tauri IPC available to invoke');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { listen };
|
package/index.cjs
ADDED
package/index.d.ts
ADDED
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tauri-remote-ui",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"version": "0.22.0",
|
|
5
|
+
"author": "DraviaVemal",
|
|
6
|
+
"description": "A Tauri plugin that exposes the application's UI to a web browser, allowing full interaction while the native app continues running. This enables end-to-end UI testing using existing web-based testing tools without requiring modifications to the app itself.",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"main": "./index.cjs",
|
|
10
|
+
"module": "./index.js",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./index.d.ts",
|
|
14
|
+
"import": "./index.js",
|
|
15
|
+
"require": "./index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"./api/app": {
|
|
18
|
+
"types": "./api/app/index.d.ts",
|
|
19
|
+
"import": "./api/app/index.js",
|
|
20
|
+
"require": "./api/app/index.cjs"
|
|
21
|
+
},
|
|
22
|
+
"./api/core": {
|
|
23
|
+
"types": "./api/core/index.d.ts",
|
|
24
|
+
"import": "./api/core/index.js",
|
|
25
|
+
"require": "./api/core/index.cjs"
|
|
26
|
+
},
|
|
27
|
+
"./api/event": {
|
|
28
|
+
"types": "./api/event/index.d.ts",
|
|
29
|
+
"import": "./api/event/index.js",
|
|
30
|
+
"require": "./api/event/index.cjs"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"typesVersions": {
|
|
34
|
+
"*": {
|
|
35
|
+
"api/app/*": [
|
|
36
|
+
"./api/app/*.d.ts"
|
|
37
|
+
],
|
|
38
|
+
"api/core/*": [
|
|
39
|
+
"./api/core/*.d.ts"
|
|
40
|
+
],
|
|
41
|
+
"api/event/*": [
|
|
42
|
+
"./api/event/*.d.ts"
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@tauri-apps/api": ">=2.0.0"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/socket.cjs
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Tauri Remote UI - API
|
|
5
|
+
*
|
|
6
|
+
* This TypeScript file serves as the main entry point for the tauri-remote-ui package.
|
|
7
|
+
* It provides WebSocket initialization and shared WebSocket state for communicating
|
|
8
|
+
* with a Tauri application.
|
|
9
|
+
*/
|
|
10
|
+
exports.ws = null;
|
|
11
|
+
exports.wsReady = null;
|
|
12
|
+
const filterCollection = {};
|
|
13
|
+
/**
|
|
14
|
+
* Get the WebSocket URL based on the current window location
|
|
15
|
+
*/
|
|
16
|
+
function getWsUrl() {
|
|
17
|
+
const loc = window.location;
|
|
18
|
+
const proto = loc.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
19
|
+
const wsUrl = `${proto}//${loc.host}/remote_ui_ws`;
|
|
20
|
+
return wsUrl;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Initialize the WebSocket connection
|
|
24
|
+
* This should be called once at the start of your application
|
|
25
|
+
*/
|
|
26
|
+
function initWebSocket() {
|
|
27
|
+
try {
|
|
28
|
+
// If we're in a Tauri app, don't use WebSocket
|
|
29
|
+
if ((window.__TAURI_INTERNALS__ && window.__TAURI_INTERNALS__.invoke) ||
|
|
30
|
+
window.__TAURI__ && window.__TAURI__.invoke) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
throw new Error("Moving to WS backup for Tauri Backend");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
if (exports.ws)
|
|
39
|
+
return;
|
|
40
|
+
console.info("Remote RPC Attempting...");
|
|
41
|
+
const wsUrl = getWsUrl();
|
|
42
|
+
try {
|
|
43
|
+
exports.ws = new WebSocket(wsUrl);
|
|
44
|
+
exports.wsReady = new Promise((resolve, reject) => {
|
|
45
|
+
exports.ws.onopen = () => {
|
|
46
|
+
console.info("Remote Connected.");
|
|
47
|
+
resolve();
|
|
48
|
+
};
|
|
49
|
+
exports.ws.onclose = () => {
|
|
50
|
+
exports.ws = null;
|
|
51
|
+
exports.wsReady = null;
|
|
52
|
+
console.info("Remote Dis-Connected.");
|
|
53
|
+
};
|
|
54
|
+
exports.ws.onerror = (e) => {
|
|
55
|
+
reject(e);
|
|
56
|
+
};
|
|
57
|
+
exports.ws.onmessage = ({ data }) => {
|
|
58
|
+
let json_data = JSON.parse(data);
|
|
59
|
+
json_data.id && filterCollection[json_data.id] && filterCollection[json_data.id](JSON.parse(json_data.payload));
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
setTimeout(() => {
|
|
65
|
+
initWebSocket();
|
|
66
|
+
}, 5000);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
exports.filterCollection = filterCollection;
|
|
72
|
+
exports.initWebSocket = initWebSocket;
|
package/socket.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tauri Remote UI - API
|
|
3
|
+
*
|
|
4
|
+
* This TypeScript file serves as the main entry point for the tauri-remote-ui package.
|
|
5
|
+
* It provides WebSocket initialization and shared WebSocket state for communicating
|
|
6
|
+
* with a Tauri application.
|
|
7
|
+
*/
|
|
8
|
+
export declare let ws: WebSocket | null;
|
|
9
|
+
export declare let wsReady: Promise<void> | null;
|
|
10
|
+
export declare const filterCollection: {
|
|
11
|
+
[msg_id: string]: (response: any) => any;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Initialize the WebSocket connection
|
|
15
|
+
* This should be called once at the start of your application
|
|
16
|
+
*/
|
|
17
|
+
export declare function initWebSocket(): void;
|
package/socket.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tauri Remote UI - API
|
|
3
|
+
*
|
|
4
|
+
* This TypeScript file serves as the main entry point for the tauri-remote-ui package.
|
|
5
|
+
* It provides WebSocket initialization and shared WebSocket state for communicating
|
|
6
|
+
* with a Tauri application.
|
|
7
|
+
*/
|
|
8
|
+
let ws = null;
|
|
9
|
+
let wsReady = null;
|
|
10
|
+
const filterCollection = {};
|
|
11
|
+
/**
|
|
12
|
+
* Get the WebSocket URL based on the current window location
|
|
13
|
+
*/
|
|
14
|
+
function getWsUrl() {
|
|
15
|
+
const loc = window.location;
|
|
16
|
+
const proto = loc.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
17
|
+
const wsUrl = `${proto}//${loc.host}/remote_ui_ws`;
|
|
18
|
+
return wsUrl;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Initialize the WebSocket connection
|
|
22
|
+
* This should be called once at the start of your application
|
|
23
|
+
*/
|
|
24
|
+
function initWebSocket() {
|
|
25
|
+
try {
|
|
26
|
+
// If we're in a Tauri app, don't use WebSocket
|
|
27
|
+
if ((window.__TAURI_INTERNALS__ && window.__TAURI_INTERNALS__.invoke) ||
|
|
28
|
+
window.__TAURI__ && window.__TAURI__.invoke) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
throw new Error("Moving to WS backup for Tauri Backend");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
if (ws)
|
|
37
|
+
return;
|
|
38
|
+
console.info("Remote RPC Attempting...");
|
|
39
|
+
const wsUrl = getWsUrl();
|
|
40
|
+
try {
|
|
41
|
+
ws = new WebSocket(wsUrl);
|
|
42
|
+
wsReady = new Promise((resolve, reject) => {
|
|
43
|
+
ws.onopen = () => {
|
|
44
|
+
console.info("Remote Connected.");
|
|
45
|
+
resolve();
|
|
46
|
+
};
|
|
47
|
+
ws.onclose = () => {
|
|
48
|
+
ws = null;
|
|
49
|
+
wsReady = null;
|
|
50
|
+
console.info("Remote Dis-Connected.");
|
|
51
|
+
};
|
|
52
|
+
ws.onerror = (e) => {
|
|
53
|
+
reject(e);
|
|
54
|
+
};
|
|
55
|
+
ws.onmessage = ({ data }) => {
|
|
56
|
+
let json_data = JSON.parse(data);
|
|
57
|
+
json_data.id && filterCollection[json_data.id] && filterCollection[json_data.id](JSON.parse(json_data.payload));
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
initWebSocket();
|
|
64
|
+
}, 5000);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { filterCollection, initWebSocket, ws, wsReady };
|