ATL-667: Warn the user when could not save sketch.

- Log the PID of the backend process.
 - Aligned the dev startup mode with the production: `--no-cluster`.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta 2020-11-06 14:22:09 +01:00 committed by Akos Kitta
parent 1a531db0b7
commit cff2c95684
6 changed files with 1295 additions and 1273 deletions

2
.vscode/launch.json vendored
View File

@ -34,7 +34,6 @@
"args": [
"--log-level=debug",
"--hostname=localhost",
"--no-cluster",
"--remote-debugging-port=9222",
"--no-app-auto-install",
"--plugins=local-dir:plugins"
@ -61,7 +60,6 @@
"args": [
"--hostname=0.0.0.0",
"--port=3000",
"--no-cluster",
"--no-app-auto-install",
"--plugins=local-dir:plugins"
],

View File

@ -2,7 +2,9 @@
import { injectable, inject } from 'inversify';
import { EditorWidget } from '@theia/editor/lib/browser';
import { CommandService } from '@theia/core/lib/common/command';
import { MessageService } from '@theia/core/lib/common/message-service';
import { OutputWidget } from '@theia/output/lib/browser/output-widget';
import { ConnectionStatusService, ConnectionStatus } from '@theia/core/lib/browser/connection-status-service';
import { ApplicationShell as TheiaApplicationShell, Widget } from '@theia/core/lib/browser';
import { Sketch } from '../../../common/protocol';
import { EditorMode } from '../../editor-mode';
@ -18,9 +20,15 @@ export class ApplicationShell extends TheiaApplicationShell {
@inject(CommandService)
protected readonly commandService: CommandService;
@inject(MessageService)
protected readonly messageService: MessageService;
@inject(SketchesServiceClientImpl)
protected readonly sketchesServiceClient: SketchesServiceClientImpl;
@inject(ConnectionStatusService)
protected readonly connectionStatusService: ConnectionStatusService;
protected track(widget: Widget): void {
super.track(widget);
if (widget instanceof OutputWidget) {
@ -60,6 +68,10 @@ export class ApplicationShell extends TheiaApplicationShell {
}
async saveAll(): Promise<void> {
if (this.connectionStatusService.currentStatus === ConnectionStatus.OFFLINE) {
this.messageService.error('Could not save the sketch. Please copy your unsaved work into your favorite text editor, and restart the IDE.');
return; // Theia does not reject on failed save: https://github.com/eclipse-theia/theia/pull/8803
}
await super.saveAll();
const options = { execOnlyIfTemp: true, openAfterMove: true };
await this.commandService.executeCommand(SaveAsSketch.Commands.SAVE_AS_SKETCH.id, options);

View File

@ -0,0 +1,28 @@
import { inject, injectable } from 'inversify';
import { remote } from 'electron';
import { ConnectionStatus, ConnectionStatusService } from '@theia/core/lib/browser/connection-status-service';
import { ElectronWindowService as TheiaElectronWindowService } from '@theia/core/lib/electron-browser/window/electron-window-service';
@injectable()
export class ElectronWindowService extends TheiaElectronWindowService {
@inject(ConnectionStatusService)
protected readonly connectionStatusService: ConnectionStatusService;
protected shouldUnload(): boolean {
const offline = this.connectionStatusService.currentStatus === ConnectionStatus.OFFLINE;
const detail = offline
? 'Could not save the sketch. Please copy your unsaved work into your favorite text editor, and restart the IDE.'
: 'Any unsaved changes will not be saved.'
const electronWindow = remote.getCurrentWindow();
const response = remote.dialog.showMessageBoxSync(electronWindow, {
type: 'question',
buttons: ['Yes', 'No'],
title: 'Confirm',
message: 'Are you sure you want to close the sketch?',
detail
});
return response === 0; // 'Yes', close the window.
}
}

View File

@ -1,9 +1,11 @@
import { ContainerModule } from 'inversify';
import { ElectronMenuContribution as TheiaElectronMenuContribution } from '@theia/core/lib/electron-browser/menu/electron-menu-contribution'
import { ElectronMenuContribution } from './electron-menu-contribution';
import { MainMenuManager } from '../../../common/main-menu-manager';
import { WindowService } from '@theia/core/lib/browser/window/window-service';
import { ElectronMainMenuFactory as TheiaElectronMainMenuFactory } from '@theia/core/lib/electron-browser/menu/electron-main-menu-factory';
import { ElectronMenuContribution as TheiaElectronMenuContribution } from '@theia/core/lib/electron-browser/menu/electron-menu-contribution'
import { MainMenuManager } from '../../../common/main-menu-manager';
import { ElectronWindowService } from '../../electron-window-service';
import { ElectronMainMenuFactory } from './electron-main-menu-factory';
import { ElectronMenuContribution } from './electron-menu-contribution';
export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(ElectronMenuContribution).toSelf().inSingletonScope();
@ -11,4 +13,6 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
rebind(TheiaElectronMenuContribution).to(ElectronMenuContribution);
bind(ElectronMainMenuFactory).toSelf().inRequestScope();
rebind(TheiaElectronMainMenuFactory).toService(ElectronMainMenuFactory);
bind(ElectronWindowService).toSelf().inSingletonScope()
rebind(WindowService).toService(ElectronWindowService);
});

View File

@ -57,6 +57,7 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
args,
await this.getForkOptions(),
);
console.log(`Starting backend process. PID: ${backendProcess.pid}`);
return new Promise((resolve, reject) => {
// The backend server main file is also supposed to send the resolved http(s) server port via IPC.
backendProcess.on('message', (address: AddressInfo) => {

2515
yarn.lock

File diff suppressed because it is too large Load Diff