Use document.title to display tab count and update info

This commit is contained in:
NI
2019-09-27 09:39:18 +08:00
parent 512e410221
commit 3b8483f9c5
3 changed files with 62 additions and 4 deletions

View File

@@ -42,6 +42,8 @@ const backendQueryRetryDelay = 2000;
const maxTimeDiff = 30000; const maxTimeDiff = 30000;
const updateIndicatorMaxDisplayTime = 3000;
const mainTemplate = ` const mainTemplate = `
<home <home
v-if="page == 'app'" v-if="page == 'app'"
@@ -50,7 +52,11 @@ const mainTemplate = `
:connection="socket" :connection="socket"
:controls="controls" :controls="controls"
:commands="commands" :commands="commands"
@navigate-to="changeURLHash"></home> @navigate-to="changeURLHash"
@tab-opened="tabOpened"
@tab-closed="tabClosed"
@tab-updated="tabUpdated"
></home>
<auth <auth
v-else-if="page == 'auth'" v-else-if="page == 'auth'"
:error="authErr" :error="authErr"
@@ -60,6 +66,8 @@ const mainTemplate = `
`.trim(); `.trim();
function startApp(rootEl) { function startApp(rootEl) {
const pageTitle = document.title;
let uiControlColor = new ControlColor(); let uiControlColor = new ControlColor();
new Vue({ new Vue({
@@ -90,7 +98,8 @@ function startApp(rootEl) {
new telnetctl.Telnet(uiControlColor), new telnetctl.Telnet(uiControlColor),
new sshctl.SSH(uiControlColor) new sshctl.SSH(uiControlColor)
]), ]),
commands: new Commands([new telnet.Command(), new ssh.Command()]) commands: new Commands([new telnet.Command(), new ssh.Command()]),
tabUpdateIndicator: null
}; };
}, },
watch: { watch: {
@@ -109,6 +118,12 @@ function startApp(rootEl) {
this.tryInitialAuth(); this.tryInitialAuth();
}, },
methods: { methods: {
changeTitleInfo(newTitleInfo) {
document.title = newTitleInfo + " " + pageTitle;
},
resetTitleInfo() {
document.title = pageTitle;
},
changeURLHash(newHash) { changeURLHash(newHash) {
window.location.hash = newHash; window.location.hash = newHash;
}, },
@@ -280,6 +295,43 @@ function startApp(rootEl) {
} catch (e) { } catch (e) {
this.authErr = "Unable to authenticate: " + e; this.authErr = "Unable to authenticate: " + e;
} }
},
updateTabTitleInfo(tabs, updated) {
if (tabs.length <= 0) {
this.resetTitleInfo();
return;
}
this.changeTitleInfo("(" + tabs.length + (updated ? "*" : "") + ")");
},
tabOpened(tabs) {
if (this.tabUpdateIndicator) {
clearTimeout(this.tabUpdateIndicator);
this.tabUpdateIndicator = null;
}
this.updateTabTitleInfo(tabs, false);
},
tabClosed(tabs) {
if (this.tabUpdateIndicator) {
clearTimeout(this.tabUpdateIndicator);
this.tabUpdateIndicator = null;
}
this.updateTabTitleInfo(tabs, false);
},
tabUpdated(tabs) {
if (this.tabUpdateIndicator) {
clearTimeout(this.tabUpdateIndicator);
this.tabUpdateIndicator = null;
}
this.updateTabTitleInfo(tabs, true);
this.tabUpdateIndicator = setTimeout(() => {
this.updateTabTitleInfo(tabs, false);
}, updateIndicatorMaxDisplayTime);
} }
} }
}); });

View File

@@ -440,6 +440,8 @@ export default {
this.windows.connect = false; this.windows.connect = false;
this.addToTab(data); this.addToTab(data);
this.$emit("tab-opened", this.tab.tabs);
}, },
async addToTab(data) { async addToTab(data) {
await this.switchTab( await this.switchTab(
@@ -498,6 +500,8 @@ export default {
} }
this.removeFromTab(index); this.removeFromTab(index);
this.$emit("tab-closed", this.tab.tabs);
}, },
tabStopped(index, reason) { tabStopped(index, reason) {
if (reason === null) { if (reason === null) {
@@ -507,7 +511,9 @@ export default {
} }
}, },
tabUpdated(index) { tabUpdated(index) {
this.tab.tabs[index].indicator.updated = this.tab.current !== index; this.$emit("tab-updated", this.tab.tabs);
this.tab.tabs[index].indicator.updated = index !== this.tab.current;
} }
} }
}; };

View File

@@ -25,7 +25,7 @@
:class="{ :class="{
active: tab === idx, active: tab === idx,
error: tabInfo.indicator.error.length > 0, error: tabInfo.indicator.error.length > 0,
updated: tabInfo.indicator.updated updated: tabInfo.indicator.updated && tab !== idx
}" }"
:style=" :style="
'background: ' + 'background: ' +