Skip to content

Commit 5ce9797

Browse files
authored
Fix: Hide 'Minimize to system tray' setting on Wayland (FreeTubeApp#9208)
* Add tooltip to 'Minimize to system tray' setting indicating that it is not available on Wayland * Only show tooltip for linux * Hide 'Minimize to system tray' setting on Wayland * Code clean-up * Replace getCmdSwitchValue with getWaylandPlatform * Add migration script to disable 'hideToTrayOnMinimize' setting if it was enabled on Wayland * Revert "Add migration script to disable 'hideToTrayOnMinimize' setting if it was enabled on Wayland" This reverts commit 5e262c7. * Rename getWayland to isWayland * Apply suggestion * Skip tray code paths for wayland * Revert addition of yarn.lock file
1 parent d2d072d commit 5ce9797

4 files changed

Lines changed: 32 additions & 8 deletions

File tree

src/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const IpcChannels = {
44
DISABLE_PROXY: 'disable-proxy',
55
GET_SYSTEM_LOCALE: 'get-system-locale',
66
GET_NAVIGATION_HISTORY: 'get-navigation-history',
7+
IS_WAYLAND_PLATFORM: 'is-wayland-platform',
78
STOP_POWER_SAVE_BLOCKER: 'stop-power-save-blocker',
89
START_POWER_SAVE_BLOCKER: 'start-power-save-blocker',
910
CREATE_NEW_WINDOW: 'create-new-window',

src/main/index.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ function runApp() {
290290
let trayOnMinimize = false
291291
let trayWindows = []
292292
const trayMaximizedWindows = {}
293+
const isTrayOnMinimizeSupported = process.platform !== 'darwin' && (process.platform !== 'linux' || app.commandLine.getSwitchValue('ozone-platform') !== 'wayland')
293294

294295
const userDataPath = app.getPath('userData')
295296

@@ -346,7 +347,7 @@ function runApp() {
346347
if (!openDeepLinksInNewWindow) {
347348
// Just focus the main window (instead of starting a new instance)
348349
if (mainWindow.isMinimized()) {
349-
if (process.platform !== 'darwin' && trayOnMinimize) {
350+
if (isTrayOnMinimizeSupported && trayOnMinimize) {
350351
trayClick(mainWindow)
351352
} else {
352353
mainWindow.restore()
@@ -524,7 +525,7 @@ function runApp() {
524525
backendPreference = doc.value
525526
break
526527
case 'hideToTrayOnMinimize':
527-
if (process.platform !== 'darwin') {
528+
if (isTrayOnMinimizeSupported) {
528529
trayOnMinimize = doc.value
529530
}
530531
break
@@ -1032,7 +1033,7 @@ function runApp() {
10321033

10331034
// endregion Ensure child windows use same options since electron 14
10341035

1035-
if (process.platform !== 'darwin') {
1036+
if (isTrayOnMinimizeSupported) {
10361037
function manageTray(window, removeWindow = false) {
10371038
if (tray) {
10381039
if (!removeWindow) {
@@ -1144,7 +1145,7 @@ function runApp() {
11441145
return
11451146
}
11461147

1147-
if (process.platform !== 'darwin' && trayOnMinimize && trayWindows.length > 0) {
1148+
if (isTrayOnMinimizeSupported && trayOnMinimize && trayWindows.length > 0) {
11481149
trayClick(newWindow)
11491150
} else {
11501151
newWindow.show()
@@ -1346,6 +1347,12 @@ function runApp() {
13461347
}
13471348
})
13481349

1350+
ipcMain.handle(IpcChannels.IS_WAYLAND_PLATFORM, (event) => {
1351+
if (isFreeTubeUrl(event.senderFrame.url)) {
1352+
return app.commandLine.getSwitchValue('ozone-platform') === 'wayland'
1353+
}
1354+
})
1355+
13491356
/**
13501357
* @param {import('electron').WebContents} webContents
13511358
* @param {string | undefined} [currentPath]
@@ -1656,7 +1663,7 @@ function runApp() {
16561663
await setMenu()
16571664
break
16581665
case 'hideToTrayOnMinimize':
1659-
if (process.platform !== 'darwin') {
1666+
if (isTrayOnMinimizeSupported) {
16601667
trayOnMinimize = data.value
16611668
if (!trayOnMinimize) { showHiddenWindows() }
16621669
}
@@ -2114,7 +2121,7 @@ function runApp() {
21142121
})
21152122
}
21162123

2117-
if (process.platform !== 'darwin') {
2124+
if (isTrayOnMinimizeSupported) {
21182125
app.on('before-quit', () => {
21192126
if (tray) { tray.destroy() }
21202127
})

src/preload/interface.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ export default {
3030
return ipcRenderer.invoke(IpcChannels.GET_SYSTEM_LOCALE)
3131
},
3232

33+
/**
34+
* @returns {Promise<boolean>}
35+
*/
36+
isWaylandPlatform: () => {
37+
return ipcRenderer.invoke(IpcChannels.IS_WAYLAND_PLATFORM)
38+
},
39+
3340
/**
3441
* @param {string} path
3542
* @param {Record<string, string> | null | undefined} query

src/renderer/components/GeneralSettings/GeneralSettings.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
@change="updateOpenDeepLinksInNewWindow"
4343
/>
4444
<FtToggleSwitch
45-
v-if="!IS_MAC && USING_ELECTRON"
45+
v-if="!IS_MAC && !isLinuxWayland && USING_ELECTRON"
4646
:label="t('Settings.General Settings.Minimize to system tray')"
4747
:default-value="hideToTrayOnMinimize"
4848
:compact="true"
@@ -166,7 +166,7 @@
166166
</template>
167167

168168
<script setup>
169-
import { computed, onBeforeUnmount } from 'vue'
169+
import { computed, onMounted, onBeforeUnmount, ref } from 'vue'
170170
import { useI18n } from '../../composables/use-i18n-polyfill'
171171
import { useRouter } from 'vue-router'
172172
@@ -190,6 +190,15 @@ const IS_MAC = process.platform === 'darwin'
190190
const { t } = useI18n()
191191
const router = useRouter()
192192
193+
// The 'minimize' event doesn't fire on wayland
194+
// https://github.com/electron/electron/issues/51766
195+
const isLinuxWayland = ref(false)
196+
if (process.env.IS_ELECTRON && process.platform === 'linux') {
197+
onMounted(async () => {
198+
isLinuxWayland.value = await window.ftElectron.isWaylandPlatform()
199+
})
200+
}
201+
193202
/** @type {import('vue').ComputedRef<boolean>} */
194203
const checkForUpdates = computed(() => store.getters.getCheckForUpdates)
195204

0 commit comments

Comments
 (0)