Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows "always on top" not working on Linux (+quickfix) #8

Closed
Xalalau opened this issue Dec 2, 2018 · 1 comment
Closed

Windows "always on top" not working on Linux (+quickfix) #8

Xalalau opened this issue Dec 2, 2018 · 1 comment

Comments

@Xalalau
Copy link

Xalalau commented Dec 2, 2018

It's an Electron bug: electron/electron#12445

We can fix the problem by editing "[...]/resources/app/main.js" with this code:

'use strict';
const electron = require('electron');
const {
	app,
	globalShortcut
} = electron;
const {
	BrowserWindow,
	ipcMain
} = electron;
const nativeImage = require('electron').nativeImage;
if (process.platform == 'linux') {
	app.disableHardwareAcceleration();
}
ipcMain.on('close-main-window', () => {
	app.quit();
});
let iconApp = nativeImage.createFromPath(__dirname + '/app/assets/ico/icon.png')
let splashWindow = null;
app.on('window-all-closed', () => {
	if (process.platform != 'darwin')
		app.quit();
});
app.on('ready', () => {

	// AlwaysOnTop Electron bug: https://github.com/electron/electron/issues/12445

	splashWindow = new BrowserWindow({
		title: 'Yout',
		icon: iconApp,
		width: 400,
		height: 400,
		backgroundColor: '#262626',
		center: true,
		movable: true,
		resizable: false,
		// alwaysOnTop: true, // Disabled
		toolbar: false,
		frame: false
	});
		// Workaround: keep this window always on top
		splashWindow.setAlwaysOnTop(true);
		// -----
	var mainWindow = new BrowserWindow({
		title: 'Yout',
		icon: iconApp,
		minWidth: 266,
		minHeight: 150,
		backgroundColor: '#000000',
		center: true,
		resizable: true,
		movable: true,
		// alwaysOnTop: true, // Disabled
		frame: false,
		toolbar: false,
		show: false,
	});
	splashWindow.setMenu(null);
	splashWindow.loadURL('file://' + __dirname + '/app/splash.html');
	ipcMain.on('show-yout-window', () => {
		splashWindow.destroy();
		mainWindow.show();
		// Workaround: keep this window always on top
		mainWindow.setAlwaysOnTop(true);
		// -----
		splashWindow = null;
	});
	mainWindow.setMenu(null);
	mainWindow.isResizable(true);
	mainWindow.loadURL('file://' + __dirname + '/app/index.html');

	function enterFullScreen() {
		if (mainWindow.isFullScreen() == false) {
			mainWindow.setFullScreen(true);
			mainWindow.webContents.send('fullscreen');
		}
	}

	function exitFullScreen() {
		if (mainWindow.isFullScreen()) {
			mainWindow.setFullScreen(false);
			mainWindow.webContents.send('showDecoration');
			mainWindow.webContents.send('killfullscreen');
		}
	}
	mainWindow.on('focus', () => {
		mainWindow.webContents.send('showDecoration');
		globalShortcut.register('Esc', () => {
			if (mainWindow.isFullScreen()) {
				exitFullScreen();
			}
		});
		globalShortcut.register('Enter', () => {
			if (mainWindow.isFullScreen()) {
				exitFullScreen();
			} else {
				enterFullScreen();
			}
		});
	});
	mainWindow.on('blur', () => {
		mainWindow.webContents.send('hideDecoration');
		globalShortcut.unregister('Esc');
		globalShortcut.unregister('Enter');
	});
	ipcMain.on('minimize-main-window', () => {
		mainWindow.minimize();
	});
	ipcMain.on('exit-fullscreen', () => {
		mainWindow.setFullScreen(false);
		mainWindow.webContents.send('showDecoration');
		mainWindow.webContents.send('killfullscreen');
	});
	ipcMain.on('maximize-main-window', () => {
		if (mainWindow.isFullScreen()) {
			exitFullScreen();
		} else {
			enterFullScreen();
		}
	});
	mainWindow.on('closed', () => {
		mainWindow = null;
		app.quit();
	});
	ipcMain.on('update-playlist', () => {
		mainWindow.setSize(800, 600);
		mainWindow.reload();
	});
	ipcMain.on('create-about-window', () => {
		let aboutWindow = new BrowserWindow({
			title: 'Yout',
			icon: iconApp,
			width: 400,
			height: 459,
			backgroundColor: '#262626',
			center: true,
			resizable: false,
			movable: true,
			// alwaysOnTop: true, // Disabled
			frame: false,
			show: false
		});
		aboutWindow.setMenu(null);
		aboutWindow.loadURL('file://' + __dirname + '/app/about.html');
		aboutWindow.show();
		// Workaround: keep this window always on top
		aboutWindow.setAlwaysOnTop(true);
		// -----
	});
	ipcMain.on('create-playlist-window', () => {
		let managePlaylistsWindow = new BrowserWindow({
			title: 'Yout',
			icon: iconApp,
			width: 400,
			height: 400,
			backgroundColor: '#262626',
			center: true,
			resizable: false,
			movable: true,
			// alwaysOnTop: true, // Disabled
			frame: false,
			show: false
		});
		managePlaylistsWindow.setMenu(null);
		managePlaylistsWindow.loadURL('file://' + __dirname + '/app/managePlaylists.html');
		managePlaylistsWindow.show();
		// Workaround: keep this window always on top
		managePlaylistsWindow.setAlwaysOnTop(true);
		// -----
	});
	ipcMain.on('create-help-window', () => {
		let helpWindow = new BrowserWindow({
			title: 'Yout',
			icon: iconApp,
			width: 770,
			height: 500,
			backgroundColor: '#262626',
			center: true,
			resizable: false,
			movable: true,
			// alwaysOnTop: true, // Disabled
			frame: false,
			show: false
		});
		helpWindow.setMenu(null);
		helpWindow.loadURL('file://' + __dirname + '/app/help.html');
		helpWindow.show();
		// Workaround: keep this window always on top
		helpWindow.setAlwaysOnTop(true);
		// -----
	});
});

Cheers

@daltonmenezes
Copy link
Member

@Xalalau , thx man, I'll include it on the next version of Yout if electron doesn't fix that bug until then.

@daltonmenezes daltonmenezes pinned this issue Dec 21, 2018
@Xalalau Xalalau closed this as completed Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants