Skip to content

Renamed the application to Arduino IDE #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 11, 2021
Prev Previous commit
Next Next commit
ATL-879: Avoid reopening the same sketch.
Instead of reopening it, focus the existing window.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
  • Loading branch information
Akos Kitta committed Feb 10, 2021
commit 4a062ca31b55baf4e97e6691a459b2aafb30cfff
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { ContainerModule } from 'inversify';
import { JsonRpcConnectionHandler } from '@theia/core/lib/common/messaging/proxy-factory';
import { ElectronConnectionHandler } from '@theia/core/lib/electron-common/messaging/electron-connection-handler';
import { ElectronMainWindowService } from '@theia/core/lib/electron-common/electron-main-window-service';
import { ElectronMainApplication as TheiaElectronMainApplication } from '@theia/core/lib/electron-main/electron-main-application';
import { SplashService, splashServicePath } from '../electron-common/splash-service';
import { SplashServiceImpl } from './splash/splash-service-impl';
import { ElectronMainApplication } from './theia/electron-main-application';
import { ElectronMainWindowServiceImpl } from './theia/electron-main-window-service';

export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(ElectronMainApplication).toSelf().inSingletonScope();
rebind(TheiaElectronMainApplication).toService(ElectronMainApplication);

bind(ElectronMainWindowServiceImpl).toSelf().inSingletonScope();
rebind(ElectronMainWindowService).toService(ElectronMainWindowServiceImpl);

bind(SplashServiceImpl).toSelf().inSingletonScope();
bind(SplashService).toService(SplashServiceImpl);
bind(ElectronConnectionHandler).toDynamicValue(context =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { SplashServiceImpl } from '../splash/splash-service-impl';
@injectable()
export class ElectronMainApplication extends TheiaElectronMainApplication {

protected windows: BrowserWindow[] = [];
protected _windows: BrowserWindow[] = [];

@inject(SplashServiceImpl)
protected readonly splashService: SplashServiceImpl;
Expand All @@ -34,7 +34,7 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
async createWindow(asyncOptions: MaybePromise<TheiaBrowserWindowOptions> = this.getDefaultBrowserWindowOptions()): Promise<BrowserWindow> {
const options = await asyncOptions;
let electronWindow: BrowserWindow | undefined;
if (this.windows.length) {
if (this._windows.length) {
electronWindow = new BrowserWindow(options);
} else {
const { bounds } = screen.getDisplayNearestPoint(screen.getCursorScreenPoint());
Expand Down Expand Up @@ -63,14 +63,14 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
splashScreenOpts
}, this.splashService.onCloseRequested);
}
this.windows.push(electronWindow);
this._windows.push(electronWindow);
electronWindow.on('closed', () => {
if (electronWindow) {
const index = this.windows.indexOf(electronWindow);
const index = this._windows.indexOf(electronWindow);
if (index === -1) {
console.warn(`Could not dispose browser window: '${electronWindow.title}'.`);
} else {
this.windows.splice(index, 1);
this._windows.splice(index, 1);
electronWindow = undefined;
}
}
Expand Down Expand Up @@ -148,4 +148,8 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
}
}

get windows(): BrowserWindow[] {
return this._windows.slice();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { inject, injectable } from 'inversify';
import { NewWindowOptions } from '@theia/core/lib/browser/window/window-service';
import { ElectronMainWindowServiceImpl as TheiaElectronMainWindowService } from '@theia/core/lib/electron-main/electron-main-window-service-impl';
import { ElectronMainApplication } from './electron-main-application';

@injectable()
export class ElectronMainWindowServiceImpl extends TheiaElectronMainWindowService {

@inject(ElectronMainApplication)
protected readonly app: ElectronMainApplication;

openNewWindow(url: string, { external }: NewWindowOptions): undefined {
if (!external) {
const existing = this.app.windows.find(window => window.webContents.getURL() === url);
if (existing) {
existing.focus();
return;
}
}
return super.openNewWindow(url, { external });
}


}