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