11const $ = new Env ( 'BoxJs' )
22$ . domain = '8.8.8.8'
33
4- $ . version = '0.6.7 '
4+ $ . version = '0.6.8 '
55$ . versionType = 'beta'
66$ . KEY_sessions = 'chavy_boxjs_sessions'
77$ . KEY_versions = 'chavy_boxjs_versions'
@@ -225,6 +225,11 @@ function getSessions() {
225225 return Array . isArray ( sessions ) ? sessions : [ ]
226226}
227227
228+ function getCurSessions ( appId ) {
229+ const curSessionsstr = $ . getdata ( $ . KEY_curSessions )
230+ return ! [ undefined , null , 'null' , '' ] . includes ( curSessionsstr ) ? JSON . parse ( curSessionsstr ) : { }
231+ }
232+
228233async function getVersions ( ) {
229234 let vers = [ ]
230235 await new Promise ( ( resolve ) => {
@@ -315,8 +320,7 @@ async function handleApi() {
315320 // 应用会话
316321 else if ( data . cmd === 'useSession' ) {
317322 $ . log ( `❕ ${ $ . name } , 应用会话!` )
318- const curSessionsstr = $ . getdata ( $ . KEY_curSessions )
319- const curSessions = ! [ undefined , null , 'null' , '' ] . includes ( curSessionsstr ) ? JSON . parse ( curSessionsstr ) : { }
323+ const curSessions = getCurSessions ( )
320324 const session = data . val
321325 const sessions = getSessions ( )
322326 const sessionIdx = sessions . findIndex ( ( s ) => session . id === s . id )
@@ -445,9 +449,9 @@ async function handleApi() {
445449 const ishttpapi = / .* ?@ .* ?: [ 0 - 9 ] + / . test ( httpapi )
446450 console . log ( ishttpapi )
447451 if ( $ . isSurge ( ) && ishttpapi ) {
448- await $ . getScript ( data . val . script ) . then ( ( script ) => $ . runScript ( script ) )
452+ await $ . getScript ( data . val ) . then ( ( script ) => $ . runScript ( script ) )
449453 } else {
450- await $ . getScript ( data . val . script ) . then ( ( script ) => {
454+ await $ . getScript ( data . val ) . then ( ( script ) => {
451455 // 避免被执行脚本误认为是 rewrite 环境
452456 // 所以需要 `$request = undefined`
453457 $request = undefined
@@ -460,6 +464,7 @@ async function handleApi() {
460464async function getBoxData ( ) {
461465 const box = {
462466 sessions : getSessions ( ) ,
467+ curSessions : getCurSessions ( ) ,
463468 versions : await getVersions ( ) ,
464469 sysapps : getSystemApps ( ) ,
465470 userapps : getUserApps ( ) ,
@@ -766,7 +771,7 @@ function printHtml(data, curapp = null, curview = 'app') {
766771 </v-list>
767772 </v-menu>
768773 <v-btn icon @click="ui.curview = ui.bfview" v-else><v-icon>mdi-chevron-left</v-icon></v-btn>
769- <v-autocomplete v-model="ui.autocomplete.curapp" :items="apps" :filter="appfilter" :menu-props="{ closeOnContentClick: true, overflowY: true }" :label="ui.curapp ? ui.curapp.name + ' ' + ui.curapp.author : 'BoxJs - v' + box.syscfgs.version" no-data-text="未实现" dense hide-details solo>
774+ <v-autocomplete v-model="ui.autocomplete.curapp" :items="apps" :filter="appfilter" :menu-props="{ closeOnContentClick: true, overflowY: true }" :label="'BoxJs - v' + box.syscfgs.version" no-data-text="未实现" dense hide-details solo>
770775 <template v-slot:item="{ item }">
771776 <v-list-item @click="goAppSessionView(item)">
772777 <v-list-item-avatar>
@@ -1013,12 +1018,26 @@ function printHtml(data, curapp = null, curview = 'app') {
10131018 </v-expansion-panels>
10141019 </v-container>
10151020 <v-container fluid v-else-if="ui.curview === 'appsession'">
1021+ <v-subheader>
1022+ <h2 >{{ui.curapp.name}}</h2>
1023+ <v-spacer></v-spacer>
1024+ <v-btn v-if="ui.curapp.script" icon @click="onRunScript(ui.curapp.script)"><v-icon color="green">mdi-play-circle</v-icon></v-btn>
1025+ </v-subheader>
1026+ <v-card class="mx-auto mb-4">
1027+ <template v-if="Array.isArray(ui.curapp.scripts)">
1028+ <v-subheader> 应用脚本 ({{ ui.curapp.scripts.length }}) </v-subheader>
1029+ <v-list dense>
1030+ <v-list-item v-for="(script, scriptIdx) in ui.curapp.scripts" :key="scriptIdx">
1031+ <v-list-item-title> {{ scriptIdx + 1 }}. {{ script.name }} </v-list-item-title>
1032+ <v-btn icon @click.stop="onRunScript(script.script)"><v-icon>mdi-play-circle</v-icon></v-btn>
1033+ </v-list-item>
1034+ </v-list>
1035+ </template>
1036+ </v-card>
10161037 <v-card class="mx-auto mb-4">
10171038 <template v-if="Array.isArray(ui.curapp.settings)">
10181039 <v-subheader v-if="Array.isArray(ui.curapp.settings)">
10191040 应用设置 ({{ ui.curapp.settings.length }})
1020- <v-spacer></v-spacer>
1021- <v-btn v-if="ui.curapp.script" icon @click="onRunScript"><v-icon color="green">mdi-play-circle</v-icon></v-btn>
10221041 </v-subheader>
10231042 <v-form class="pl-4 pr-4">
10241043 <template v-for="(setting, settingIdx) in ui.curapp.settings">
@@ -1045,9 +1064,8 @@ function printHtml(data, curapp = null, curview = 'app') {
10451064 </v-card>
10461065 <v-card class="mx-auto" v-if="ui.curapp.datas && ui.curapp.datas.length > 0">
10471066 <v-subheader>
1048- 当前会话 ( {{ ui.curapp.datas.length }})
1067+ 当前会话<a class="ml-2"> {{ cursession ? cursession.name : '' }}</a>
10491068 <v-spacer></v-spacer>
1050- <v-btn v-if="ui.curapp.script" icon @click="onRunScript"><v-icon color="green">mdi-play-circle</v-icon></v-btn>
10511069 <v-menu bottom left>
10521070 <template v-slot:activator="{ on }">
10531071 <v-btn icon v-on="on"><v-icon>mdi-dots-vertical</v-icon></v-btn>
@@ -1091,7 +1109,8 @@ function printHtml(data, curapp = null, curview = 'app') {
10911109 </v-card>
10921110 <v-card class="ml-10 mt-4" v-for="(session, sessionIdx) in ui.curappSessions" :key="session.id">
10931111 <v-subheader>
1094- #{{ sessionIdx + 1 }} {{ session.name }}
1112+ <a v-if="cursession.id === session.id">#{{ sessionIdx + 1 }} {{ session.name }}</a>
1113+ <template v-else>#{{ sessionIdx + 1 }} {{ session.name }}</template>
10951114 <v-spacer></v-spacer>
10961115 <v-menu bottom left>
10971116 <template v-slot:activator="{ on }">
@@ -1578,6 +1597,13 @@ function printHtml(data, curapp = null, curview = 'app') {
15781597 sessioncnt: function () {
15791598 return Array.isArray(this.box.sessions) ? this.box.sessions.length : 0
15801599 },
1600+ cursession: function() {
1601+ if (this.ui.curapp) {
1602+ const curSessionId = this.box.curSessions[this.ui.curapp.id]
1603+ return this.box.sessions.find(s => s.id === curSessionId) || {}
1604+ }
1605+ return {}
1606+ },
15811607 boxdat: function () {
15821608 const KEY_sessions = 'chavy_boxjs_sessions'
15831609 const KEY_sysCfgs = 'chavy_boxjs_sysCfgs'
@@ -1644,34 +1670,33 @@ function printHtml(data, curapp = null, curview = 'app') {
16441670 'ui.curview': {
16451671 handler(newval, oldval) {
16461672 this.ui.bfview = oldval
1647- const isFullScreen = window.navigator.standalone
16481673 if (newval === 'app') {
16491674 this.ui.curapp = null
16501675 this.ui.curappSessions = null
16511676 var state = { title: 'BoxJs' }
16521677 document.title = state.title
1653- if (!isFullScreen ) {
1678+ if (!this.fullscreen ) {
16541679 history.pushState(state, '', '/home')
16551680 }
1656- this.$vuetify.goTo(this.ui.scrollY, { duration: 0, offset: 0 })
16571681 } else if (newval === 'sub') {
16581682 this.ui.curapp = null
16591683 this.ui.curappSessions = null
16601684 this.showRefreshTip()
16611685 var state = { title: 'BoxJs' }
16621686 document.title = state.title
1663- if (!isFullScreen ) {
1687+ if (!this.fullscreen ) {
16641688 history.pushState(state, '', '/sub')
16651689 }
16661690 } else if (newval === 'my') {
16671691 this.ui.curapp = null
16681692 this.ui.curappSessions = null
16691693 var state = { title: 'BoxJs' }
16701694 document.title = state.title
1671- if (!isFullScreen ) {
1695+ if (!this.fullscreen ) {
16721696 history.pushState(state, '', '/my')
16731697 }
16741698 }
1699+ this.$vuetify.goTo(newval === 'app' ? this.ui.scrollY : 0, { duration: 0, offset: 0 })
16751700 }
16761701 },
16771702 'ui.reloadConfirmDialog.sec': {
@@ -1770,8 +1795,7 @@ function printHtml(data, curapp = null, curview = 'app') {
17701795 this.ui.curappSessions = this.box.sessions.filter((s) => s.appId === this.ui.curapp.id)
17711796 this.ui.curview = 'appsession'
17721797 var state = { title: 'BoxJs - ' + this.ui.curapp.name, url: window.location.href }
1773- const isFullScreen = window.navigator.standalone
1774- if (!isFullScreen) {
1798+ if (!this.fullscreen) {
17751799 history.pushState(state, '', '/app/' + this.ui.curapp.id)
17761800 }
17771801 document.title = state.title
@@ -1991,7 +2015,7 @@ function printHtml(data, curapp = null, curview = 'app') {
19912015 })
19922016 })
19932017 },
1994- onRunScript() {
2018+ onRunScript(url ) {
19952019 this.ui.overlay.show = true
19962020
19972021 // const [key, addr] = this.box.usercfgs.httpapi.split('@')
@@ -2000,7 +2024,7 @@ function printHtml(data, curapp = null, curview = 'app') {
20002024 // const opts = {headers: { 'X-Key': key, 'Accept': '*/*' }}
20012025 // axios.post(url, body, opts)
20022026
2003- axios.post('/api', JSON.stringify({ cmd: 'runScript', val: this.ui.curapp })).finally(() => {
2027+ axios.post('/api', JSON.stringify({ cmd: 'runScript', val: url })).finally(() => {
20042028 this.ui.overlay.show = false
20052029 })
20062030 }
0 commit comments