diff --git a/src/actions/index.js b/src/actions/index.js new file mode 100644 index 0000000000..6629b271eb --- /dev/null +++ b/src/actions/index.js @@ -0,0 +1,5 @@ +import { setDocumentTitle } from './setDocumentTitle' + +export { + setDocumentTitle +} diff --git a/src/actions/setDocumentTitle.js b/src/actions/setDocumentTitle.js new file mode 100644 index 0000000000..2d952ff289 --- /dev/null +++ b/src/actions/setDocumentTitle.js @@ -0,0 +1,35 @@ +import { formatBytes } from '@/helpers' + +export class setDocumentTitle { + static setDefault() { + this.set('VueTorrent') + } + + static setGlobalSpeed(speeds) { + if (!speeds || speeds.length !== 2) return + this.set(`[D: ${formatBytes(speeds[0])}/s, U: ${formatBytes(speeds[1])}/s] VueTorrent`) + } + + static setFirstTorrentStatus(torrent) { + if (!torrent) return + this.set(`${torrent.state.toLowerCase()} - ${torrent.progress}% - ${torrent.name}`) + } + + static updateTitle(mode, speeds, torrent) { + if (!mode || !speeds.length || !torrent) return + switch (mode) { + case 'Default': + return this.setDefault() + case 'Global Speed': + return this.setGlobalSpeed(speeds) + case 'First Torrent Status': + return this.setFirstTorrentStatus(torrent) + default: + return this.setDefault() + } + } + + static set(title) { + document.title = title + } +} diff --git a/src/components/Core/SpeedCard.vue b/src/components/Core/SpeedCard.vue index 6866db435a..4df76cb9c2 100644 --- a/src/components/Core/SpeedCard.vue +++ b/src/components/Core/SpeedCard.vue @@ -1,29 +1,31 @@ @@ -47,7 +49,7 @@ export default { diff --git a/src/components/Modals/SettingsModal/Tabs/Vuetorrent/General.vue b/src/components/Modals/SettingsModal/Tabs/Vuetorrent/General.vue index 31b0bf76f4..00d5cd9114 100644 --- a/src/components/Modals/SettingsModal/Tabs/Vuetorrent/General.vue +++ b/src/components/Modals/SettingsModal/Tabs/Vuetorrent/General.vue @@ -59,16 +59,6 @@ Show Tracker Filter - - - + + +

+ VueTorrent title: +

+
+ + + +

@@ -136,6 +141,7 @@ export default { data() { return { paginationSizes: [5, 15, 30, 50], + titleOptions: ['Default', 'Global Speed', 'First Torrent Status'], Qbitversion: 0 } }, @@ -190,21 +196,20 @@ export default { this.webuiSettings.useDeviceDarkMode = val } }, - showSpeedInTitle: { + paginationSize: { get() { - return this.webuiSettings.showSpeedInTitle + return this.webuiSettings.paginationSize }, set(val) { - this.webuiSettings.showSpeedInTitle = val - document.title = 'VueTorrent' + this.webuiSettings.paginationSize = val } }, - paginationSize: { + title: { get() { - return this.webuiSettings.paginationSize + return this.webuiSettings.title }, set(val) { - this.webuiSettings.paginationSize = val + this.webuiSettings.title = val } }, version() { diff --git a/src/store/index.js b/src/store/index.js index 87d11098f3..50f6b0d981 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -57,6 +57,7 @@ export default new Vuex.Store({ showCurrentSpeed: true, showTrackerFilter: false, showSpeedInTitle: false, + title: 'Default', useDeviceDarkMode: true, paginationSize: 15, busyTorrentProperties: [ diff --git a/src/store/mutations.js b/src/store/mutations.js index 834b4048ac..b5c0aef4e7 100644 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -1,7 +1,8 @@ import Torrent from '../models/Torrent' import Status from '../models/Status' import qbit from '../services/qbit' -import { formatBytes, getHostName } from '@/helpers' +import { getHostName } from '@/helpers' +import { setDocumentTitle } from '@/actions' export default { SET_APP_VERSION(state, version) { @@ -79,21 +80,22 @@ export default { } } - // torrent speed in title - if (state.webuiSettings.showSpeedInTitle) { - // eslint-disable-next-line max-len - document.title = `[D: ${formatBytes(state.status.dlspeed)}/s, U: ${formatBytes(state.status.upspeed)}/s] VueTorrent` - } - // torrents state.torrents = data.map(t => new Torrent(t)) + + // update document title + setDocumentTitle.updateTitle( + state.webuiSettings.title, + [state.status.dlspeed, state.status.upspeed], + state.torrents ? state.torrents[0] : null + ) }, FETCH_SETTINGS: async state => { const { data } = await qbit.getAppPreferences() state.settings = data }, UPDATE_SORT_OPTIONS: (state, { - hashes = [], + hashes = [], filter = null, category = null, tracker = null diff --git a/tests/helpers.js b/tests/helpers.js index f474f226cb..9ddac2b844 100644 --- a/tests/helpers.js +++ b/tests/helpers.js @@ -10,4 +10,4 @@ export function setup(component, propsData) { vuetify, propsData }) -} \ No newline at end of file +}