Skip to content

Commit babe33d

Browse files
committed
Make it possible to specify the URL for an ApplicationWindow
This will make it easier to create specialized application windows for tests etc. by switching out the URL loaded in the BrowserWindow.
1 parent a4d6f81 commit babe33d

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/main-process/application-window.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22
// MIT License, see LICENSE file for full terms.
33

44
import * as path from 'path';
5-
import * as url from 'url';
65
import * as BrowserWindow from 'browser-window';
76

87
export interface IApplicationWindowOpenParams {
9-
/** Path to the root directory of the application. */
10-
rootPath: string;
8+
windowUrl: string;
119
}
1210

1311
export default class ApplicationWindow {
1412
private _browserWindow: GitHubElectron.BrowserWindow;
1513

16-
open({ rootPath }: IApplicationWindowOpenParams): void {
14+
open({ windowUrl }: IApplicationWindowOpenParams): void {
1715
const options = <GitHubElectron.BrowserWindowOptions> {
1816
// the window will be shown later after everything is fully initialized
1917
show: false,
@@ -23,11 +21,7 @@ export default class ApplicationWindow {
2321
}
2422
};
2523
this._browserWindow = new BrowserWindow(options);
26-
this._browserWindow.loadUrl(url.format({
27-
protocol: 'file',
28-
pathname: `${rootPath}/static/index.html`
29-
}));
30-
24+
this._browserWindow.loadUrl(windowUrl);
3125
this._bindEventHandlers();
3226
}
3327

src/main-process/application.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// Copyright (c) 2015 Vadim Macagon
22
// MIT License, see LICENSE file for full terms.
33

4+
import * as url from 'url';
45
import ApplicationWindow from './application-window';
56
import { AppProtocolHandler } from './protocol-handlers';
67

78
export interface IApplicationArgs {
9+
/** Path to the root directory of the application. */
810
rootPath: string;
911
}
1012

@@ -15,8 +17,12 @@ export default class Application {
1517
run(args: IApplicationArgs): void {
1618
this._appProtocolHandler = new AppProtocolHandler(args.rootPath);
1719
this._window = new ApplicationWindow();
20+
const windowUrl = url.format({
21+
protocol: 'file',
22+
pathname: `${args.rootPath}/static/index.html`
23+
});
1824
this._window.open({
19-
rootPath: args.rootPath
25+
windowUrl
2026
});
2127
}
2228
}

0 commit comments

Comments
 (0)