Skip to content

Commit b0e1fa1

Browse files
committed
更新[box.switcher.js]: BoxJs 可设置切换会话时静默运行 (不发出系统通知)
1 parent 078a0a8 commit b0e1fa1

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

box/switcher/box.switcher.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
const $ = new Env('会话切换')
22
$.KEY_sessions = 'chavy_boxjs_sessions'
3+
$.CFG_isSilent = $.getdata('CFG_BoxSwitcher_isSilent')
34

45
!(async () => {
56
$.log('', `🔔 ${$.name}, 开始!`, '')
67
await execSwitch()
8+
await showmsg()
79
})()
810
.catch((e) => {
911
$.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '')
1012
})
1113
.finally(() => {
12-
$.msg($.name, $.subt, $.desc), $.log('', `🔔 ${$.name}, 结束!`, ''), $.done()
14+
$.log('', `🔔 ${$.name}, 结束!`, ''), $.done()
1315
})
1416

1517
function execSwitch() {
@@ -69,5 +71,14 @@ function getSessions() {
6971
return Array.isArray(sessions) ? sessions : []
7072
}
7173

74+
function showmsg() {
75+
return new Promise((resove) => {
76+
if (!$.CFG_isSilent || $.CFG_isSilent === 'false') {
77+
$.msg($.name, $.subt, $.desc)
78+
}
79+
resove()
80+
})
81+
}
82+
7283
// prettier-ignore
7384
function Env(t){this.name=t,this.logs=[],this.isSurge=(()=>"undefined"!=typeof $httpClient),this.isQuanX=(()=>"undefined"!=typeof $task),this.log=((...t)=>{this.logs=[...this.logs,...t],t?console.log(t.join("\n")):console.log(this.logs.join("\n"))}),this.msg=((t=this.name,s="",i="")=>{this.isSurge()&&$notification.post(t,s,i),this.isQuanX()&&$notify(t,s,i),this.log("==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="),t&&this.log(t),s&&this.log(s),i&&this.log(i)}),this.getdata=(t=>this.isSurge()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):void 0),this.setdata=((t,s)=>this.isSurge()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):void 0),this.get=((t,s)=>this.send(t,"GET",s)),this.wait=((t,s=t)=>i=>setTimeout(()=>i(),Math.floor(Math.random()*(s-t+1)+t))),this.post=((t,s)=>this.send(t,"POST",s)),this.send=((t,s,i)=>{if(this.isSurge()){const e="POST"==s?$httpClient.post:$httpClient.get;e(t,(t,s,e)=>{s.body=e,s.statusCode=s.status,i(t,s,e)})}this.isQuanX()&&(t.method=s,$task.fetch(t).then(t=>{t.status=t.statusCode,i(null,t,t.body)},t=>i(t.error,t,t)))}),this.done=((t={})=>$done(t))}

chavy.box.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,15 @@ function getSystemApps() {
261261
author: '@Sunert',
262262
repo: 'https://github.com/Sunert/Scripts/blob/master/Task/txnews.js',
263263
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/txnews.png', 'https://raw.githubusercontent.com/Orz-3/task/master/txnews.png']
264+
},
265+
{
266+
id: 'BoxSwitcher',
267+
name: '会话切换',
268+
keys: [],
269+
settings: [{ id: 'CFG_BoxSwitcher_isSilent', name: '静默运行', val: false, type: 'boolean', desc: '切换会话时不发出系统通知!' }],
270+
author: '@chavyleung',
271+
repo: 'https://github.com/chavyleung/scripts/blob/master/box/switcher/box.switcher.js',
272+
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/box.png', 'https://raw.githubusercontent.com/Orz-3/task/master/box.png']
264273
}
265274
]
266275
sysapps
@@ -560,7 +569,7 @@ function printHtml(data, curapp = null) {
560569
</v-card-actions>
561570
</template>
562571
</v-card>
563-
<v-card class="mx-auto">
572+
<v-card class="mx-auto" v-if="ui.curapp.datas && ui.curapp.datas.length > 0">
564573
<v-subheader>
565574
当前会话 ({{ ui.curapp.datas.length }})
566575
<v-spacer></v-spacer>

0 commit comments

Comments
 (0)