@@ -53,6 +53,8 @@ $done();
53
53
54
54
function manager ( ) {
55
55
let ssid ;
56
+ let mode ;
57
+
56
58
if ( isSurge ) {
57
59
const v4_ip = $network . v4 . primaryAddress ;
58
60
// no network connection
@@ -61,7 +63,7 @@ function manager() {
61
63
return ;
62
64
}
63
65
ssid = $network . wifi . ssid ;
64
- const mode = ssid ? lookupSSID ( ssid ) : config . cellular ;
66
+ mode = ssid ? lookupSSID ( ssid ) : config . cellular ;
65
67
const target = {
66
68
RULE : "rule" ,
67
69
PROXY : "global-proxy" ,
@@ -71,7 +73,7 @@ function manager() {
71
73
} else if ( isLoon ) {
72
74
const conf = JSON . parse ( $config . getConfig ( ) ) ;
73
75
ssid = conf . ssid ;
74
- const mode = ssid ? lookupSSID ( ssid ) : config . cellular ;
76
+ mode = ssid ? lookupSSID ( ssid ) : config . cellular ;
75
77
const target = {
76
78
DIRECT : 0 ,
77
79
RULE : 1 ,
@@ -98,16 +100,11 @@ function lookupSSID(ssid) {
98
100
}
99
101
100
102
function notify ( title , subtitle , content ) {
101
- const TIMESTAMP_KEY = "running_mode_notified_time" ;
102
- const THROTTLE_TIME = 3 * 1000 ;
103
- const lastNotifiedTime = $persistentStore . read ( THROTTLE_TIME ) ;
104
- if (
105
- ! lastNotifiedTime ||
106
- new Date ( ) . getTime ( ) - lastNotifiedTime > THROTTLE_TIME
107
- ) {
108
- $persistentStore . write ( new Date ( ) . getTime ( ) . toString ( ) , TIMESTAMP_KEY ) ;
103
+ const SUBTITLE_STORE_KEY = "running_mode_notified_subtitle" ;
104
+ const lastNotifiedSubtitle = $persistentStore . read ( SUBTITLE_STORE_KEY ) ;
105
+
106
+ if ( ! lastNotifiedSubtitle || lastNotifiedSubtitle !== subtitle ) {
107
+ $persistentStore . write ( subtitle . toString ( ) , SUBTITLE_STORE_KEY ) ;
109
108
$notification . post ( title , subtitle , content ) ;
110
109
}
111
- }
112
-
113
- notify ( "title" , "subtitle" , "content" ) ;
110
+ }
0 commit comments