Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
digimezzo committed Sep 19, 2024
1 parent 0fa8e59 commit ac8c7ae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 7 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ function createMainWindow(): void {

globalAny.windowHasFrame = windowHasFrame();
globalAny.isMacOS = isMacOS();
globalAny.macOSOpenedFiles = [];

if (isServing) {
require('electron-reload')(__dirname, {
Expand Down Expand Up @@ -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]);
}
});
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 7 additions & 2 deletions src/app/services/file/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
) {
Expand All @@ -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);
}
Expand Down

0 comments on commit ac8c7ae

Please sign in to comment.