diff --git a/packages/core/src/browser/opener-service.ts b/packages/core/src/browser/opener-service.ts index 029798a4da182..d4f58f44a6fac 100644 --- a/packages/core/src/browser/opener-service.ts +++ b/packages/core/src/browser/opener-service.ts @@ -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'; @@ -109,23 +109,6 @@ export class DefaultOpenerService implements OpenerService { protected readonly handlersProvider: ContributionProvider ) { } - @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(); diff --git a/packages/core/src/electron-browser/electron-uri-handler.ts b/packages/core/src/electron-browser/electron-uri-handler.ts new file mode 100644 index 0000000000000..c3fdd3a993dae --- /dev/null +++ b/packages/core/src/electron-browser/electron-uri-handler.ts @@ -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; + }); + } +} diff --git a/packages/core/src/electron-browser/window/electron-window-module.ts b/packages/core/src/electron-browser/window/electron-window-module.ts index 78f490c1c98db..b4edcee810a10 100644 --- a/packages/core/src/electron-browser/window/electron-window-module.ts +++ b/packages/core/src/electron-browser/window/electron-window-module.ts @@ -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 => @@ -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();