Skip to content

Commit

Permalink
Move electron-specific code out of DefaultOpenerService
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Mäder <[email protected]>
  • Loading branch information
tsmaeder committed Jul 25, 2024
1 parent 465bdfc commit b5bad35
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 18 deletions.
19 changes: 1 addition & 18 deletions packages/core/src/browser/opener-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************

import { named, injectable, inject, postConstruct } from 'inversify';
import { named, injectable, inject } from 'inversify';
import URI from '../common/uri';
import { ContributionProvider, Prioritizeable, MaybePromise, Emitter, Event, Disposable } from '../common';

Expand Down Expand Up @@ -109,23 +109,6 @@ export class DefaultOpenerService implements OpenerService {
protected readonly handlersProvider: ContributionProvider<OpenHandler>
) { }

@postConstruct()
init(): void {
window.electronTheiaCore.setOpenUrlHandler(async url => {
const uri = new URI(url);
try {
const handler = await this.getOpener(uri);
if (handler) {
await handler.open(uri);
return true;
}
} catch (e) {
// no handler
}
return false;
});
}

addHandler(openHandler: OpenHandler): Disposable {
this.customEditorOpenHandlers.push(openHandler);
this.onDidChangeOpenersEmitter.fire();
Expand Down
42 changes: 42 additions & 0 deletions packages/core/src/electron-browser/electron-uri-handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// *****************************************************************************
// Copyright (C) 2024 STMicroelectronics and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************

import { FrontendApplicationContribution, OpenerService } from '../browser';

import { injectable, inject } from 'inversify';
import { URI } from '../common';

@injectable()
export class ElectronUriHandlerContribution implements FrontendApplicationContribution {
@inject(OpenerService)
protected readonly openenerService: OpenerService;

initialize(): void {
window.electronTheiaCore.setOpenUrlHandler(async url => {
const uri = new URI(url);
try {
const handler = await this.openenerService.getOpener(uri);
if (handler) {
await handler.open(uri);
return true;
}
} catch (e) {
// no handler
}
return false;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { ElectronSecondaryWindowService } from './electron-secondary-window-serv
import { bindWindowPreferences } from './electron-window-preferences';
import { ElectronWindowService } from './electron-window-service';
import { ExternalAppOpenHandler } from './external-app-open-handler';
import { ElectronUriHandlerContribution } from '../electron-uri-handler';

export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(ElectronMainWindowService).toDynamicValue(context =>
Expand All @@ -37,6 +38,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
bindWindowPreferences(bind);
bind(WindowService).to(ElectronWindowService).inSingletonScope();
bind(FrontendApplicationContribution).toService(WindowService);
bind(ElectronUriHandlerContribution).toSelf().inSingletonScope();
bind(FrontendApplicationContribution).toService(ElectronUriHandlerContribution);
bind(ClipboardService).to(ElectronClipboardService).inSingletonScope();
rebind(FrontendApplicationStateService).to(ElectronFrontendApplicationStateService).inSingletonScope();
bind(SecondaryWindowService).to(ElectronSecondaryWindowService).inSingletonScope();
Expand Down

0 comments on commit b5bad35

Please sign in to comment.