1
+ /**
2
+ * OpenAPI
3
+ * @author : Peng-YM
4
+ * https://github.com/Peng-YM/QuanX/blob/master/Tools/OpenAPI/README.md
5
+ */
1
6
function ENV ( ) {
2
7
const isQX = typeof $task !== "undefined" ;
3
8
const isLoon = typeof $loon !== "undefined" ;
@@ -134,8 +139,7 @@ function API(name = "untitled", debug = false) {
134
139
} ;
135
140
}
136
141
137
- // persistance
138
-
142
+ // persistence
139
143
// initialize cache
140
144
initCache ( ) {
141
145
if ( isQX ) this . cache = JSON . parse ( $prefs . valueForKey ( this . name ) || "{}" ) ;
@@ -175,7 +179,7 @@ function API(name = "untitled", debug = false) {
175
179
176
180
// store cache
177
181
persistCache ( ) {
178
- const data = JSON . stringify ( this . cache ) ;
182
+ const data = JSON . stringify ( this . cache , null , 2 ) ;
179
183
if ( isQX ) $prefs . setValueForKey ( data , this . name ) ;
180
184
if ( isLoon || isSurge ) $persistentStore . write ( data , this . name ) ;
181
185
if ( isNode ) {
@@ -187,7 +191,7 @@ function API(name = "untitled", debug = false) {
187
191
) ;
188
192
this . node . fs . writeFileSync (
189
193
"root.json" ,
190
- JSON . stringify ( this . root ) ,
194
+ JSON . stringify ( this . root , null , 2 ) ,
191
195
{ flag : "w" } ,
192
196
( err ) => console . log ( err )
193
197
) ;
@@ -270,7 +274,7 @@ function API(name = "untitled", debug = false) {
270
274
let opts = { } ;
271
275
if ( openURL ) opts [ "openUrl" ] = openURL ;
272
276
if ( mediaURL ) opts [ "mediaUrl" ] = mediaURL ;
273
- if ( JSON . stringify ( opts ) == "{}" ) {
277
+ if ( JSON . stringify ( opts ) === "{}" ) {
274
278
$notification . post ( title , subtitle , content ) ;
275
279
} else {
276
280
$notification . post ( title , subtitle , content , opts ) ;
@@ -295,15 +299,15 @@ function API(name = "untitled", debug = false) {
295
299
296
300
// other helper functions
297
301
log ( msg ) {
298
- if ( this . debug ) console . log ( msg ) ;
302
+ if ( this . debug ) console . log ( `[ ${ this . name } ] LOG: ${ msg } ` ) ;
299
303
}
300
304
301
305
info ( msg ) {
302
- console . log ( msg ) ;
306
+ console . log ( `[ ${ this . name } ] INFO: ${ msg } ` ) ;
303
307
}
304
308
305
309
error ( msg ) {
306
- console . log ( " ERROR: " + msg ) ;
310
+ console . log ( `[ ${ this . name } ] ERROR: ${ msg } ` ) ;
307
311
}
308
312
309
313
wait ( millisec ) {
@@ -322,4 +326,4 @@ function API(name = "untitled", debug = false) {
322
326
}
323
327
}
324
328
} ) ( name , debug ) ;
325
- }
329
+ }
0 commit comments