yout icon indicating copy to clipboard operation
yout copied to clipboard

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

Open Xalalau opened this issue 6 years ago • 1 comments

It's an Electron bug: https://github.com/electron/electron/issues/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

Xalalau avatar Dec 02 '18 01:12 Xalalau

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

daltonmenezes avatar Dec 02 '18 02:12 daltonmenezes