Beta release - Prefer OpenGL on macOS and more

This commit is contained in:
Anirudh Sevugan 2025-06-17 17:06:21 -05:00 committed by GitHub
parent cf6cbefca7
commit 840ef8935d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,10 +3,14 @@ const path = require('path');
const fs = require('fs');
const os = require('os');
const { pathToFileURL } = require("url");
var didRegisterShortcuts = false;
let didRegisterShortcuts = false;
app.commandLine.appendSwitch('disable-features', 'Metal');
app.commandLine.appendSwitch('use-gl', 'desktop');
let mainWindow;
// Handle file opening from Finder or File Explorer
app.on('open-file', (event, filePath) => {
event.preventDefault();
@ -15,25 +19,25 @@ app.on('open-file', (event, filePath) => {
const openFile = (filePath) => {
app.whenReady().then(() => {
const fileURL = pathToFileURL(filePath).href;
if (mainWindow) {
const fileURL = pathToFileURL(filePath).href; // ✅ Convert and encode file path
if (mainWindow.webContents.isLoading()) {
mainWindow.webContents.once("did-finish-load", () => {
mainWindow.webContents.send("play-media", fileURL);
});
} else {
const fileURL = pathToFileURL(filePath).href; // ✅ Convert and encode file path
mainWindow.webContents.send("play-media", fileURL);
}
} else {
createWindow(() => {
const fileURL = pathToFileURL(filePath).href; // ✅ Convert and encode file path
mainWindow.webContents.send("play-media", fileURL);
});
}
});
};
const takeSnapshot = async () => {
if (!mainWindow) return;
@ -81,6 +85,16 @@ const createWindow = (onReadyCallback) => {
mainWindow.loadFile("index.html");
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.webContents.executeJavaScript("navigator.userAgent").then(ua => {
console.log("User Agent:", ua);
});
mainWindow.webContents.executeJavaScript("chrome.loadTimes ? chrome.loadTimes() : {}").then(loadTimes => {
console.log("GPU Info (legacy):", loadTimes);
});
});
mainWindow.once("ready-to-show", () => {
if (onReadyCallback) onReadyCallback();
});
@ -103,6 +117,7 @@ const setupContextMenu = () => {
});
};
// Set up application menu
const setupMenu = () => {
const menu = Menu.getApplicationMenu();
@ -206,7 +221,7 @@ app.whenReady().then(() => {
openFileSafely(filePath);
});
if (process.platform === "win32") {
if (["win32", "linux"].includes(process.platform)) {
if (!app.requestSingleInstanceLock()) {
app.quit();
} else {
@ -225,9 +240,8 @@ function openFileSafely(filePath) {
hasOpenedFile = true;
if (mainWindow?.webContents) {
mainWindow.webContents.once("did-finish-load", () => {
mainWindow.webContents.send("play-media", filePath);
});
const winFileURL = pathToFileURL(filePath).href; // ✅ Convert and encode file path
mainWindow.webContents.send("play-media", winFileURL);
}
setTimeout(() => (hasOpenedFile = false), 1000);
@ -238,10 +252,6 @@ function isValidFileArg(arg) {
return arg && !arg.startsWith('-') && !arg.includes('electron') && fs.existsSync(arg);
}
app.on("window-all-closed", () => {
globalShortcut.unregisterAll();
app.quit();