mirror of
https://github.com/A-Star100/simpliplay-desktop.git
synced 2025-09-17 22:29:38 +00:00
Update main.js
This commit is contained in:
parent
15f6cd586b
commit
d6acb8bb62
@ -6,7 +6,7 @@ const { pathToFileURL } = require("url");
|
||||
const { checkForUpdate } = require('./updateChecker');
|
||||
let gpuAccel = "";
|
||||
let didRegisterShortcuts = false;
|
||||
let version = "2.0.0.2"
|
||||
let version = "2.0.3.0"
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
if (process.argv.includes('--use-gl')) {
|
||||
@ -261,8 +261,15 @@ app.whenReady().then(() => {
|
||||
createWindow();
|
||||
setupMenu();
|
||||
|
||||
|
||||
mainWindow?.on("focus", () => {
|
||||
if (!didRegisterShortcuts) setupShortcuts();
|
||||
});
|
||||
|
||||
mainWindow?.on("blur", unregisterShortcuts);
|
||||
|
||||
// Store but delay opening
|
||||
const args = process.argv.slice(1);
|
||||
const args = process.argv.slice(2);
|
||||
const fileArg = args.find(isValidFileArg);
|
||||
|
||||
if (fileArg) {
|
||||
@ -271,12 +278,6 @@ app.whenReady().then(() => {
|
||||
});
|
||||
}
|
||||
|
||||
mainWindow?.on("focus", () => {
|
||||
if (!didRegisterShortcuts) setupShortcuts();
|
||||
});
|
||||
|
||||
mainWindow?.on("blur", unregisterShortcuts);
|
||||
|
||||
app.on("open-file", (event, filePath) => {
|
||||
event.preventDefault();
|
||||
openFileSafely(filePath);
|
||||
@ -300,6 +301,8 @@ function openFileSafely(filePath) {
|
||||
if (!hasOpenedFile) {
|
||||
hasOpenedFile = true;
|
||||
|
||||
const absPath = path.resolve(filePath); // ensure absolute path
|
||||
|
||||
if (mainWindow?.webContents) {
|
||||
const winFileURL = pathToFileURL(filePath).href; // ✅ Convert and encode file path
|
||||
mainWindow.webContents.send("play-media", winFileURL);
|
||||
@ -310,7 +313,10 @@ function openFileSafely(filePath) {
|
||||
}
|
||||
|
||||
function isValidFileArg(arg) {
|
||||
return arg && !arg.startsWith('-') && !arg.includes('electron') && fs.existsSync(arg);
|
||||
if (!arg || arg.startsWith('-') || arg.includes('electron')) return false;
|
||||
|
||||
const resolvedPath = path.resolve(arg); // resolves relative paths to absolute
|
||||
return fs.existsSync(resolvedPath);
|
||||
}
|
||||
|
||||
app.on("window-all-closed", () => {
|
||||
|
Loading…
Reference in New Issue
Block a user