Main+Renderer+Dev-Runner: Refactor smooth scrolling toggling
Smooth scrolling toggling is currently wonky on runtime, since, most of the time, it doesn't toggle on and off properly. In addition, now that we have multi-window support, the current implementation was somewhat lacking. This commit solves those issues by replacing the existing smooth scrolling related channels with a new generic `relaunchRequest` channel.
This commit is contained in:
parent
bceab435b7
commit
77e743060f
|
@ -23,6 +23,10 @@ if (remoteDebugging) {
|
|||
process.env.RENDERER_REMOTE_DEBUGGING = true
|
||||
}
|
||||
|
||||
// Define exit code for relaunch and set it in the environment
|
||||
const relaunchExitCode = 69
|
||||
process.env.FREETUBE_RELAUNCH_EXIT_CODE = relaunchExitCode
|
||||
|
||||
async function killElectron(pid) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (pid) {
|
||||
|
@ -50,7 +54,13 @@ async function restartElectron() {
|
|||
remoteDebugging ? '--remote-debugging-port=9223' : '',
|
||||
])
|
||||
|
||||
electronProcess.on('exit', (code, signal) => {
|
||||
electronProcess.on('exit', (code, _) => {
|
||||
if (code === relaunchExitCode) {
|
||||
electronProcess = null
|
||||
restartElectron()
|
||||
return
|
||||
}
|
||||
|
||||
if (!manualRestart) process.exit(0)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -294,16 +294,36 @@ function runApp() {
|
|||
}
|
||||
})
|
||||
|
||||
ipcMain.on('disableSmoothScrolling', () => {
|
||||
app.commandLine.appendSwitch('disable-smooth-scrolling')
|
||||
mainWindow.close()
|
||||
createWindow()
|
||||
})
|
||||
ipcMain.on('relaunchRequest', () => {
|
||||
if (isDev) {
|
||||
app.exit(parseInt(process.env.FREETUBE_RELAUNCH_EXIT_CODE))
|
||||
return
|
||||
}
|
||||
|
||||
ipcMain.on('enableSmoothScrolling', () => {
|
||||
app.commandLine.appendSwitch('enable-smooth-scrolling')
|
||||
mainWindow.close()
|
||||
createWindow()
|
||||
// The AppImage and Windows portable formats must be accounted for
|
||||
// because `process.execPath` points at the temporarily extracted
|
||||
// executables, not the executables themselves
|
||||
//
|
||||
// It's possible to detect these formats and identify their
|
||||
// executables' paths by checking the environmental variables
|
||||
const { env: { APPIMAGE, PORTABLE_EXECUTABLE_FILE } } = process
|
||||
|
||||
if (!APPIMAGE) {
|
||||
// If it's a Windows portable, PORTABLE_EXECUTABLE_FILE will
|
||||
// hold a value.
|
||||
// Otherwise, `process.execPath` should be used instead.
|
||||
app.relaunch({
|
||||
args: process.argv.slice(1),
|
||||
execPath: PORTABLE_EXECUTABLE_FILE || process.execPath
|
||||
})
|
||||
} else {
|
||||
// If it's an AppImage, things must be done the "hard way"
|
||||
// `app.relaunch` doesn't work because of FUSE limitations
|
||||
// Spawn a new process using the APPIMAGE env variable
|
||||
cp.spawn(APPIMAGE, { detached: true, stdio: 'ignore' })
|
||||
}
|
||||
|
||||
app.quit()
|
||||
})
|
||||
|
||||
ipcMain.on('enableProxy', (_, url) => {
|
||||
|
|
|
@ -158,16 +158,14 @@ export default Vue.extend({
|
|||
return
|
||||
}
|
||||
|
||||
this.updateDisableSmoothScrolling(this.disableSmoothScrollingToggleValue)
|
||||
this.updateDisableSmoothScrolling(
|
||||
this.disableSmoothScrollingToggleValue
|
||||
).then(() => {
|
||||
// FIXME: No electron safeguard
|
||||
const { ipcRenderer } = require('electron')
|
||||
|
||||
// FIXME: No electron safeguard
|
||||
const { ipcRenderer } = require('electron')
|
||||
|
||||
if (this.disableSmoothScrollingToggleValue) {
|
||||
ipcRenderer.send('disableSmoothScrolling')
|
||||
} else {
|
||||
ipcRenderer.send('enableSmoothScrolling')
|
||||
}
|
||||
ipcRenderer.send('relaunchRequest')
|
||||
})
|
||||
},
|
||||
|
||||
updateMainColor: function (color) {
|
||||
|
|
Loading…
Reference in New Issue