From e1d8a1858562fa2be802d7934c3507d86fac254c Mon Sep 17 00:00:00 2001 From: Tomoyuki Aota Date: Tue, 19 Nov 2024 02:38:40 +0900 Subject: [PATCH] Updated code so that clicking "Open with Photo Location Map" in the Explorer's context menu starts the app and opens the path. --- src/app/app.component.ts | 7 ++++-- .../open-after-launch-if-needed.ts | 12 --------- .../add-registry-for-explorer-context-menu.ts | 6 ++--- .../service/open-after-launch.service.ts | 25 +++++++++++++++++++ 4 files changed, 33 insertions(+), 17 deletions(-) delete mode 100644 src/app/open-after-launch/open-after-launch-if-needed.ts create mode 100644 src/app/shared/service/open-after-launch.service.ts diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 7254b210..90479182 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -11,8 +11,8 @@ import { } from '../global-variables/global-variable-for-internal-use-in-renderer'; import { AboutBoxComponent } from './about-box/about-box.component'; import { DirectoryTreeViewSelectionService } from './directory-tree-view/directory-tree-view-selection.service'; -import { openAfterLaunchIfNeeded } from './open-after-launch/open-after-launch-if-needed'; import { SettingsDialogComponent } from './settings-dialog/settings-dialog.component'; +import { OpenAfterLaunchService } from './shared/service/open-after-launch.service'; import { PhotoSelectionHistoryService } from './shared/service/photo-selection-history.service'; import { WelcomeDialogComponent } from './welcome-dialog/welcome-dialog.component'; import { WelcomeDialogAtAppLaunchService } from './welcome-dialog/welcome-dialog-at-app-launch/welcome-dialog-at-app-launch.service'; @@ -26,6 +26,7 @@ export class AppComponent implements OnInit, AfterViewInit, OnDestroy { constructor(private dialog: MatDialog, private directoryTreeViewSelectionService: DirectoryTreeViewSelectionService, private ngZone: NgZone, + private openAfterLaunchService: OpenAfterLaunchService, private photoSelectionHistoryService: PhotoSelectionHistoryService, private translate: TranslateService, private welcomeDialogAtAppLaunchService: WelcomeDialogAtAppLaunchService) { @@ -54,7 +55,9 @@ export class AppComponent implements OnInit, AfterViewInit, OnDestroy { public ngAfterViewInit(): void { this.welcomeDialogAtAppLaunchService.showWelcomeDialogIfUserHasNotClickedOk(); - openAfterLaunchIfNeeded(); + + // noinspection JSIgnoredPromiseFromCall + this.openAfterLaunchService.openAfterLaunchIfNeeded(); } public ngOnDestroy(): void { diff --git a/src/app/open-after-launch/open-after-launch-if-needed.ts b/src/app/open-after-launch/open-after-launch-if-needed.ts deleted file mode 100644 index 615a7cc6..00000000 --- a/src/app/open-after-launch/open-after-launch-if-needed.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { ipcRenderer } from 'electron'; -import { CommandLineOptions } from '../../../src-shared/command-line-options/command-line-options'; -import { IpcConstants } from '../../../src-shared/ipc/ipc-constants'; - -export async function openAfterLaunchIfNeeded() { - const commandLineOptions = await getCommandLineOptionsFromMainProcess(); - console.log('commandLineOptions', commandLineOptions); -} - -async function getCommandLineOptionsFromMainProcess(): Promise { - return await ipcRenderer.invoke(IpcConstants.CommandLineOptions.Get); -} diff --git a/src/app/settings-dialog/os-settings/add-registry-for-explorer-context-menu.ts b/src/app/settings-dialog/os-settings/add-registry-for-explorer-context-menu.ts index 4d8976c9..6482c409 100644 --- a/src/app/settings-dialog/os-settings/add-registry-for-explorer-context-menu.ts +++ b/src/app/settings-dialog/os-settings/add-registry-for-explorer-context-menu.ts @@ -7,17 +7,17 @@ export async function addRegistryForExplorerContextMenu() { // Add the Explorer's context menu item for files await Registry.set('HKEY_CURRENT_USER\\Software\\Classes\\*\\shell\\OpenWithPhotoLocationMap', '', 'Open with &Photo Location Map'); await Registry.set('HKEY_CURRENT_USER\\Software\\Classes\\*\\shell\\OpenWithPhotoLocationMap', 'icon', photoLocationMapExePath); - await Registry.set('HKEY_CURRENT_USER\\Software\\Classes\\*\\shell\\OpenWithPhotoLocationMap\\command', '', `${photoLocationMapExePath} "%1"`); + await Registry.set('HKEY_CURRENT_USER\\Software\\Classes\\*\\shell\\OpenWithPhotoLocationMap\\command', '', `${photoLocationMapExePath} --open "%1"`); // Add the Explorer's context menu item for directories await Registry.set('HKEY_CURRENT_USER\\Software\\Classes\\Directory\\shell\\OpenWithPhotoLocationMap', '', 'Open with &Photo Location Map'); await Registry.set('HKEY_CURRENT_USER\\Software\\Classes\\Directory\\shell\\OpenWithPhotoLocationMap', 'icon', photoLocationMapExePath); - await Registry.set('HKEY_CURRENT_USER\\Software\\Classes\\Directory\\shell\\OpenWithPhotoLocationMap\\command', '', `${photoLocationMapExePath} "%1"`); + await Registry.set('HKEY_CURRENT_USER\\Software\\Classes\\Directory\\shell\\OpenWithPhotoLocationMap\\command', '', `${photoLocationMapExePath} --open "%1"`); // Add the Explorer's context menu item for the background await Registry.set('HKEY_CURRENT_USER\\Software\\Classes\\Directory\\Background\\shell\\OpenWithPhotoLocationMap', '', 'Open with &Photo Location Map'); await Registry.set('HKEY_CURRENT_USER\\Software\\Classes\\Directory\\Background\\shell\\OpenWithPhotoLocationMap', 'icon', photoLocationMapExePath); - await Registry.set('HKEY_CURRENT_USER\\Software\\Classes\\Directory\\Background\\shell\\OpenWithPhotoLocationMap\\command', '', `${photoLocationMapExePath} "%V"`); + await Registry.set('HKEY_CURRENT_USER\\Software\\Classes\\Directory\\Background\\shell\\OpenWithPhotoLocationMap\\command', '', `${photoLocationMapExePath} --open "%V"`); // TODO: Add logging and analytics } diff --git a/src/app/shared/service/open-after-launch.service.ts b/src/app/shared/service/open-after-launch.service.ts new file mode 100644 index 00000000..5bdd18fe --- /dev/null +++ b/src/app/shared/service/open-after-launch.service.ts @@ -0,0 +1,25 @@ +import { Injectable } from '@angular/core'; +import { ipcRenderer } from 'electron'; +import { CommandLineOptions } from '../../../../src-shared/command-line-options/command-line-options'; +import { IpcConstants } from '../../../../src-shared/ipc/ipc-constants'; +import { OpenPathService } from './open-path.service'; + +@Injectable({ + providedIn: 'root' +}) +export class OpenAfterLaunchService { + constructor(private openPathService: OpenPathService) { } + + public async openAfterLaunchIfNeeded() { + const commandLineOptions = await this.getCommandLineOptionsFromMainProcess(); + console.log('commandLineOptions', commandLineOptions); + const path = commandLineOptions.open; + if (path) { + await this.openPathService.open(path); + } + } + + private async getCommandLineOptionsFromMainProcess(): Promise { + return await ipcRenderer.invoke(IpcConstants.CommandLineOptions.Get); + } +}