From d6e4a1e9cc6fe9190d1b9045d1ab7d84d819d0e5 Mon Sep 17 00:00:00 2001 From: Preston Date: Wed, 7 Oct 2020 09:57:22 -0400 Subject: [PATCH] Add Setting to disable smooth scrolling --- src/main/index.js | 66 +++++++++++++++---- .../theme-settings/theme-settings.js | 53 ++++++++++++++- .../theme-settings/theme-settings.vue | 12 ++++ src/renderer/store/modules/settings.js | 23 +++++-- static/locales/en-US.yaml | 2 + 5 files changed, 136 insertions(+), 20 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index 7108b1a6..d1f375b9 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -50,15 +50,28 @@ if (!isDev) { }) app.on('ready', (event, commandLine, workingDirectory) => { - createWindow() + settingsDb.findOne({ + _id: 'disableSmoothScrolling' + }, function (err, doc) { + if (err) { + app.exit(0) + return + } - if (isDev) { - installDevTools() - } + if (doc !== null && doc.value) { + app.commandLine.appendSwitch('disable-smooth-scrolling') + } - if (isDebug) { - mainWindow.webContents.openDevTools() - } + createWindow() + + if (isDev) { + installDevTools() + } + + if (isDebug) { + mainWindow.webContents.openDevTools() + } + }) }) } else { app.quit() @@ -69,15 +82,28 @@ if (!isDev) { }) app.on('ready', () => { - createWindow() + settingsDb.findOne({ + _id: 'disableSmoothScrolling' + }, function (err, doc) { + if (err) { + app.exit(0) + return + } - if (isDev) { - installDevTools() - } + if (doc !== null && doc.value) { + app.commandLine.appendSwitch('disable-smooth-scrolling') + } - if (isDebug) { - mainWindow.webContents.openDevTools() - } + createWindow() + + if (isDev) { + installDevTools() + } + + if (isDebug) { + mainWindow.webContents.openDevTools() + } + }) }) } @@ -206,6 +232,18 @@ function createWindow () { mainWindow.webContents.send('ping', process.argv) } }) + + ipcMain.on('disableSmoothScrolling', () => { + app.commandLine.appendSwitch('disable-smooth-scrolling') + mainWindow.close() + createWindow() + }) + + ipcMain.on('enableSmoothScrolling', () => { + app.commandLine.appendSwitch('enable-smooth-scrolling') + mainWindow.close() + createWindow() + }) } app.on('window-all-closed', () => { diff --git a/src/renderer/components/theme-settings/theme-settings.js b/src/renderer/components/theme-settings/theme-settings.js index ca3486ee..bc9dbdf9 100644 --- a/src/renderer/components/theme-settings/theme-settings.js +++ b/src/renderer/components/theme-settings/theme-settings.js @@ -5,6 +5,7 @@ import FtSelect from '../ft-select/ft-select.vue' import FtToggleSwitch from '../ft-toggle-switch/ft-toggle-switch.vue' import FtSlider from '../ft-slider/ft-slider.vue' import FtFlexBox from '../ft-flex-box/ft-flex-box.vue' +import FtPrompt from '../ft-prompt/ft-prompt.vue' export default Vue.extend({ name: 'ThemeSettings', @@ -13,7 +14,8 @@ export default Vue.extend({ 'ft-select': FtSelect, 'ft-toggle-switch': FtToggleSwitch, 'ft-slider': FtSlider, - 'ft-flex-box': FtFlexBox + 'ft-flex-box': FtFlexBox, + 'ft-prompt': FtPrompt }, data: function () { return { @@ -24,6 +26,12 @@ export default Vue.extend({ minUiScale: 50, maxUiScale: 300, uiScaleStep: 5, + disableSmoothScrollingToggleValue: false, + showRestartPrompt: false, + restartPromptValues: [ + 'yes', + 'no' + ], baseThemeValues: [ 'light', 'dark', @@ -62,6 +70,21 @@ export default Vue.extend({ return this.$store.getters.getUiScale }, + disableSmoothScrolling: function () { + return this.$store.getters.getDisableSmoothScrolling + }, + + restartPromptMessage: function () { + return this.$t('Settings["The app needs to restart for changes to take effect. Restart and apply change?"]') + }, + + restartPromptNames: function () { + return [ + this.$t('Yes'), + this.$t('No') + ] + }, + baseThemeNames: function () { return [ this.$t('Settings.Theme Settings.Base Theme.Light'), @@ -96,6 +119,7 @@ export default Vue.extend({ this.currentMainColor = localStorage.getItem('mainColor').replace('main', '') this.currentSecColor = localStorage.getItem('secColor').replace('sec', '') this.expandSideBar = localStorage.getItem('expandSideBar') === 'true' + this.disableSmoothScrollingToggleValue = this.disableSmoothScrolling }, methods: { updateBaseTheme: function (theme) { @@ -128,6 +152,30 @@ export default Vue.extend({ this.updateUiScale(parseInt(value)) }, + handleRestartPrompt: function (value) { + this.disableSmoothScrollingToggleValue = value + this.showRestartPrompt = true + }, + + handleSmoothScrolling: function (value) { + this.showRestartPrompt = false + + if (value === null || value === 'no') { + this.disableSmoothScrollingToggleValue = !this.disableSmoothScrollingToggleValue + return + } + + this.updateDisableSmoothScrolling(this.disableSmoothScrollingToggleValue) + + const electron = require('electron') + + if (this.disableSmoothScrollingToggleValue) { + electron.ipcRenderer.send('disableSmoothScrolling') + } else { + electron.ipcRenderer.send('enableSmoothScrolling') + } + }, + updateMainColor: function (color) { const mainColor = `main${color}` const secColor = `sec${this.currentSecColor}` @@ -158,7 +206,8 @@ export default Vue.extend({ ...mapActions([ 'updateBarColor', - 'updateUiScale' + 'updateUiScale', + 'updateDisableSmoothScrolling' ]) } }) diff --git a/src/renderer/components/theme-settings/theme-settings.vue b/src/renderer/components/theme-settings/theme-settings.vue index ea248361..078056e4 100644 --- a/src/renderer/components/theme-settings/theme-settings.vue +++ b/src/renderer/components/theme-settings/theme-settings.vue @@ -16,6 +16,11 @@ :default-value="expandSideBar" @change="handleExpandSideBar" /> + + diff --git a/src/renderer/store/modules/settings.js b/src/renderer/store/modules/settings.js index 6f1109a1..0bfdf8b6 100644 --- a/src/renderer/store/modules/settings.js +++ b/src/renderer/store/modules/settings.js @@ -60,7 +60,7 @@ const state = { useTor: false, proxy: 'SOCKS5://127.0.0.1:9050', debugMode: false, - disctractionFreeMode: false, + disableSmoothScrolling: false, hideWatchedSubs: false, useRssFeeds: false, usingElectron: true, @@ -191,6 +191,10 @@ const getters = { return state.usingElectron }, + getDisableSmoothScrolling: () => { + return state.disableSmoothScrolling + }, + getHideVideoViews: () => { return state.hideVideoViews }, @@ -274,6 +278,9 @@ const actions = { webframe.setZoomFactor(parseInt(result.value) / 100) commit('setUiScale', result.value) break + case 'disableSmoothScrolling': + commit('setDisableSmoothScrolling', result.value) + break case 'hideWatchedSubs': commit('setHideWatchedSubs', result.value) break @@ -584,6 +591,14 @@ const actions = { }) }, + updateDisableSmoothScrolling ({ commit }, disableSmoothScrolling) { + settingsDb.update({ _id: 'disableSmoothScrolling' }, { _id: 'disableSmoothScrolling', value: disableSmoothScrolling }, { upsert: true }, (err, numReplaced) => { + if (!err) { + commit('setDisableSmoothScrolling', disableSmoothScrolling) + } + }) + }, + updateHideVideoViews ({ commit }, hideVideoViews) { settingsDb.update({ _id: 'hideVideoViews' }, { _id: 'hideVideoViews', value: hideVideoViews }, { upsert: true }, (err, numReplaced) => { if (!err) { @@ -740,9 +755,6 @@ const mutations = { setDebugMode (state, debugMode) { state.debugMode = debugMode }, - setDistractionFreeMode (state, disctractionFreeMode) { - state.disctractionFreeMode = disctractionFreeMode - }, setHideWatchedSubs (state, hideWatchedSubs) { state.hideWatchedSubs = hideWatchedSubs }, @@ -752,6 +764,9 @@ const mutations = { setUsingElectron (state, usingElectron) { state.usingElectron = usingElectron }, + setDisableSmoothScrolling (state, disableSmoothScrolling) { + state.disableSmoothScrolling = disableSmoothScrolling + }, setVideoView (state, videoView) { state.videoView = videoView }, diff --git a/static/locales/en-US.yaml b/static/locales/en-US.yaml index 492c2c94..86c10dff 100644 --- a/static/locales/en-US.yaml +++ b/static/locales/en-US.yaml @@ -90,6 +90,7 @@ History: Settings: # On Settings Page Settings: Settings + The app needs to restart for changes to take effect. Restart and apply change?: The app needs to restart for changes to take effect. Restart and apply change? General Settings: General Settings: General Settings Check for Updates: Check for Updates @@ -121,6 +122,7 @@ Settings: Theme Settings: Theme Settings Match Top Bar with Main Color: Match Top Bar with Main Color Expand Side Bar by Default: Expand Side Bar by Default + Disable Smooth Scrolling: Disable Smooth Scrolling UI Scale: UI Scale Base Theme: Base Theme: Base Theme