Skip to content

Commit b24d440

Browse files
authored
Merge pull request #53 from bcmi-labs/PROEDITOR-27
PROEDITOR-27: Try to preserve the window.
2 parents 37db6c4 + af9b9fb commit b24d440

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

arduino-ide-electron/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939
"editor.autoSave": "on"
4040
}
4141
}
42-
}
43-
},
44-
"generator": {
45-
"config": {
46-
"preloadTemplate": "<div class='theia-preload' style='background-color: rgb(237, 241, 242);'></div>"
42+
},
43+
"generator": {
44+
"config": {
45+
"preloadTemplate": "<div class='theia-preload' style='background-color: rgb(237, 241, 242);'></div>"
46+
}
4747
}
4848
}
4949
}

arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

+19-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service
1919
import { SketchFactory } from './sketch-factory';
2020
import { ArduinoToolbar } from './toolbar/arduino-toolbar';
2121
import { EditorManager, EditorMainMenu } from '@theia/editor/lib/browser';
22-
import { ContextMenuRenderer, OpenerService, Widget, StatusBar, ShellLayoutRestorer, StatusBarAlignment } from '@theia/core/lib/browser';
22+
import { ContextMenuRenderer, OpenerService, Widget, StatusBar, ShellLayoutRestorer, StatusBarAlignment, LabelProvider } from '@theia/core/lib/browser';
2323
import { OpenFileDialogProps, FileDialogService } from '@theia/filesystem/lib/browser/file-dialog';
2424
import { FileSystem, FileStat } from '@theia/filesystem/lib/common';
2525
import { ArduinoToolbarContextMenu } from './arduino-file-menu';
@@ -113,6 +113,9 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
113113
@inject(ShellLayoutRestorer)
114114
protected readonly layoutRestorer: ShellLayoutRestorer;
115115

116+
@inject(LabelProvider)
117+
protected readonly labelProvider: LabelProvider;
118+
116119
protected boardsToolbarItem: BoardsToolBarItem | null;
117120
protected wsSketchCount: number = 0;
118121

@@ -375,9 +378,21 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
375378
}
376379

377380
protected async openSketchFilesInNewWindow(uri: string) {
378-
const location = new URL(window.location.href);
379-
location.searchParams.set('sketch', uri);
380-
this.windowService.openNewWindow(location.toString());
381+
const url = new URL(window.location.href);
382+
const currentSketch = url.searchParams.get('sketch');
383+
// Nothing to do if we want to open the same sketch which is already opened.
384+
if (!!currentSketch && new URI(currentSketch).toString() === new URI(uri).toString()) {
385+
this.messageService.info(`The '${this.labelProvider.getLongName(new URI(uri))}' is already opened.`);
386+
// NOOP.
387+
return;
388+
}
389+
// Preserve the current window if the `sketch` is not in the `searchParams`.
390+
url.searchParams.set('sketch', uri);
391+
if (!currentSketch) {
392+
setTimeout(() => window.location.href = url.toString(), 100);
393+
return;
394+
}
395+
this.windowService.openNewWindow(url.toString());
381396
}
382397

383398
async openSketchFiles(uri: string) {

electron/packager/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
//-------------------------------------------------------------------------------------------------+
6767
// Rebuild the extension with the copied `yarn.lock`. It is a must to use the same Theia versions. |
6868
//-------------------------------------------------------------------------------------------------+
69-
exec(`yarn --cwd ${path('..', workingCopy)}`, 'Building the Arduino Theia extensions');
69+
exec(`yarn --network-timeout 1000000 --cwd ${path('..', workingCopy)}`, 'Building the Arduino Theia extensions');
7070
// Collect all unused dependencies by the backend. We have to remove them from the electron app.
7171
// The `bundle.js` already contains everything we need for the frontend.
7272
// We have to do it before changing the dependencies to `local-path`.
@@ -98,8 +98,8 @@ ${fs.readFileSync(path('..', 'build', 'package.json')).toString()}
9898
//-------------------------------------------------------------------------------------------+
9999
// Install all private and public dependencies for the electron application and build Theia. |
100100
//-------------------------------------------------------------------------------------------+
101-
exec(`yarn --cwd ${path('..', 'build')}`, 'Installing dependencies');
102-
exec(`yarn --cwd ${path('..', 'build')} build${release ? ':release' : ''}`, 'Building the Arduino-PoC application');
101+
exec(`yarn --network-timeout 1000000 --cwd ${path('..', 'build')}`, 'Installing dependencies');
102+
exec(`yarn --network-timeout 1000000 --cwd ${path('..', 'build')} build${release ? ':release' : ''}`, 'Building the Arduino-PoC application');
103103

104104
//------------------------------------------------------------------------------+
105105
// Create a throw away dotenv file which we use to feed the builder with input. |
@@ -115,7 +115,7 @@ ${fs.readFileSync(path('..', 'build', 'package.json')).toString()}
115115
//-----------------------------------+
116116
// Package the electron application. |
117117
//-----------------------------------+
118-
exec(`yarn --cwd ${path('..', 'build')} package`, `Packaging your Arduino-PoC application`);
118+
exec(`yarn --network-timeout 1000000 --cwd ${path('..', 'build')} package`, `Packaging your Arduino-PoC application`);
119119
echo(`🎉 Success. Your application is at: ${path('..', 'build', 'dist')}`);
120120

121121
restore();

0 commit comments

Comments
 (0)