deeke-script-app 1.5.0 → 1.5.1

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.
@@ -0,0 +1,31 @@
1
+
2
+ declare global {
3
+ var ForegroundServiceBridge: foregroundServiceBridge;
4
+ }
5
+
6
+ interface foregroundServiceBridge {
7
+ /**
8
+ * 开启前台服务
9
+ */
10
+ public startService(): void;
11
+
12
+ /**
13
+ * 注册执行的方法(启动服务前设置)
14
+ * @param register 注册监听
15
+ */
16
+ public register(func: Function): void;
17
+
18
+ /**
19
+ * 前台服务标题和内容设置(启动服务前设置)
20
+ * @param title 前台服务标题
21
+ * @param content 前台服务内容
22
+ */
23
+ public setContent(title: string, content: string):void;
24
+
25
+ /**
26
+ * 关闭服务
27
+ */
28
+ public stopService(): void;
29
+ }
30
+
31
+ export { };
@@ -18,6 +18,11 @@ interface notificationBridge {
18
18
  onNotification: (packageName: string, title: string, text: string) => void,
19
19
  onNotificationRemoved: (packageName: string, title: string, text: string) => void
20
20
  ): void;
21
+
22
+ /**
23
+ * 关闭服务
24
+ */
25
+ public stopService(): void;
21
26
  }
22
27
 
23
28
  export { };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deeke-script-app",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "DeekeScript应用",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
@@ -0,0 +1,23 @@
1
+
2
+ let close = false;
3
+ ForegroundServiceBridge.setContent('测试', '前台服务');
4
+ ForegroundServiceBridge.register(()=>{
5
+ console.log('前台服务启动成功');
6
+ let m = setInterval(() => {
7
+ console.log('正在执行任务...');
8
+ if(close){
9
+ clearInterval(m);
10
+ }
11
+ }, 3000);
12
+ });
13
+
14
+ ForegroundServiceBridge.startService();
15
+
16
+ let i = 0;
17
+ setInterval(() => {
18
+ console.log('正在监听中...');
19
+ if(i++ >= 1){
20
+ ForegroundServiceBridge.stopService();
21
+ close = true;
22
+ }
23
+ }, 10000);
@@ -11,8 +11,12 @@ if (!root) {
11
11
  NotificationBridge.startService();
12
12
  NotificationBridge.startListening((packageName, title, text) => {
13
13
  console.log('收到通知', packageName, title, text);
14
+ if(text == '关闭'){
15
+ NotificationBridge.stopService();
16
+ }
14
17
  }, (packageName, title, text) => {
15
18
  console.log('通知监听已关闭', packageName, title, text);
19
+
16
20
  });
17
21
 
18
22
  NotificationBridge.startService();