Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const IpcChannels = {
GET_REPLACE_HTTP_CACHE: 'get-replace-http-cache',
TOGGLE_REPLACE_HTTP_CACHE: 'toggle-replace-http-cache',

GET_DISABLE_HARDWARE_ACCELERATION: 'get-disable-hardware-acceleration',
TOGGLE_DISABLE_HARDWARE_ACCELERATION: 'toggle-disable-hardware-acceleration',

PLAYER_CACHE_GET: 'player-cache-get',
PLAYER_CACHE_SET: 'player-cache-set',

Expand Down
28 changes: 28 additions & 0 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ function runApp() {
app.commandLine.appendSwitch('disable-http-cache')
}

const DISABLE_HARDWARE_ACCELERATION_PATH = `${userDataPath}/experiment-disable-hardware-acceleration`
const disableHardwareAcceleration = existsSync(DISABLE_HARDWARE_ACCELERATION_PATH)
if (disableHardwareAcceleration) {
app.commandLine.appendSwitch('disable-gpu')
}

const PLAYER_CACHE_PATH = `${userDataPath}/player_cache`

// See: https://stackoverflow.com/questions/45570589/electron-protocol-handler-not-working-on-windows
Expand Down Expand Up @@ -1565,6 +1571,28 @@ function runApp() {
relaunch()
})

ipcMain.handle(IpcChannels.GET_DISABLE_HARDWARE_ACCELERATION, (event) => {
if (isFreeTubeUrl(event.senderFrame.url)) {
return disableHardwareAcceleration
}
})

ipcMain.once(IpcChannels.TOGGLE_DISABLE_HARDWARE_ACCELERATION, async (event) => {
if (!isFreeTubeUrl(event.senderFrame.url)) {
return
}

if (disableHardwareAcceleration) {
await asyncFs.rm(DISABLE_HARDWARE_ACCELERATION_PATH)
} else {
// create an empty file
const handle = await asyncFs.open(DISABLE_HARDWARE_ACCELERATION_PATH, 'w')
await handle.close()
}

relaunch()
})

function playerCachePathForKey(key) {
// Remove path separators and period characters,
// to prevent any files outside of the player_cache directory,
Expand Down
11 changes: 11 additions & 0 deletions src/preload/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,21 @@ export default {
return ipcRenderer.invoke(IpcChannels.GET_REPLACE_HTTP_CACHE)
},

/**
* @returns {Promise<boolean>}
*/
getDisableHardwareAcceleration: () => {
return ipcRenderer.invoke(IpcChannels.GET_DISABLE_HARDWARE_ACCELERATION)
},

toggleReplaceHttpCache: () => {
ipcRenderer.send(IpcChannels.TOGGLE_REPLACE_HTTP_CACHE)
},

toggleDisableHardwareAcceleration: () => {
ipcRenderer.send(IpcChannels.TOGGLE_DISABLE_HARDWARE_ACCELERATION)
},

// Allows programmatic toggling of picture-in-picture mode without accompanying user interaction.
// See: https://developer.mozilla.org/en-US/docs/Web/Security/User_activation#transient_activation
requestPiP: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,24 @@
:default-value="replaceHttpCache"
:disabled="replaceHttpCacheLoading"
:tooltip="$t('Tooltips.Experimental Settings.Replace HTTP Cache')"
@change="handleRestartPrompt"
@change="handleToggleReplaceHttpCache"
/>
<FtToggleSwitch
tooltip-position="top"
:label="$t('Settings.Experimental Settings.Disable Hardware Acceleration')"
compact
:default-value="disableHardwareAcceleration"
:disabled="disableHardwareAccelerationLoading"
:tooltip="$t('Tooltips.Experimental Settings.Disable Hardware Acceleration')"
@change="handleToggleDisableHardwareAcceleration"
/>
</FtFlexBox>
<FtPrompt
v-if="showRestartPrompt"
:label="$t('Settings[\'The app needs to restart for changes to take effect. Restart and apply change?\']')"
:option-names="[$t('Yes, Restart'), $t('Cancel')]"
:option-values="['restart', 'cancel']"
@click="handleReplaceHttpCache"
@click="handleRestartPrompt"
/>
</FtSettingsSection>
</template>
Expand All @@ -36,37 +45,59 @@ import FtPrompt from '../FtPrompt/FtPrompt.vue'

const replaceHttpCacheLoading = ref(true)
const replaceHttpCache = ref(false)
let replaceHttpCacheRunningState = null

const disableHardwareAccelerationLoading = ref(true)
const disableHardwareAcceleration = ref(false)
let disableHardwareAccelerationRunningState = null

const showRestartPrompt = ref(false)

onMounted(async () => {
if (process.env.IS_ELECTRON) {
replaceHttpCache.value = await window.ftElectron.getReplaceHttpCache()
[replaceHttpCache.value, disableHardwareAcceleration.value] =
[replaceHttpCacheRunningState, disableHardwareAccelerationRunningState] =
await Promise.all([window.ftElectron.getReplaceHttpCache(), window.ftElectron.getDisableHardwareAcceleration()])
}

replaceHttpCacheLoading.value = false
disableHardwareAccelerationLoading.value = false
})

/**
* @param {boolean} value
*/
function handleRestartPrompt(value) {
function handleToggleReplaceHttpCache(value) {
replaceHttpCache.value = value
showRestartPrompt.value = true
}

/**
* @param {boolean} value
*/
function handleToggleDisableHardwareAcceleration(value) {
disableHardwareAcceleration.value = value
showRestartPrompt.value = true
}

/**
* @param {'restart' | 'cancel' | null} value
*/
function handleReplaceHttpCache(value) {
function handleRestartPrompt(value) {
showRestartPrompt.value = false

if (value === null || value === 'cancel') {
replaceHttpCache.value = !replaceHttpCache.value
replaceHttpCache.value = replaceHttpCacheRunningState
disableHardwareAcceleration.value = disableHardwareAccelerationRunningState
return
}

if (process.env.IS_ELECTRON) {
window.ftElectron.toggleReplaceHttpCache()
if (replaceHttpCache.value !== replaceHttpCacheRunningState) {
window.ftElectron.toggleReplaceHttpCache()
} else if (disableHardwareAcceleration.value !== disableHardwareAccelerationRunningState) {
window.ftElectron.toggleDisableHardwareAcceleration()
}
}
}
</script>
Expand Down
2 changes: 2 additions & 0 deletions static/locales/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ Settings:
Experimental Settings: Experimental
Warning: These settings are experimental, they may cause crashes while enabled. Making backups is highly recommended. Use at your own risk!
Replace HTTP Cache: Replace HTTP Cache
Disable Hardware Acceleration: Disable Hardware Acceleration
Password Dialog:
Password: Password
Enter Password To Unlock: Enter password to unlock settings
Expand Down Expand Up @@ -1106,6 +1107,7 @@ Tooltips:
your subscription feed on startup and when a new window is opened.
Experimental Settings:
Replace HTTP Cache: Disables Electron's disk based HTTP cache and enables a custom in-memory image cache. Will lead to increased RAM usage.
Disable Hardware Acceleration: Disables GPU hardware acceleration. May fix graphical issues, but will probably perform worse.
SponsorBlock Settings:
UseDeArrowTitles: Replace video titles with user-submitted titles from DeArrow.
UseDeArrowThumbnails: Replace video thumbnails with thumbnails from DeArrow.
Expand Down