mirror of https://github.com/FreeTubeApp/FreeTube
Ask the main process, instead of the file system whether the replace HTTP cache setting is enabled (#4894)
This commit is contained in:
parent
f7206ec7e8
commit
ab60eb264a
|
@ -23,7 +23,10 @@ const IpcChannels = {
|
|||
SYNC_SETTINGS: 'sync-settings',
|
||||
SYNC_HISTORY: 'sync-history',
|
||||
SYNC_PROFILES: 'sync-profiles',
|
||||
SYNC_PLAYLISTS: 'sync-playlists'
|
||||
SYNC_PLAYLISTS: 'sync-playlists',
|
||||
|
||||
GET_REPLACE_HTTP_CACHE: 'get-replace-http-cache',
|
||||
TOGGLE_REPLACE_HTTP_CACHE: 'toggle-replace-http-cache'
|
||||
}
|
||||
|
||||
const DBActions = {
|
||||
|
|
|
@ -10,6 +10,7 @@ import { IpcChannels, DBActions, SyncEvents } from '../constants'
|
|||
import baseHandlers from '../datastores/handlers/base'
|
||||
import { extractExpiryTimestamp, ImageCache } from './ImageCache'
|
||||
import { existsSync } from 'fs'
|
||||
import asyncFs from 'fs/promises'
|
||||
|
||||
import packageDetails from '../../package.json'
|
||||
|
||||
|
@ -177,7 +178,8 @@ function runApp() {
|
|||
// command line switches need to be added before the app ready event first
|
||||
// that means we can't use the normal settings system as that is asynchronous,
|
||||
// doing it synchronously ensures that we add it before the event fires
|
||||
const replaceHttpCache = existsSync(`${app.getPath('userData')}/experiment-replace-http-cache`)
|
||||
const REPLACE_HTTP_CACHE_PATH = `${app.getPath('userData')}/experiment-replace-http-cache`
|
||||
const replaceHttpCache = existsSync(REPLACE_HTTP_CACHE_PATH)
|
||||
if (replaceHttpCache) {
|
||||
// the http cache causes excessive disk usage during video playback
|
||||
// we've got a custom image cache to make up for disabling the http cache
|
||||
|
@ -662,7 +664,7 @@ function runApp() {
|
|||
}
|
||||
})
|
||||
|
||||
ipcMain.once('relaunchRequest', () => {
|
||||
function relaunch() {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
app.exit(parseInt(process.env.FREETUBE_RELAUNCH_EXIT_CODE))
|
||||
return
|
||||
|
@ -693,6 +695,10 @@ function runApp() {
|
|||
}
|
||||
|
||||
app.quit()
|
||||
}
|
||||
|
||||
ipcMain.once('relaunchRequest', () => {
|
||||
relaunch()
|
||||
})
|
||||
|
||||
nativeTheme.on('updated', () => {
|
||||
|
@ -780,6 +786,22 @@ function runApp() {
|
|||
child.unref()
|
||||
})
|
||||
|
||||
ipcMain.handle(IpcChannels.GET_REPLACE_HTTP_CACHE, () => {
|
||||
return replaceHttpCache
|
||||
})
|
||||
|
||||
ipcMain.once(IpcChannels.TOGGLE_REPLACE_HTTP_CACHE, async () => {
|
||||
if (replaceHttpCache) {
|
||||
await asyncFs.rm(REPLACE_HTTP_CACHE_PATH)
|
||||
} else {
|
||||
// create an empty file
|
||||
const handle = await asyncFs.open(REPLACE_HTTP_CACHE_PATH, 'w')
|
||||
await handle.close()
|
||||
}
|
||||
|
||||
relaunch()
|
||||
})
|
||||
|
||||
// ************************************************* //
|
||||
// DB related IPC calls
|
||||
// *********** //
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
import fs from 'fs/promises'
|
||||
import { defineComponent } from 'vue'
|
||||
import FtSettingsSection from '../ft-settings-section/ft-settings-section.vue'
|
||||
import FtFlexBox from '../ft-flex-box/ft-flex-box.vue'
|
||||
import FtToggleSwitch from '../ft-toggle-switch/ft-toggle-switch.vue'
|
||||
import FtPrompt from '../ft-prompt/ft-prompt.vue'
|
||||
import { pathExists } from '../../helpers/filesystem'
|
||||
import { getUserDataPath } from '../../helpers/utils'
|
||||
import { IpcChannels } from '../../../constants'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ExperimentalSettings',
|
||||
|
@ -19,19 +17,16 @@ export default defineComponent({
|
|||
return {
|
||||
replaceHttpCacheLoading: true,
|
||||
replaceHttpCache: false,
|
||||
replaceHttpCachePath: '',
|
||||
showRestartPrompt: false
|
||||
}
|
||||
},
|
||||
mounted: function () {
|
||||
getUserDataPath().then((userData) => {
|
||||
this.replaceHttpCachePath = `${userData}/experiment-replace-http-cache`
|
||||
mounted: async function () {
|
||||
if (process.env.IS_ELECTRON) {
|
||||
const { ipcRenderer } = require('electron')
|
||||
this.replaceHttpCache = await ipcRenderer.invoke(IpcChannels.GET_REPLACE_HTTP_CACHE)
|
||||
}
|
||||
|
||||
pathExists(this.replaceHttpCachePath).then((exists) => {
|
||||
this.replaceHttpCache = exists
|
||||
this.replaceHttpCacheLoading = false
|
||||
})
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
handleRestartPrompt: function (value) {
|
||||
|
@ -39,7 +34,7 @@ export default defineComponent({
|
|||
this.showRestartPrompt = true
|
||||
},
|
||||
|
||||
handleReplaceHttpCache: async function (value) {
|
||||
handleReplaceHttpCache: function (value) {
|
||||
this.showRestartPrompt = false
|
||||
|
||||
if (value === null || value === 'no') {
|
||||
|
@ -47,16 +42,10 @@ export default defineComponent({
|
|||
return
|
||||
}
|
||||
|
||||
if (this.replaceHttpCache) {
|
||||
// create an empty file
|
||||
const handle = await fs.open(this.replaceHttpCachePath, 'w')
|
||||
await handle.close()
|
||||
} else {
|
||||
await fs.rm(this.replaceHttpCachePath)
|
||||
}
|
||||
|
||||
if (process.env.IS_ELECTRON) {
|
||||
const { ipcRenderer } = require('electron')
|
||||
ipcRenderer.send('relaunchRequest')
|
||||
ipcRenderer.send(IpcChannels.TOGGLE_REPLACE_HTTP_CACHE)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue