Skip to content

Commit

Permalink
Updated code so that clicking "Open with Photo Location Map" in the E…
Browse files Browse the repository at this point in the history
…xplorer's context menu starts the app and opens the path.
  • Loading branch information
TomoyukiAota committed Nov 18, 2024
1 parent 0002725 commit e1d8a18
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
7 changes: 5 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 0 additions & 12 deletions src/app/open-after-launch/open-after-launch-if-needed.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
}
25 changes: 25 additions & 0 deletions src/app/shared/service/open-after-launch.service.ts
Original file line number Diff line number Diff line change
@@ -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<CommandLineOptions> {
return await ipcRenderer.invoke(IpcConstants.CommandLineOptions.Get);
}
}

0 comments on commit e1d8a18

Please sign in to comment.