From ac8c7ae1a248bf8aa576ff196fa2d15d5f331329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Digimezzo=20Rapha=C3=ABl?= Date: Thu, 19 Sep 2024 22:29:27 +0200 Subject: [PATCH] More fixes --- main.ts | 8 +++++++- src/app/services/file/file.service.ts | 9 +++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/main.ts b/main.ts index d90f5d45..b5441ce0 100644 --- a/main.ts +++ b/main.ts @@ -212,6 +212,7 @@ function createMainWindow(): void { globalAny.windowHasFrame = windowHasFrame(); globalAny.isMacOS = isMacOS(); + globalAny.macOSOpenedFiles = []; if (isServing) { require('electron-reload')(__dirname, { @@ -433,11 +434,12 @@ try { }); app.on('open-file', (event, path) => { - log.info('[App] [open-file] File opened: ' + path); + log.info('[App] [open-file] Detected file: ' + path); if (mainWindow) { // On macOS, the path of a double-clicked file is not passed as argument. Instead, it is passed as open-file event. // https://stackoverflow.com/questions/50935292/argv1-returns-unexpected-value-when-i-open-a-file-on-double-click-in-electron event.preventDefault(); + globalAny.macOSOpenedFiles.push(path); mainWindow.webContents.send('arguments-received', [path]); } }); @@ -506,6 +508,10 @@ try { app.quit(); }); + ipcMain.on('clear-macOSOpenedFiles', (_) => { + globalAny.macOSOpenedFiles = []; + }); + ipcMain.on('set-full-player', (event: any, arg: any) => { settings.set('playerType', 'full'); if (mainWindow) { diff --git a/src/app/services/file/file.service.ts b/src/app/services/file/file.service.ts index 948bd5d1..01ab498c 100644 --- a/src/app/services/file/file.service.ts +++ b/src/app/services/file/file.service.ts @@ -9,8 +9,9 @@ import { PlaybackServiceBase } from '../playback/playback.service.base'; import { EventListenerServiceBase } from '../event-listener/event-listener.service.base'; import { ApplicationBase } from '../../common/io/application.base'; import { FileValidator } from '../../common/validation/file-validator'; -import {SettingsBase} from "../../common/settings/settings.base"; -import {A} from "@angular/cdk/keycodes"; +import { SettingsBase } from '../../common/settings/settings.base'; +import { A } from '@angular/cdk/keycodes'; +import { IpcProxyBase } from '../../common/io/ipc-proxy.base'; @Injectable() export class FileService implements FileServiceBase { @@ -22,6 +23,7 @@ export class FileService implements FileServiceBase { private trackModelFactory: TrackModelFactory, private application: ApplicationBase, private fileValidator: FileValidator, + private ipcProxy: IpcProxyBase, private settings: SettingsBase, private logger: Logger, ) { @@ -42,6 +44,9 @@ export class FileService implements FileServiceBase { public hasPlayableFilesAsParameters(): boolean { const parameters: string[] = this.application.getParameters(); + const macOOParameters: string[] = this.application.getGlobal('macOSOpenedFiles') as string[]; + parameters.push(...macOOParameters); + this.ipcProxy.sendToMainProcess('clear-macOSOpenedFiles', null); return this.hasPlayableFilesAsGivenParameters(parameters); }