mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-05 00:41:40 +00:00
Refactor skip intro/outro to global settings instead of per-book
Settings are now stored as top-level user settings in localStorage rather than nested under bookSkipSettings per libraryItemId. This makes the settings always accessible regardless of playback state.
This commit is contained in:
parent
d157388680
commit
8a34eff1e9
3 changed files with 26 additions and 54 deletions
|
|
@ -548,16 +548,19 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获取当前书籍的跳过设置
|
// 获取跳过设置
|
||||||
getBookSkipSettings() {
|
getSkipSettings() {
|
||||||
if (!this.streamLibraryItem) return null
|
return {
|
||||||
const bookSkipSettings = this.$store.getters['user/getUserSetting']('bookSkipSettings') || {}
|
skipIntro: this.$store.getters['user/getUserSetting']('skipIntro'),
|
||||||
return bookSkipSettings[this.streamLibraryItem.id] || {}
|
introDuration: this.$store.getters['user/getUserSetting']('introDuration'),
|
||||||
|
skipOutro: this.$store.getters['user/getUserSetting']('skipOutro'),
|
||||||
|
outroDuration: this.$store.getters['user/getUserSetting']('outroDuration')
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 检查并执行章节intro/outro跳过
|
// 检查并执行章节intro/outro跳过
|
||||||
checkAndSkipIntroOutro(currentTime) {
|
checkAndSkipIntroOutro(currentTime) {
|
||||||
const skipSettings = this.getBookSkipSettings()
|
const skipSettings = this.getSkipSettings()
|
||||||
if (!skipSettings) return
|
if (!skipSettings) return
|
||||||
|
|
||||||
const doSkipIntro = skipSettings.skipIntro && skipSettings.introDuration > 0
|
const doSkipIntro = skipSettings.skipIntro && skipSettings.introDuration > 0
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,10 @@
|
||||||
<div class="flex items-center mb-4">
|
<div class="flex items-center mb-4">
|
||||||
<ui-select-input v-model="playbackRateIncrementDecrement" :label="$strings.LabelPlaybackRateIncrementDecrement" menuMaxHeight="250px" :items="playbackRateIncrementDecrementValues" @input="setPlaybackRateIncrementDecrementAmount" />
|
<ui-select-input v-model="playbackRateIncrementDecrement" :label="$strings.LabelPlaybackRateIncrementDecrement" menuMaxHeight="250px" :items="playbackRateIncrementDecrementValues" @input="setPlaybackRateIncrementDecrementAmount" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 书籍跳过配置 -->
|
<div class="border-t pt-4 mt-6">
|
||||||
<div class="border-t pt-4 mt-6" v-if="currentLibraryItemId">
|
<h4 class="text-lg font-medium mb-4">章节跳过设置</h4>
|
||||||
<h4 class="text-lg font-medium mb-4">本书跳过设置</h4>
|
|
||||||
|
|
||||||
<div class="flex items-center mb-4">
|
<div class="flex items-center mb-4">
|
||||||
<ui-toggle-switch v-model="skipIntro" @input="setSkipIntro" />
|
<ui-toggle-switch v-model="skipIntro" @input="setSkipIntro" />
|
||||||
<div class="pl-4 flex-1">
|
<div class="pl-4 flex-1">
|
||||||
|
|
@ -30,7 +29,7 @@
|
||||||
<ui-text-input v-model="introDuration" type="number" min="0" max="60" @input="setIntroDuration" class="w-20" />
|
<ui-text-input v-model="introDuration" type="number" min="0" max="60" @input="setIntroDuration" class="w-20" />
|
||||||
<span class="ml-2 text-sm text-gray-400">秒</span>
|
<span class="ml-2 text-sm text-gray-400">秒</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex items-center mb-4">
|
<div class="flex items-center mb-4">
|
||||||
<ui-toggle-switch v-model="skipOutro" @input="setSkipOutro" />
|
<ui-toggle-switch v-model="skipOutro" @input="setSkipOutro" />
|
||||||
<div class="pl-4 flex-1">
|
<div class="pl-4 flex-1">
|
||||||
|
|
@ -64,9 +63,6 @@ export default {
|
||||||
jumpBackwardAmount: 10,
|
jumpBackwardAmount: 10,
|
||||||
playbackRateIncrementDecrementValues: [0.1, 0.05],
|
playbackRateIncrementDecrementValues: [0.1, 0.05],
|
||||||
playbackRateIncrementDecrement: 0.1,
|
playbackRateIncrementDecrement: 0.1,
|
||||||
|
|
||||||
// 书籍跳过设置
|
|
||||||
currentLibraryItemId: null,
|
|
||||||
skipIntro: false,
|
skipIntro: false,
|
||||||
introDuration: 10,
|
introDuration: 10,
|
||||||
skipOutro: false,
|
skipOutro: false,
|
||||||
|
|
@ -99,67 +95,37 @@ export default {
|
||||||
this.playbackRateIncrementDecrement = val
|
this.playbackRateIncrementDecrement = val
|
||||||
this.$store.dispatch('user/updateUserSettings', { playbackRateIncrementDecrement: val })
|
this.$store.dispatch('user/updateUserSettings', { playbackRateIncrementDecrement: val })
|
||||||
},
|
},
|
||||||
|
|
||||||
// 书籍跳过设置方法
|
|
||||||
setSkipIntro() {
|
setSkipIntro() {
|
||||||
this.updateBookSkipSetting('skipIntro', this.skipIntro)
|
this.$store.dispatch('user/updateUserSettings', { skipIntro: this.skipIntro })
|
||||||
},
|
},
|
||||||
setIntroDuration() {
|
setIntroDuration() {
|
||||||
this.introDuration = Math.max(0, Math.min(60, parseInt(this.introDuration) || 0))
|
this.introDuration = Math.max(0, Math.min(60, parseInt(this.introDuration) || 0))
|
||||||
this.updateBookSkipSetting('introDuration', this.introDuration)
|
this.$store.dispatch('user/updateUserSettings', { introDuration: this.introDuration })
|
||||||
},
|
},
|
||||||
setSkipOutro() {
|
setSkipOutro() {
|
||||||
this.updateBookSkipSetting('skipOutro', this.skipOutro)
|
this.$store.dispatch('user/updateUserSettings', { skipOutro: this.skipOutro })
|
||||||
},
|
},
|
||||||
setOutroDuration() {
|
setOutroDuration() {
|
||||||
this.outroDuration = Math.max(0, Math.min(60, parseInt(this.outroDuration) || 0))
|
this.outroDuration = Math.max(0, Math.min(60, parseInt(this.outroDuration) || 0))
|
||||||
this.updateBookSkipSetting('outroDuration', this.outroDuration)
|
this.$store.dispatch('user/updateUserSettings', { outroDuration: this.outroDuration })
|
||||||
},
|
|
||||||
updateBookSkipSetting(key, value) {
|
|
||||||
if (!this.currentLibraryItemId) return
|
|
||||||
|
|
||||||
const bookSkipSettings = { ...this.$store.getters['user/getUserSetting']('bookSkipSettings') || {} }
|
|
||||||
if (!bookSkipSettings[this.currentLibraryItemId]) {
|
|
||||||
bookSkipSettings[this.currentLibraryItemId] = {}
|
|
||||||
}
|
|
||||||
bookSkipSettings[this.currentLibraryItemId][key] = value
|
|
||||||
this.$store.dispatch('user/updateUserSettings', { bookSkipSettings })
|
|
||||||
},
|
},
|
||||||
settingsUpdated() {
|
settingsUpdated() {
|
||||||
this.useChapterTrack = this.$store.getters['user/getUserSetting']('useChapterTrack')
|
this.useChapterTrack = this.$store.getters['user/getUserSetting']('useChapterTrack')
|
||||||
this.jumpForwardAmount = this.$store.getters['user/getUserSetting']('jumpForwardAmount')
|
this.jumpForwardAmount = this.$store.getters['user/getUserSetting']('jumpForwardAmount')
|
||||||
this.jumpBackwardAmount = this.$store.getters['user/getUserSetting']('jumpBackwardAmount')
|
this.jumpBackwardAmount = this.$store.getters['user/getUserSetting']('jumpBackwardAmount')
|
||||||
this.playbackRateIncrementDecrement = this.$store.getters['user/getUserSetting']('playbackRateIncrementDecrement')
|
this.playbackRateIncrementDecrement = this.$store.getters['user/getUserSetting']('playbackRateIncrementDecrement')
|
||||||
|
this.skipIntro = this.$store.getters['user/getUserSetting']('skipIntro') || false
|
||||||
// 加载当前书籍的跳过设置
|
this.introDuration = this.$store.getters['user/getUserSetting']('introDuration') || 10
|
||||||
this.loadBookSkipSettings()
|
this.skipOutro = this.$store.getters['user/getUserSetting']('skipOutro') || false
|
||||||
},
|
this.outroDuration = this.$store.getters['user/getUserSetting']('outroDuration') || 10
|
||||||
loadBookSkipSettings() {
|
|
||||||
// 获取当前播放的书籍ID
|
|
||||||
const mediaPlayerContainer = this.$root.$refs.mediaPlayerContainer || this.$parent.$refs.mediaPlayerContainer
|
|
||||||
if (mediaPlayerContainer && mediaPlayerContainer.streamLibraryItem) {
|
|
||||||
this.currentLibraryItemId = mediaPlayerContainer.streamLibraryItem.id
|
|
||||||
|
|
||||||
const bookSkipSettings = this.$store.getters['user/getUserSetting']('bookSkipSettings') || {}
|
|
||||||
const currentBookSettings = bookSkipSettings[this.currentLibraryItemId] || {}
|
|
||||||
|
|
||||||
this.skipIntro = currentBookSettings.skipIntro || false
|
|
||||||
this.introDuration = currentBookSettings.introDuration || 10
|
|
||||||
this.skipOutro = currentBookSettings.skipOutro || false
|
|
||||||
this.outroDuration = currentBookSettings.outroDuration || 10
|
|
||||||
} else {
|
|
||||||
this.currentLibraryItemId = null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.settingsUpdated()
|
this.settingsUpdated()
|
||||||
this.$eventBus.$on('user-settings', this.settingsUpdated)
|
this.$eventBus.$on('user-settings', this.settingsUpdated)
|
||||||
this.$eventBus.$on('playback-session-changed', this.loadBookSkipSettings)
|
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
this.$eventBus.$off('user-settings', this.settingsUpdated)
|
this.$eventBus.$off('user-settings', this.settingsUpdated)
|
||||||
this.$eventBus.$off('playback-session-changed', this.loadBookSkipSettings)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,10 @@ export const state = () => ({
|
||||||
authorSortDesc: false,
|
authorSortDesc: false,
|
||||||
jumpForwardAmount: 10,
|
jumpForwardAmount: 10,
|
||||||
jumpBackwardAmount: 10,
|
jumpBackwardAmount: 10,
|
||||||
bookSkipSettings: {} // 书籍跳过配置 { [libraryItemId]: { skipIntro, introDuration, skipOutro, outroDuration } }
|
skipIntro: false,
|
||||||
|
introDuration: 10,
|
||||||
|
skipOutro: false,
|
||||||
|
outroDuration: 10
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue