Skip to content

Commit 3406d23

Browse files
committed
Move electron-specific code out of DefaultOpenerService
Signed-off-by: Thomas Mäder <[email protected]>
1 parent 8c86ee0 commit 3406d23

File tree

3 files changed

+46
-18
lines changed

3 files changed

+46
-18
lines changed

packages/core/src/browser/opener-service.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
1515
// *****************************************************************************
1616

17-
import { named, injectable, inject, postConstruct } from 'inversify';
17+
import { named, injectable, inject } from 'inversify';
1818
import URI from '../common/uri';
1919
import { ContributionProvider, Prioritizeable, MaybePromise, Emitter, Event, Disposable } from '../common';
2020

@@ -109,23 +109,6 @@ export class DefaultOpenerService implements OpenerService {
109109
protected readonly handlersProvider: ContributionProvider<OpenHandler>
110110
) { }
111111

112-
@postConstruct()
113-
init(): void {
114-
window.electronTheiaCore.setOpenUrlHandler(async url => {
115-
const uri = new URI(url);
116-
try {
117-
const handler = await this.getOpener(uri);
118-
if (handler) {
119-
await handler.open(uri);
120-
return true;
121-
}
122-
} catch (e) {
123-
// no handler
124-
}
125-
return false;
126-
});
127-
}
128-
129112
addHandler(openHandler: OpenHandler): Disposable {
130113
this.customEditorOpenHandlers.push(openHandler);
131114
this.onDidChangeOpenersEmitter.fire();
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// *****************************************************************************
2+
// Copyright (C) 2024 STMicroelectronics and others.
3+
//
4+
// This program and the accompanying materials are made available under the
5+
// terms of the Eclipse Public License v. 2.0 which is available at
6+
// http://www.eclipse.org/legal/epl-2.0.
7+
//
8+
// This Source Code may also be made available under the following Secondary
9+
// Licenses when the conditions for such availability set forth in the Eclipse
10+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
11+
// with the GNU Classpath Exception which is available at
12+
// https://www.gnu.org/software/classpath/license.html.
13+
//
14+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15+
// *****************************************************************************
16+
17+
import { FrontendApplicationContribution, OpenerService } from '../browser';
18+
19+
import { injectable, inject } from 'inversify';
20+
import { URI } from '../common';
21+
22+
@injectable()
23+
export class ElectronUriHandlerContribution implements FrontendApplicationContribution {
24+
@inject(OpenerService)
25+
protected readonly openenerService: OpenerService;
26+
27+
initialize(): void {
28+
window.electronTheiaCore.setOpenUrlHandler(async url => {
29+
const uri = new URI(url);
30+
try {
31+
const handler = await this.openenerService.getOpener(uri);
32+
if (handler) {
33+
await handler.open(uri);
34+
return true;
35+
}
36+
} catch (e) {
37+
// no handler
38+
}
39+
return false;
40+
});
41+
}
42+
}

packages/core/src/electron-browser/window/electron-window-module.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { ElectronSecondaryWindowService } from './electron-secondary-window-serv
2929
import { bindWindowPreferences } from './electron-window-preferences';
3030
import { ElectronWindowService } from './electron-window-service';
3131
import { ExternalAppOpenHandler } from './external-app-open-handler';
32+
import { ElectronUriHandlerContribution } from '../electron-uri-handler';
3233

3334
export default new ContainerModule((bind, unbind, isBound, rebind) => {
3435
bind(ElectronMainWindowService).toDynamicValue(context =>
@@ -37,6 +38,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
3738
bindWindowPreferences(bind);
3839
bind(WindowService).to(ElectronWindowService).inSingletonScope();
3940
bind(FrontendApplicationContribution).toService(WindowService);
41+
bind(ElectronUriHandlerContribution).toSelf().inSingletonScope();
42+
bind(FrontendApplicationContribution).toService(ElectronUriHandlerContribution);
4043
bind(ClipboardService).to(ElectronClipboardService).inSingletonScope();
4144
rebind(FrontendApplicationStateService).to(ElectronFrontendApplicationStateService).inSingletonScope();
4245
bind(SecondaryWindowService).to(ElectronSecondaryWindowService).inSingletonScope();

0 commit comments

Comments
 (0)