tauri-plugin-background-service 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-js/index.cjs +35 -0
- package/dist-js/index.cjs.map +1 -0
- package/dist-js/index.d.ts +36 -0
- package/dist-js/index.d.ts.map +1 -0
- package/dist-js/index.js +30 -0
- package/dist-js/index.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@tauri-apps/api/core');
|
|
4
|
+
var event = require('@tauri-apps/api/event');
|
|
5
|
+
|
|
6
|
+
// guest-js/index.ts
|
|
7
|
+
/**
|
|
8
|
+
* Start the background service.
|
|
9
|
+
* The service struct is already registered in main.rs — this just starts it.
|
|
10
|
+
*/
|
|
11
|
+
async function startService(config = {}) {
|
|
12
|
+
await core.invoke('plugin:background-service|start', { config });
|
|
13
|
+
}
|
|
14
|
+
/** Stop the service and cancel the shutdown token. */
|
|
15
|
+
async function stopService() {
|
|
16
|
+
await core.invoke('plugin:background-service|stop');
|
|
17
|
+
}
|
|
18
|
+
/** Returns true if the Rust service is currently running. */
|
|
19
|
+
async function isServiceRunning() {
|
|
20
|
+
return core.invoke('plugin:background-service|is_running');
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Listen to built-in plugin lifecycle events.
|
|
24
|
+
* Your service can emit its own custom events via ctx.app.emit() —
|
|
25
|
+
* subscribe to those separately with tauri's `listen()`.
|
|
26
|
+
*/
|
|
27
|
+
async function onPluginEvent(handler) {
|
|
28
|
+
return event.listen('background-service://event', e => handler(e.payload));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
exports.isServiceRunning = isServiceRunning;
|
|
32
|
+
exports.onPluginEvent = onPluginEvent;
|
|
33
|
+
exports.startService = startService;
|
|
34
|
+
exports.stopService = stopService;
|
|
35
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../index.ts"],"sourcesContent":[null],"names":["invoke","listen"],"mappings":";;;;;AAAA;AAoBA;;;AAGG;AACI,eAAe,YAAY,CAAC,SAAsB,EAAE,EAAA;IACzD,MAAMA,WAAM,CAAC,iCAAiC,EAAE,EAAE,MAAM,EAAE,CAAC;AAC7D;AAEA;AACO,eAAe,WAAW,GAAA;AAC/B,IAAA,MAAMA,WAAM,CAAC,gCAAgC,CAAC;AAChD;AAEA;AACO,eAAe,gBAAgB,GAAA;AACpC,IAAA,OAAOA,WAAM,CAAU,sCAAsC,CAAC;AAChE;AAEA;;;;AAIG;AACI,eAAe,aAAa,CACjC,OAAqC,EAAA;AAErC,IAAA,OAAOC,YAAM,CAAc,4BAA4B,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;AACnF;;;;;;;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type UnlistenFn } from '@tauri-apps/api/event';
|
|
2
|
+
export interface StartConfig {
|
|
3
|
+
/** Text shown in the Android persistent foreground notification */
|
|
4
|
+
serviceLabel?: string;
|
|
5
|
+
/**
|
|
6
|
+
* Android foreground service type. Valid values: `"dataSync"` (default), `"specialUse"`.
|
|
7
|
+
* Ignored on non-Android platforms.
|
|
8
|
+
*/
|
|
9
|
+
foregroundServiceType?: string;
|
|
10
|
+
}
|
|
11
|
+
/** Built-in plugin lifecycle events */
|
|
12
|
+
export type PluginEvent = {
|
|
13
|
+
type: 'started';
|
|
14
|
+
} | {
|
|
15
|
+
type: 'stopped';
|
|
16
|
+
reason: string;
|
|
17
|
+
} | {
|
|
18
|
+
type: 'error';
|
|
19
|
+
message: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Start the background service.
|
|
23
|
+
* The service struct is already registered in main.rs — this just starts it.
|
|
24
|
+
*/
|
|
25
|
+
export declare function startService(config?: StartConfig): Promise<void>;
|
|
26
|
+
/** Stop the service and cancel the shutdown token. */
|
|
27
|
+
export declare function stopService(): Promise<void>;
|
|
28
|
+
/** Returns true if the Rust service is currently running. */
|
|
29
|
+
export declare function isServiceRunning(): Promise<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* Listen to built-in plugin lifecycle events.
|
|
32
|
+
* Your service can emit its own custom events via ctx.app.emit() —
|
|
33
|
+
* subscribe to those separately with tauri's `listen()`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function onPluginEvent(handler: (event: PluginEvent) => void): Promise<UnlistenFn>;
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEhE,MAAM,WAAW,WAAW;IAC1B,mEAAmE;IACnE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,uCAAuC;AACvC,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAI,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1C;;;GAGG;AACH,wBAAsB,YAAY,CAAC,MAAM,GAAE,WAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1E;AAED,sDAAsD;AACtD,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAEjD;AAED,6DAA6D;AAC7D,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,OAAO,CAAC,CAEzD;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GACpC,OAAO,CAAC,UAAU,CAAC,CAErB"}
|
package/dist-js/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { invoke } from '@tauri-apps/api/core';
|
|
2
|
+
import { listen } from '@tauri-apps/api/event';
|
|
3
|
+
|
|
4
|
+
// guest-js/index.ts
|
|
5
|
+
/**
|
|
6
|
+
* Start the background service.
|
|
7
|
+
* The service struct is already registered in main.rs — this just starts it.
|
|
8
|
+
*/
|
|
9
|
+
async function startService(config = {}) {
|
|
10
|
+
await invoke('plugin:background-service|start', { config });
|
|
11
|
+
}
|
|
12
|
+
/** Stop the service and cancel the shutdown token. */
|
|
13
|
+
async function stopService() {
|
|
14
|
+
await invoke('plugin:background-service|stop');
|
|
15
|
+
}
|
|
16
|
+
/** Returns true if the Rust service is currently running. */
|
|
17
|
+
async function isServiceRunning() {
|
|
18
|
+
return invoke('plugin:background-service|is_running');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Listen to built-in plugin lifecycle events.
|
|
22
|
+
* Your service can emit its own custom events via ctx.app.emit() —
|
|
23
|
+
* subscribe to those separately with tauri's `listen()`.
|
|
24
|
+
*/
|
|
25
|
+
async function onPluginEvent(handler) {
|
|
26
|
+
return listen('background-service://event', e => handler(e.payload));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { isServiceRunning, onPluginEvent, startService, stopService };
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAAA;AAoBA;;;AAGG;AACI,eAAe,YAAY,CAAC,SAAsB,EAAE,EAAA;IACzD,MAAM,MAAM,CAAC,iCAAiC,EAAE,EAAE,MAAM,EAAE,CAAC;AAC7D;AAEA;AACO,eAAe,WAAW,GAAA;AAC/B,IAAA,MAAM,MAAM,CAAC,gCAAgC,CAAC;AAChD;AAEA;AACO,eAAe,gBAAgB,GAAA;AACpC,IAAA,OAAO,MAAM,CAAU,sCAAsC,CAAC;AAChE;AAEA;;;;AAIG;AACI,eAAe,aAAa,CACjC,OAAqC,EAAA;AAErC,IAAA,OAAO,MAAM,CAAc,4BAA4B,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;AACnF;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tauri-plugin-background-service",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Manage long-lived background service lifecycle in Tauri v2 apps across Android, iOS, and desktop.",
|
|
5
|
+
"license": "MIT OR Apache-2.0",
|
|
6
|
+
"authors": [
|
|
7
|
+
"Mohamed Dardouri <med@dardouri.com>"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"types": "./dist-js/index.d.ts",
|
|
11
|
+
"main": "./dist-js/index.cjs",
|
|
12
|
+
"module": "./dist-js/index.js",
|
|
13
|
+
"exports": {
|
|
14
|
+
"types": "./dist-js/index.d.ts",
|
|
15
|
+
"import": "./dist-js/index.js",
|
|
16
|
+
"require": "./dist-js/index.cjs"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "rollup -c",
|
|
20
|
+
"prepublishOnly": "npm run build"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist-js",
|
|
24
|
+
"README.md",
|
|
25
|
+
"LICENSE"
|
|
26
|
+
],
|
|
27
|
+
"keywords": [
|
|
28
|
+
"tauri",
|
|
29
|
+
"tauri-plugin",
|
|
30
|
+
"background",
|
|
31
|
+
"service",
|
|
32
|
+
"foreground-service",
|
|
33
|
+
"android",
|
|
34
|
+
"ios",
|
|
35
|
+
"mobile",
|
|
36
|
+
"lifecycle"
|
|
37
|
+
],
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/dardourimohamed/tauri-background-service.git"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/dardourimohamed/tauri-background-service#readme",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/dardourimohamed/tauri-background-service/issues"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@tauri-apps/api": "^2.0.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"typescript": "^5.0.0",
|
|
51
|
+
"rollup": "^4.0.0",
|
|
52
|
+
"@rollup/plugin-typescript": "^11.0.0",
|
|
53
|
+
"tslib": "^2.6.0"
|
|
54
|
+
}
|
|
55
|
+
}
|