diff --git a/src/app/effects/app.effects.ts b/src/app/effects/app.effects.ts
index a4b4db1c..2d7ffce4 100644
--- a/src/app/effects/app.effects.ts
+++ b/src/app/effects/app.effects.ts
@@ -104,4 +104,4 @@ export class AppEffects {
})
});
}
-}
\ No newline at end of file
+}
diff --git a/src/app/effects/backend.wired.effects.ts b/src/app/effects/backend.wired.effects.ts
index 6c345b1b..45bd17f5 100644
--- a/src/app/effects/backend.wired.effects.ts
+++ b/src/app/effects/backend.wired.effects.ts
@@ -25,7 +25,7 @@ declare var Blockly: any;
// Defines the effects on the Electron environment that different state changes have
export class BackendWiredEffects {
- constructor(private router: Router, private backEndState: BackEndState, private appState: AppState, private blocklyEditorState: BlocklyEditorState, private robotWiredState: RobotWiredState, private dialogState: DialogState, private zone: NgZone, private dialog: MatDialog) {
+ constructor(private blocklyState: BlocklyEditorState, private router: Router, private backEndState: BackEndState, private appState: AppState, private blocklyEditorState: BlocklyEditorState, private robotWiredState: RobotWiredState, private dialogState: DialogState, private zone: NgZone, private dialog: MatDialog) {
// Only set up these effects when we're in Desktop mode
this.appState.isDesktop$
.pipe(filter(isDesktop => !!isDesktop))
@@ -273,6 +273,24 @@ export class BackendWiredEffects {
case 'open-browser-page':
const url = args[0];
window.open(url, '_blank').focus();
+ break;
+ case 'save-workspace-temp':
+ const data = args[0].data;
+ sessionStorage.setItem('workspace', data);
+ break;
+ case 'restore-workspace-temp':
+ console.log('restoring workspace');
+ const workspaceTemp = sessionStorage.getItem('workspace');
+ console.log(workspaceTemp);
+ try {
+ this.blocklyState.setWorkspaceXml(workspaceTemp);
+ this.blocklyState.setProjectFilePath('');
+ this.blocklyState.setWorkspaceStatus(WorkspaceStatus.Restoring);
+ } catch (error) {
+ console.log('Error:', error.message);
+ }
+ console.log('restored workspace');
+ break;
default:
console.log(channel);
break;
diff --git a/src/app/effects/blockly-editor.effects.ts b/src/app/effects/blockly-editor.effects.ts
index b99055bd..79165c91 100644
--- a/src/app/effects/blockly-editor.effects.ts
+++ b/src/app/effects/blockly-editor.effects.ts
@@ -29,10 +29,9 @@ export class BlocklyEditorEffects {
this.appState.currentLanguage$
.pipe(filter(language => !!language))
.subscribe(async language => {
+ console.log('Loading Blockly translations for language: ' + language.code);
const translations = await import(`node_modules/leaphy-blockly/msg/${language.code}.js`);
- Object.keys(translations.default).forEach(function (tk) {
- Blockly.Msg[tk] = translations[tk];
- });
+ Blockly.setLocale(translations);
});
// When the language is changed, save the workspace temporarily
@@ -139,11 +138,17 @@ export class BlocklyEditorEffects {
this.blocklyState.workspaceStatus$
.pipe(filter(status => status === WorkspaceStatus.Restoring))
.pipe(withLatestFrom(this.blocklyState.workspaceXml$, this.blocklyState.workspace$))
- .subscribe(([, workspaceXml, workspace]) => {
- workspace.clear();
- const xml = Blockly.Xml.textToDom(workspaceXml);
- Blockly.Xml.domToWorkspace(xml, workspace);
- this.blocklyState.setWorkspaceStatus(WorkspaceStatus.Clean);
+ .subscribe(async ([, workspaceXml, workspace]) => {
+ console.log('Restoring workspace');
+ while (this.blocklyState.workspace == null) {
+ await new Promise(resolve => setTimeout(resolve, 1000));
+ }
+ workspace = this.blocklyState.workspace;
+ console.log('Workspace loaded');
+ workspace.clear();
+ const xml = Blockly.Xml.textToDom(workspaceXml);
+ Blockly.Xml.domToWorkspace(xml, workspace);
+ this.blocklyState.setWorkspaceStatus(WorkspaceStatus.Clean);
});
// When the user presses undo or redo, trigger undo or redo on the workspace
diff --git a/src/app/modules/blockly-editor/blockly-editor.page.html b/src/app/modules/blockly-editor/blockly-editor.page.html
index ef4e4b84..57818636 100644
--- a/src/app/modules/blockly-editor/blockly-editor.page.html
+++ b/src/app/modules/blockly-editor/blockly-editor.page.html
@@ -4,7 +4,7 @@