Skip to content
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const IpcChannels = {
DISABLE_PROXY: 'disable-proxy',
GET_SYSTEM_LOCALE: 'get-system-locale',
GET_NAVIGATION_HISTORY: 'get-navigation-history',
IS_WAYLAND_PLATFORM: 'is-wayland-platform',
STOP_POWER_SAVE_BLOCKER: 'stop-power-save-blocker',
START_POWER_SAVE_BLOCKER: 'start-power-save-blocker',
CREATE_NEW_WINDOW: 'create-new-window',
Expand Down
19 changes: 13 additions & 6 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ function runApp() {
let trayOnMinimize = false
let trayWindows = []
const trayMaximizedWindows = {}
const isTrayOnMinimizeSupported = process.platform !== 'darwin' && (process.platform !== 'linux' || app.commandLine.getSwitchValue('ozone-platform') !== 'wayland')

const userDataPath = app.getPath('userData')

Expand Down Expand Up @@ -346,7 +347,7 @@ function runApp() {
if (!openDeepLinksInNewWindow) {
// Just focus the main window (instead of starting a new instance)
if (mainWindow.isMinimized()) {
if (process.platform !== 'darwin' && trayOnMinimize) {
if (isTrayOnMinimizeSupported && trayOnMinimize) {
trayClick(mainWindow)
} else {
mainWindow.restore()
Expand Down Expand Up @@ -524,7 +525,7 @@ function runApp() {
backendPreference = doc.value
break
case 'hideToTrayOnMinimize':
if (process.platform !== 'darwin') {
if (isTrayOnMinimizeSupported) {
trayOnMinimize = doc.value
}
break
Expand Down Expand Up @@ -1032,7 +1033,7 @@ function runApp() {

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

if (process.platform !== 'darwin') {
if (isTrayOnMinimizeSupported) {
function manageTray(window, removeWindow = false) {
if (tray) {
if (!removeWindow) {
Expand Down Expand Up @@ -1144,7 +1145,7 @@ function runApp() {
return
}

if (process.platform !== 'darwin' && trayOnMinimize && trayWindows.length > 0) {
if (isTrayOnMinimizeSupported && trayOnMinimize && trayWindows.length > 0) {
trayClick(newWindow)
} else {
newWindow.show()
Expand Down Expand Up @@ -1346,6 +1347,12 @@ function runApp() {
}
})

ipcMain.handle(IpcChannels.IS_WAYLAND_PLATFORM, (event) => {
if (isFreeTubeUrl(event.senderFrame.url)) {
return app.commandLine.getSwitchValue('ozone-platform') === 'wayland'
}
})

/**
* @param {import('electron').WebContents} webContents
* @param {string | undefined} [currentPath]
Expand Down Expand Up @@ -1656,7 +1663,7 @@ function runApp() {
await setMenu()
break
case 'hideToTrayOnMinimize':
if (process.platform !== 'darwin') {
if (isTrayOnMinimizeSupported) {
trayOnMinimize = data.value
if (!trayOnMinimize) { showHiddenWindows() }
}
Expand Down Expand Up @@ -2114,7 +2121,7 @@ function runApp() {
})
}

if (process.platform !== 'darwin') {
if (isTrayOnMinimizeSupported) {
app.on('before-quit', () => {
if (tray) { tray.destroy() }
})
Expand Down
7 changes: 7 additions & 0 deletions src/preload/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ export default {
return ipcRenderer.invoke(IpcChannels.GET_SYSTEM_LOCALE)
},

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

/**
* @param {string} path
* @param {Record<string, string> | null | undefined} query
Expand Down
13 changes: 11 additions & 2 deletions src/renderer/components/GeneralSettings/GeneralSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
@change="updateOpenDeepLinksInNewWindow"
/>
<FtToggleSwitch
v-if="!IS_MAC && USING_ELECTRON"
v-if="!IS_MAC && !isLinuxWayland && USING_ELECTRON"
Comment thread
Shadorc marked this conversation as resolved.
:label="t('Settings.General Settings.Minimize to system tray')"
:default-value="hideToTrayOnMinimize"
:compact="true"
Expand Down Expand Up @@ -166,7 +166,7 @@
</template>

<script setup>
import { computed, onBeforeUnmount } from 'vue'
import { computed, onMounted, onBeforeUnmount, ref } from 'vue'
import { useI18n } from '../../composables/use-i18n-polyfill'
import { useRouter } from 'vue-router'

Expand All @@ -190,6 +190,15 @@ const IS_MAC = process.platform === 'darwin'
const { t } = useI18n()
const router = useRouter()

// The 'minimize' event doesn't fire on wayland
// https://github.com/electron/electron/issues/51766
const isLinuxWayland = ref(false)
if (process.env.IS_ELECTRON && process.platform === 'linux') {
onMounted(async () => {
isLinuxWayland.value = await window.ftElectron.isWaylandPlatform()
})
}

/** @type {import('vue').ComputedRef<boolean>} */
const checkForUpdates = computed(() => store.getters.getCheckForUpdates)

Expand Down