diff --git a/src/app/effects/app.effects.ts b/src/app/effects/app.effects.ts index c500194a..046ce670 100644 --- a/src/app/effects/app.effects.ts +++ b/src/app/effects/app.effects.ts @@ -9,8 +9,6 @@ import {MatDialog} from "@angular/material/dialog"; import {ChangeLogDialog} from "../modules/core/dialogs/change-log/change-log.dialog"; import showdown from "showdown"; import {WorkspaceService} from "../services/workspace.service"; -import * as Blockly from "blockly/core"; -import {VariableDialog} from "../modules/core/dialogs/variable/variable.dialog"; @Injectable({ providedIn: 'root', @@ -38,9 +36,9 @@ export class AppEffects { .pipe(filter(isToggled => !!isToggled), withLatestFrom(this.appState.codeEditor$)) .subscribe(([, codeEditorType]) => { if (codeEditorType == CodeEditorType.Beginner) { - this.appState.setSelectedCodeEditor(CodeEditorType.CPP); + this.appState.selectedCodeEditor = CodeEditorType.CPP; } else if (codeEditorType == CodeEditorType.CPP) { - this.appState.setSelectedCodeEditor(CodeEditorType.Beginner); + this.appState.selectedCodeEditor = CodeEditorType.Beginner; } }); @@ -61,7 +59,7 @@ export class AppEffects { default: break; } - this.appState.setIsCodeEditorToggleConfirmed(false); + this.appState.isCodeEditorToggleConfirmed = false; }); @@ -69,7 +67,7 @@ export class AppEffects { this.appState.releaseInfo$ .pipe(filter(releaseInfo => !!releaseInfo)) .subscribe(releaseInfo => { - const releaseVersion = this.appState.getReleaseVersion(); + const releaseVersion = this.appState.releaseVersion; if (!releaseVersion) { return; } @@ -128,23 +126,6 @@ export class AppEffects { } }) - this.appState.isDesktop$ - .pipe(filter(isDesktop => !!isDesktop)) - .subscribe(() => { - try { - Blockly.dialog.setPrompt((msg, defaultValue, callback) => { - this.dialog.open(VariableDialog, { - width: '400px', - data: { name: defaultValue } - }).afterClosed().subscribe(result => { - callback(result); - }); - }); - } catch (e) { - console.log(e); - throw e; - } - }); } diff --git a/src/app/effects/blockly-editor.effects.ts b/src/app/effects/blockly-editor.effects.ts index 1e104df7..9b0a1cd5 100644 --- a/src/app/effects/blockly-editor.effects.ts +++ b/src/app/effects/blockly-editor.effects.ts @@ -62,7 +62,7 @@ export class BlocklyEditorEffects { .pipe(withLatestFrom(this.blocklyState.workspaceJSON$, this.appState.selectedRobotType$)) .subscribe(([, workspaceXml]) => { this.workspaceService.saveWorkspaceTemp(workspaceXml).then(() => {}); - this.localStorage.store("changedLanguage", this.appState.getSelectedRobotType().id); + this.localStorage.store("changedLanguage", this.appState.selectedRobotType.id); }); // When all prerequisites are there, Create a new workspace and open the codeview if needed @@ -75,7 +75,7 @@ export class BlocklyEditorEffects { this.getXmlContent('./assets/blockly/leaphy-start.xml') )) .subscribe(([[[element, config], robotType], baseToolboxXml, leaphyToolboxXml, startWorkspaceXml]) => { - const leaphyBlocks = getBlocks(this.appState.getSelectedRobotType().id); + const leaphyBlocks = getBlocks(this.appState.selectedRobotType.id); Blockly.defineBlocksWithJsonArray(leaphyBlocks.block) config.theme = Blockly.Theme.defineTheme('leaphy', { 'blockStyles': THEME.defaultBlockStyles, @@ -92,21 +92,21 @@ export class BlocklyEditorEffects { toolbox.getFlyout().autoClose = false; const xml = Blockly.utils.xml.textToDom(startWorkspaceXml); Blockly.Xml.domToWorkspace(xml, workspace); - this.blocklyState.setWorkspace(workspace); - this.blocklyState.setToolboxXml(toolboxXmlString); - if (this.appState.getCurrentEditor() == CodeEditorType.Beginner) { + this.blocklyState.workspace = workspace; + this.blocklyState.toolboxXml = toolboxXmlString; + if (this.appState.currentEditor == CodeEditorType.Beginner) { this.workspaceService.restoreWorkspaceTemp().then(() => {}); } toolbox.selectItemByPosition(0); toolbox.refreshTheme(); - setTimeout(() => this.blocklyState.setIsSideNavOpen(robotType.features.showCodeOnStart), 200); + setTimeout(() => this.blocklyState.isSideNavOpen = robotType.features.showCodeOnStart, 200); }); // When a new project is started, reset the blockly code this.appState.selectedRobotType$ .pipe(filter(robotType => !robotType)) - .subscribe(() => this.codeEditorState.setCode('')) + .subscribe(() => this.codeEditorState.code = '') // When the robot selection changes, set the toolbox and initialWorkspace this.appState.selectedRobotType$ @@ -119,7 +119,7 @@ export class BlocklyEditorEffects { )) .subscribe(([[robotType, workspace], baseToolboxXml, leaphyToolboxXml, startWorkspaceXml]) => { const toolboxXmlString = this.loadToolBox(baseToolboxXml, leaphyToolboxXml, robotType); - this.blocklyState.setToolboxXml(toolboxXmlString); + this.blocklyState.toolboxXml = toolboxXmlString; workspace.clear(); const xml = Blockly.utils.xml.textToDom(startWorkspaceXml); @@ -139,8 +139,8 @@ export class BlocklyEditorEffects { workspace.clearUndo(); workspace.addChangeListener(Blockly.Events.disableOrphans); workspace.addChangeListener(async () => { - this.codeEditorState.setCode(arduino.workspaceToCode(workspace, this.appState.getSelectedRobotType().id)); - this.blocklyState.setWorkspaceJSON(JSON.stringify(Blockly.serialization.workspaces.save(workspace))); + this.codeEditorState.code = arduino.workspaceToCode(workspace, this.appState.selectedRobotType.id); + this.blocklyState.workspaceJSON = JSON.stringify(Blockly.serialization.workspaces.save(workspace)); }); }); @@ -158,21 +158,14 @@ export class BlocklyEditorEffects { filter(([previous, current]) => (current === CodeEditorType.CPP || current === CodeEditorType.Python ) && current !== previous) ) .subscribe(() => { - this.blocklyState.setIsSideNavOpen(false); - }); - - // Toggle the isSideNavOpen state - this.blocklyState.isSideNavOpenToggled$ - .pipe(filter(isToggled => !!isToggled), withLatestFrom(this.blocklyState.isSideNavOpen$)) - .subscribe(([, isSideNavOpen]) => { - this.blocklyState.setIsSideNavOpen(!isSideNavOpen); + this.blocklyState.isSideNavOpen = false; }); // Toggle the isSoundOn state this.blocklyState.isSoundToggled$ .pipe(filter(isToggled => !!isToggled), withLatestFrom(this.blocklyState.isSoundOn$)) .subscribe(([, isSoundOn]) => { - this.blocklyState.setIsSoundOn(!isSoundOn); + this.blocklyState.isSoundOn = !isSoundOn; }); // When the sound is turned on off, update the Blockly function @@ -181,7 +174,7 @@ export class BlocklyEditorEffects { .subscribe(([isSoundOn, basePlay]) => { if (!basePlay) { basePlay = Blockly.WorkspaceAudio.prototype.play; - this.blocklyState.setPlaySoundFunction(basePlay); + this.blocklyState.playSoundFunction = basePlay; } Blockly.WorkspaceAudio.prototype.play = function (name, opt_volume) { if (isSoundOn) { @@ -192,7 +185,7 @@ export class BlocklyEditorEffects { // When the code editor is changed, clear the projectFilePath this.appState.codeEditor$ - .subscribe(() => this.blocklyState.setProjectFileHandle(null)); + .subscribe(() => this.blocklyState.projectFileHandle = null); } private parseCategory(root: Document, category: HTMLElement, robotType: RobotType,) : HTMLElement { diff --git a/src/app/effects/code-editor.effects.ts b/src/app/effects/code-editor.effects.ts index 092e5d6e..fee2576d 100644 --- a/src/app/effects/code-editor.effects.ts +++ b/src/app/effects/code-editor.effects.ts @@ -19,9 +19,9 @@ export class CodeEditorEffects { this.appState.codeEditor$ .subscribe(codeEditor => { if (codeEditor == CodeEditorType.Python) { - this.codeEditorState.setCode(this.codeEditorState.pythonProgram); - } else if (codeEditor == CodeEditorType.CPP && this.appState.getSelectedRobotType() == genericRobotType) { - this.codeEditorState.setCode(this.codeEditorState.originalProgram); + this.codeEditorState.code = `from leaphymicropython.utils.pins import set_pwm`; + } else if (codeEditor == CodeEditorType.CPP && this.appState.selectedRobotType == genericRobotType) { + this.codeEditorState.code = this.codeEditorState.originalProgram; } }); } diff --git a/src/app/effects/dialog.effects.ts b/src/app/effects/dialog.effects.ts index 1500b802..903b52b9 100644 --- a/src/app/effects/dialog.effects.ts +++ b/src/app/effects/dialog.effects.ts @@ -45,14 +45,14 @@ export class DialogEffects { // If the isSerialOutputWindowOpen is set to true open the dialog this.dialogState.isSerialOutputWindowOpen$ .subscribe(() => { - if (this.dialogState.getIsSerialOutputWindowOpen() !== true) + if (this.dialogState.isSerialOutputWindowOpen !== true) return; this.dialog.open(SerialOutputComponent, { width: "800px", disableClose: true, hasBackdrop: false, }).afterClosed().subscribe(() => { - this.dialogState.setIsSerialOutputWindowOpen(false); + this.dialogState.isSerialOutputWindowOpen = false; }); }); @@ -60,12 +60,12 @@ export class DialogEffects { // If the isLibraryManagerWindowOpen is set to true open the dialog this.dialogState.isLibraryManagerWindowOpen$ .subscribe(() => { - if (this.dialogState.getIsLibraryManagerWindowOpen() !== true) + if (this.dialogState.isLibraryManagerWindowOpen !== true) return; this.dialog.open(LibraryManagerComponent, { disableClose: true, }).afterClosed().subscribe(() => { - this.dialogState.setIsLibraryManagerWindowOpen(false); + this.dialogState.isLibraryManagerWindowOpen = false; }); }); diff --git a/src/app/effects/robot.wired.effects.ts b/src/app/effects/robot.wired.effects.ts index f0f91e92..9ea48705 100644 --- a/src/app/effects/robot.wired.effects.ts +++ b/src/app/effects/robot.wired.effects.ts @@ -25,7 +25,7 @@ export class RobotWiredEffects { this.dialogState.isSerialOutputListening$ .pipe(filter(isListening => !!isListening)) .subscribe(async () => { - if (this.robotWiredState.getPythonDeviceConnected()) + if (this.robotWiredState.pythonDeviceConnected) return; const robotWiredState = this.robotWiredState; @@ -38,8 +38,7 @@ export class RobotWiredEffects { const date = new Date(); function makeString (chunkedStr: string) { - const serialData = { time: date, data: chunkedStr }; - robotWiredState.setIncomingSerialData(serialData); + robotWiredState.incomingSerialData = { time: date, data: chunkedStr }; } let i = this.logBuffer.indexOf("\n"); diff --git a/src/app/modules/blockly-editor/components/leaphy-blockly/leaphy-blockly.component.ts b/src/app/modules/blockly-editor/components/leaphy-blockly/leaphy-blockly.component.ts index b7ff8eae..21217887 100644 --- a/src/app/modules/blockly-editor/components/leaphy-blockly/leaphy-blockly.component.ts +++ b/src/app/modules/blockly-editor/components/leaphy-blockly/leaphy-blockly.component.ts @@ -55,7 +55,7 @@ export class LeaphyBlocklyComponent implements AfterViewInit { } ngAfterViewInit() { - this.blocklyState.setBlocklyElement(this.blockContent.nativeElement); + this.blocklyState.blocklyElement = this.blockContent.nativeElement; this.blocklyState.workspace$.subscribe(workspace => { this.workspace = workspace workspace.addChangeListener((event: any) => { diff --git a/src/app/modules/code-editor-cpp/code-editor-cpp.page.html b/src/app/modules/code-editor-cpp/code-editor-cpp.page.html index cf8c6c94..44bf9ca6 100644 --- a/src/app/modules/code-editor-cpp/code-editor-cpp.page.html +++ b/src/app/modules/code-editor-cpp/code-editor-cpp.page.html @@ -3,7 +3,7 @@ class="monaco-editor" [options]="editorOptions" [ngModel]="codeEditorState.code$ | async" - (ngModelChange)="codeEditorState.setCode($event)" + (ngModelChange)="codeEditorState.code = $event" /> diff --git a/src/app/modules/code-editor-cpp/code-editor-cpp.page.ts b/src/app/modules/code-editor-cpp/code-editor-cpp.page.ts index da513fb4..82f4e0ce 100644 --- a/src/app/modules/code-editor-cpp/code-editor-cpp.page.ts +++ b/src/app/modules/code-editor-cpp/code-editor-cpp.page.ts @@ -32,7 +32,7 @@ export class CodeEditorCppPage implements AfterViewInit { ngAfterViewInit(): void { window.addEventListener("beforeunload", async () => { - await this.workspaceService.saveWorkspaceTemp(this.codeEditorState.getCode()); + await this.workspaceService.saveWorkspaceTemp(this.codeEditorState.code); }); } } diff --git a/src/app/modules/code-editor-python/code-editor-python.page.html b/src/app/modules/code-editor-python/code-editor-python.page.html index 1efa2644..27008262 100644 --- a/src/app/modules/code-editor-python/code-editor-python.page.html +++ b/src/app/modules/code-editor-python/code-editor-python.page.html @@ -3,7 +3,7 @@ class="monaco-editor" [options]="editorOptions" [ngModel]="codeEditorState.code$ | async" - (ngModelChange)="codeEditorState.setCode($event)" + (ngModelChange)="codeEditorState.code = ($event)" /> diff --git a/src/app/modules/code-editor-python/code-editor-python.page.ts b/src/app/modules/code-editor-python/code-editor-python.page.ts index e467e5b0..f0b8e847 100644 --- a/src/app/modules/code-editor-python/code-editor-python.page.ts +++ b/src/app/modules/code-editor-python/code-editor-python.page.ts @@ -32,7 +32,7 @@ export class CodeEditorPythonPage implements AfterViewInit { ngAfterViewInit(): void { window.addEventListener("beforeunload", async () => { - await this.workspaceService.saveWorkspaceTemp(this.codeEditorState.getCode()); + await this.workspaceService.saveWorkspaceTemp(this.codeEditorState.code); }) } } diff --git a/src/app/modules/components/header/header.component.html b/src/app/modules/components/header/header.component.html index 3633b89f..fec99b5d 100644 --- a/src/app/modules/components/header/header.component.html +++ b/src/app/modules/components/header/header.component.html @@ -65,7 +65,7 @@ -
{{ (appState.releaseVersion$ | async) }}
+
{{ (appState.releaseVersion) }}
@@ -133,7 +133,7 @@ - diff --git a/src/app/modules/components/header/header.component.ts b/src/app/modules/components/header/header.component.ts index d5516aac..41e4b6ee 100644 --- a/src/app/modules/components/header/header.component.ts +++ b/src/app/modules/components/header/header.component.ts @@ -78,10 +78,10 @@ export class HeaderComponent { public async onChooseRobot() { const port = await this.robotWiredState.requestSerialPort(true) - if (port !== this.robotWiredState.getSerialPort()) { + if (port !== this.robotWiredState.serialPort) { await port.open({baudRate: 115200}); - this.robotWiredState.setSerialPort(port); - this.dialogState.setIsSerialOutputListening(true); + this.robotWiredState.serialPort = port; + this.dialogState.isSerialOutputListening = true; } this.snackBar.openFromComponent(StatusMessageDialog, { @@ -110,7 +110,7 @@ export class HeaderComponent { } public onSaveWorkspaceAsClicked() { - this.workspaceService.saveWorkspaceAs(this.appState.getSelectedRobotType().id).then(() => {}); + this.workspaceService.saveWorkspaceAs(this.appState.selectedRobotType.id).then(() => {}); } public onConnectClicked() { @@ -119,7 +119,7 @@ export class HeaderComponent { }).afterClosed().subscribe((result) => { if (result) { if (result == "HELP_ENVIRONMENT") { - const langcode = this.appState.getCurrentLanguageCode(); + const langcode = this.appState.currentLanguageCode; this.router.navigateByUrl('/' + langcode + '/driverissues', {skipLocationChange: true}).then(() => {}); } } @@ -127,12 +127,12 @@ export class HeaderComponent { } public async onRunClicked() { - const robotType = this.appState.getSelectedRobotType(); - const code = this.codeEditorState.getCode(); + const robotType = this.appState.selectedRobotType; + const code = this.codeEditorState.code; const libraries = [...robotType.libs]; - libraries.push(...this.codeEditorState.getInstalledLibraries().map(lib => `${lib.name}@${lib.version}`)); + libraries.push(...this.codeEditorState.installedLibraries.map(lib => `${lib.name}@${lib.version}`)); try { - if (this.appState.getCurrentEditor() == CodeEditorType.Python) { + if (this.appState.currentEditor == CodeEditorType.Python) { await this.uploaderService.runCode(code) } else { this.dialog.open(UploadDialog, { @@ -141,7 +141,7 @@ export class HeaderComponent { }).afterClosed().subscribe((result) => { if (result) { if (result == "HELP_ENVIRONMENT") { - const langcode = this.appState.getCurrentLanguageCode(); + const langcode = this.appState.currentLanguageCode; this.router.navigateByUrl('/' + langcode + '/driverissues', {skipLocationChange: true}); } } @@ -155,11 +155,11 @@ export class HeaderComponent { } public onUndoClicked() { - this.blocklyState.setUndo(false); + this.blocklyState.undo = false; } public onRedoClicked() { - this.blocklyState.setUndo(true); + this.blocklyState.undo = true; } public onHelpClicked() { @@ -179,7 +179,7 @@ export class HeaderComponent { } public onShowInfoClicked() { - this.dialogState.setIsInfoDialogVisible(true); + this.dialogState.isInfoDialogVisible = true; } public onViewLogClicked() { @@ -189,25 +189,25 @@ export class HeaderComponent { } public onToggleSoundClicked() { - this.blocklyState.setIsSoundToggled(); + this.blocklyState.isSoundToggled; } public onLanguageChanged(language: Language) { - this.appState.setChangedLanguage(language); + this.appState.changedLanguage = language; window.location.reload(); } public onBackToBlocks() { - if (this.appState.getCurrentEditor() == CodeEditorType.Beginner) + if (this.appState.currentEditor == CodeEditorType.Beginner) this.router.navigate(['/blocks'], {skipLocationChange: true}).then(() => {}); - else if (this.appState.getCurrentEditor() == CodeEditorType.CPP) + else if (this.appState.currentEditor == CodeEditorType.CPP) this.router.navigate(['/cppEditor'], { skipLocationChange: true }).then(() => {}); - else if (this.appState.getCurrentEditor() == CodeEditorType.Python) + else if (this.appState.currentEditor == CodeEditorType.Python) this.router.navigate(['/pythonEditor'], { skipLocationChange: true }).then(() => {}); } public onExamplesClicked() { - this.dialogState.setIsExamplesDialogVisible(true) + this.dialogState.isExamplesDialogVisible = true } protected readonly AppState = AppState; diff --git a/src/app/modules/components/robot-selection/robot-selection.component.ts b/src/app/modules/components/robot-selection/robot-selection.component.ts index f7dd339e..348691f6 100644 --- a/src/app/modules/components/robot-selection/robot-selection.component.ts +++ b/src/app/modules/components/robot-selection/robot-selection.component.ts @@ -45,11 +45,11 @@ export class RobotSelectionComponent { // checked this.appState.setSelectedRobotType(robot, this.secondary); if (robot.id === 'l_code') { - this.appState.setSelectedCodeEditor(CodeEditorType.CPP) + this.appState.selectedCodeEditor = CodeEditorType.CPP } else if (robot.id === 'l_micropython') { - this.appState.setSelectedCodeEditor(CodeEditorType.Python) + this.appState.selectedCodeEditor = CodeEditorType.Python } else { - this.appState.setSelectedCodeEditor(CodeEditorType.Beginner) + this.appState.selectedCodeEditor = CodeEditorType.Beginner } } diff --git a/src/app/modules/components/start/start.component.html b/src/app/modules/components/start/start.component.html index ecbe2e2f..833482f7 100644 --- a/src/app/modules/components/start/start.component.html +++ b/src/app/modules/components/start/start.component.html @@ -2,7 +2,7 @@ diff --git a/src/app/modules/core/dialogs/connect-python/connect-python.dialog.ts b/src/app/modules/core/dialogs/connect-python/connect-python.dialog.ts index 4e0b68f3..90d9b75a 100644 --- a/src/app/modules/core/dialogs/connect-python/connect-python.dialog.ts +++ b/src/app/modules/core/dialogs/connect-python/connect-python.dialog.ts @@ -30,7 +30,7 @@ export class ConnectPythonDialog { ) {} public async makePythonRobotConnection() { - this.dialogState.setIsSerialOutputListening(false); + this.dialogState.isSerialOutputListening = false; this.uploading.next(true); this.onUpdate('CONNECTING'); this.progressBarWidth += 25; @@ -63,7 +63,7 @@ export class ConnectPythonDialog { this.onUpdate('CONNECTED'); this.showReturnOptions(); - this.robotWiredState.setPythonDeviceConnected(true); + this.robotWiredState.pythonDeviceConnected = true; } public async startFlash() { @@ -114,12 +114,12 @@ export class ConnectPythonDialog { } returnBlockEnvironment() { - this.dialogState.setIsSerialOutputListening(true); + this.dialogState.isSerialOutputListening = true; this.dialogRef.close("BLOCK_ENVIRONMENT"); } returnHelpEnvironment() { - this.dialogState.setIsSerialOutputListening(true); + this.dialogState.isSerialOutputListening = true; this.dialogRef.close("HELP_ENVIRONMENT"); } diff --git a/src/app/modules/core/dialogs/debug-information/debug-information.dialog.html b/src/app/modules/core/dialogs/debug-information/debug-information.dialog.html index 24a0f2cf..bf492c54 100644 --- a/src/app/modules/core/dialogs/debug-information/debug-information.dialog.html +++ b/src/app/modules/core/dialogs/debug-information/debug-information.dialog.html @@ -20,7 +20,7 @@
Browser: {{browser}}
Version {{browserVersion}}
Serial Port; Device ID: {{serialPort?.getInfo().usbProductId}}; USB Vendor ID: {{serialPort?.getInfo().usbVendorId}}
-
Supported Vendor IDs: {{robotWiredState.SUPPORTED_VENDORS.join(", ")}}
+
Supported Vendor IDs: {{RobotWiredState.SUPPORTED_VENDORS.join(", ")}}
Web Serial Supported: {{webSerialSupported}}
diff --git a/src/app/modules/core/dialogs/debug-information/debug-information.dialog.ts b/src/app/modules/core/dialogs/debug-information/debug-information.dialog.ts index 4750bac2..d001eab8 100644 --- a/src/app/modules/core/dialogs/debug-information/debug-information.dialog.ts +++ b/src/app/modules/core/dialogs/debug-information/debug-information.dialog.ts @@ -28,7 +28,7 @@ export class DebugInformationDialog { this.browser = navigator.userAgentData?.brands[1].brand ?? translate.instant("UNKNOWN"); // @ts-ignore this.browserVersion = navigator.userAgentData?.brands[1].version ?? translate.instant("UNKNOWN"); - this.serialPort = this.robotWiredState.getSerialPort(); + this.serialPort = this.robotWiredState.serialPort; if (!('serial' in navigator)) { this.webSerialSupported = translate.instant("WEB_SERIAL_NOT_SUPPORTED"); } else { @@ -42,4 +42,5 @@ export class DebugInformationDialog { protected readonly document = document; + protected readonly RobotWiredState = RobotWiredState; } diff --git a/src/app/modules/core/dialogs/examples/examples-dialog.component.ts b/src/app/modules/core/dialogs/examples/examples-dialog.component.ts index 4568c662..be4d2148 100644 --- a/src/app/modules/core/dialogs/examples/examples-dialog.component.ts +++ b/src/app/modules/core/dialogs/examples/examples-dialog.component.ts @@ -18,7 +18,7 @@ export class ExamplesDialog { private dialog: MatDialogRef, private workspaceService: WorkspaceService ) { - this.examples = this.getExamplesForRobot(this.appState.getSelectedRobotType().id) + this.examples = this.getExamplesForRobot(this.appState.selectedRobotType.id) this.filtered = this.examples } @@ -44,7 +44,7 @@ export class ExamplesDialog { .then(res => res.text()) this.workspaceService.restoreWorkspaceFromMessage({ - payload: { data: sketch, type: 'beginner', extension: this.appState.getSelectedRobotType().id }, + payload: { data: sketch, type: 'beginner', extension: this.appState.selectedRobotType.id }, displayTimeout: 2000 }) this.close() diff --git a/src/app/modules/core/dialogs/file-explorer/file-explorer.dialog.ts b/src/app/modules/core/dialogs/file-explorer/file-explorer.dialog.ts index ecda1e77..5176fa1a 100644 --- a/src/app/modules/core/dialogs/file-explorer/file-explorer.dialog.ts +++ b/src/app/modules/core/dialogs/file-explorer/file-explorer.dialog.ts @@ -22,7 +22,7 @@ export class FileExplorerDialog { private robotWiredState: RobotWiredState ) { this.upload.connect().then(() => { - this.robotWiredState.setSerialPort(this.upload.port) + this.robotWiredState.serialPort = this.upload.port this.upload.runFileSystemCommand('ls', this.currentPath).then((files) => { this.dirContent = files; }); diff --git a/src/app/modules/core/dialogs/info/info.dialog.html b/src/app/modules/core/dialogs/info/info.dialog.html index 9adfc157..3a0d853b 100644 --- a/src/app/modules/core/dialogs/info/info.dialog.html +++ b/src/app/modules/core/dialogs/info/info.dialog.html @@ -22,7 +22,7 @@

- {{(appState.releaseVersion$ | async)}} + {{(appState.releaseVersion)}}

diff --git a/src/app/modules/core/dialogs/language-select/language-select.dialog.html b/src/app/modules/core/dialogs/language-select/language-select.dialog.html index 5c1452db..f88812b3 100644 --- a/src/app/modules/core/dialogs/language-select/language-select.dialog.html +++ b/src/app/modules/core/dialogs/language-select/language-select.dialog.html @@ -1,11 +1,11 @@
- -
- -
+ +
+ +
diff --git a/src/app/modules/core/dialogs/language-select/language-select.dialog.ts b/src/app/modules/core/dialogs/language-select/language-select.dialog.ts index 2b4191d9..85ba7c58 100644 --- a/src/app/modules/core/dialogs/language-select/language-select.dialog.ts +++ b/src/app/modules/core/dialogs/language-select/language-select.dialog.ts @@ -15,7 +15,9 @@ export class LanguageSelectDialog { ) { } public onLanguageSelected(language: Language) { - this.appState.setCurrentLanguage(language); + this.appState.currentLanguage = language; this.dialogRef.close(); } + + protected readonly AppState = AppState; } diff --git a/src/app/modules/core/dialogs/upload/upload.dialog.ts b/src/app/modules/core/dialogs/upload/upload.dialog.ts index a5db487d..08bc99cd 100644 --- a/src/app/modules/core/dialogs/upload/upload.dialog.ts +++ b/src/app/modules/core/dialogs/upload/upload.dialog.ts @@ -54,26 +54,26 @@ export class UploadDialog { } public async startUpload(source_code: string, board: string, libraries: string) { - this.dialogState.setIsSerialOutputListening(false); + this.dialogState.isSerialOutputListening = false; if (!navigator.serial && !navigator.usb) { - this.uploadState.setStatusMessage('NO_SERIAL_SUPPORT') - this.uploadState.setFailed(true) - this.uploadState.setDone(true) + this.uploadState.statusMessage = 'NO_SERIAL_SUPPORT' + this.uploadState.failed = true + this.uploadState.done = true return } - if (this.robotWiredState.getSerialPort() === null) { + if (this.robotWiredState.serialPort === null) { try { await this.upload.connect() - this.robotWiredState.setSerialPort(this.upload.port); + this.robotWiredState.serialPort = this.upload.port; } catch (error) { if (error.toString() === 'Error: No device selected') { - this.uploadState.setFailed(true) - this.uploadState.setStatusMessage('NO_DEVICE_SELECTED') + this.uploadState.failed = true + this.uploadState.statusMessage = 'NO_DEVICE_SELECTED' console.error(error); } else { - this.uploadState.setStatusMessage("UPDATE_FAILED") - this.uploadState.setError(error.toString()) + this.uploadState.statusMessage = "UPDATE_FAILED" + this.uploadState.error = error.toString() console.error(error); } @@ -81,54 +81,53 @@ export class UploadDialog { } } - this.robotWiredState.getAbortController()?.abort("Upload started"); - this.upload.setPort(this.robotWiredState.getSerialPort()); + this.robotWiredState.abortController?.abort("Upload started"); + this.upload.setPort(this.robotWiredState.serialPort); this.uploadState.addProgress(25); - this.uploadState.setStatusMessage('COMPILATION_STARTED'); + this.uploadState.statusMessage = 'COMPILATION_STARTED'; const response = await this.compile(source_code, board, libraries).catch(error => { - this.uploadState.setStatusMessage('COMPILATION_FAILED'); + this.uploadState.statusMessage = 'COMPILATION_FAILED'; // make the printed red text console.log('%c' + error.toString(), 'color: red'); // remove the last 4 lines of the error message const errorLines = error.toString().split("\n"); errorLines.splice(errorLines.length - 5, 5); - const errorString = errorLines.join("\n"); - this.uploadState.setError(errorString) + this.uploadState.error = errorLines.join("\n") }) if (!response) return this.uploadState.addProgress(25); - this.uploadState.setStatusMessage('UPDATE_STARTED') + this.uploadState.statusMessage = 'UPDATE_STARTED' try { await this.upload.upload(response); } catch (error) { - this.uploadState.setError(error.toString()) + this.uploadState.error = error.toString() console.error(error); } - this.uploadState.setDone(true); + this.uploadState.done = true; console.log("Finished upload"); } returnBlockEnvironment() { - this.dialogState.setIsSerialOutputListening(true); + this.dialogState.isSerialOutputListening = true; this.dialogRef.close("BLOCK_ENVIRONMENT"); } returnHelpEnvironment() { - this.dialogState.setIsSerialOutputListening(true); + this.dialogState.isSerialOutputListening = true; this.dialogRef.close("HELP_ENVIRONMENT"); } async reconnect() { try { const port = await navigator.usb.requestDevice({ - filters: this.robotWiredState.SUPPORTED_VENDORS.map(vendor => ({ + filters: RobotWiredState.SUPPORTED_VENDORS.map(vendor => ({ vendorId: vendor })) }) diff --git a/src/app/modules/shared/components/button-bar/button-bar.component.ts b/src/app/modules/shared/components/button-bar/button-bar.component.ts index a2b520bf..ab69bf04 100644 --- a/src/app/modules/shared/components/button-bar/button-bar.component.ts +++ b/src/app/modules/shared/components/button-bar/button-bar.component.ts @@ -19,15 +19,15 @@ export class ButtonBarComponent { ) { } public onSideNavToggled() { - this.blocklyState.setIsSideNavOpenToggled(); + this.blocklyState.isSideNavOpen = !this.blocklyState.isSideNavOpen; } public onShowSerialOutputClicked() { - this.dialogState.setIsSerialOutputWindowOpen(true); + this.dialogState.isSerialOutputWindowOpen = true; } public onShowLibraryManagerClicked() { - this.dialogState.setIsLibraryManagerWindowOpen(true); + this.dialogState.isLibraryManagerWindowOpen = true; } protected readonly AppState = AppState; diff --git a/src/app/modules/shared/components/library-manager/library-manager.component.ts b/src/app/modules/shared/components/library-manager/library-manager.component.ts index 1a2a158d..c4ce5bf6 100644 --- a/src/app/modules/shared/components/library-manager/library-manager.component.ts +++ b/src/app/modules/shared/components/library-manager/library-manager.component.ts @@ -10,14 +10,14 @@ import {AnnotatedLibrary, Library, LibraryResponse} from "src/app/domain/library styleUrls: ["./library-manager.component.scss"], }) export class LibraryManagerComponent { - public libraries: AnnotatedLibrary[] = []; + private librariesBack: AnnotatedLibrary[] = []; constructor( public editorState: CodeEditorState, public dialogState: DialogState, private dialog: MatDialogRef ) { - if (this.editorState.getLibraryCache().length === 0) { + if (this.editorState.libraryCache.length === 0) { this.loadLibraryCache().then(); } @@ -49,25 +49,23 @@ export class LibraryManagerComponent { }) }) - this.editorState.setLibraryCache(Array.from(result.values())); + this.editorState.libraryCache = Array.from(result.values()); this.filter(); } - public setLibraries(libraries: Library[]) { - const installed = this.editorState.getInstalledLibraries(); + set libraries(libraries: Library[]) { + const installed = this.editorState.installedLibraries; - this.libraries = libraries.map(lib => ({ + this.librariesBack = libraries.map(lib => ({ ...lib, installed: installed.find(installedLib => installedLib.name === lib.name)?.version })) } public filter(filter = "") { - this.setLibraries( - this.editorState.getLibraryCache() + this.libraries = this.editorState.libraryCache .filter(lib => lib.name.toLowerCase().includes(filter.toLowerCase())) .slice(0, 50) - ); } public close() { @@ -76,22 +74,22 @@ export class LibraryManagerComponent { public install(library: Library, version: string) { // get installed libraries and remove existing version - const installed = this.editorState.getInstalledLibraries() + const installed = this.editorState.installedLibraries .filter((lib) => lib.name !== library.name); - this.editorState.setInstalledLibraries([...installed, { + this.editorState.installedLibraries = [...installed, { ...library, version - }]); - this.setLibraries(this.libraries); + }]; + this.libraries = this.librariesBack; } public uninstall(library: Library) { - const installed = this.editorState.getInstalledLibraries(); + const installed = this.editorState.installedLibraries; const current = installed.find((lib) => lib.name === library.name); if (!current) return; - this.editorState.setInstalledLibraries(installed.filter((lib) => lib.name !== library.name)); - this.setLibraries(this.libraries); + this.editorState.installedLibraries = installed.filter((lib) => lib.name !== library.name); + this.libraries = this.librariesBack; } } diff --git a/src/app/modules/shared/components/serial-output/serial-output.component.ts b/src/app/modules/shared/components/serial-output/serial-output.component.ts index dbc28dba..b8a538d3 100644 --- a/src/app/modules/shared/components/serial-output/serial-output.component.ts +++ b/src/app/modules/shared/components/serial-output/serial-output.component.ts @@ -49,7 +49,7 @@ export class SerialOutputComponent implements AfterViewInit, OnInit { public async write(data: string) { - const writer = this.robotWiredState.getSerialWrite(); + const writer = this.robotWiredState.serialWrite; if (!writer) return; await writer.write(new TextEncoder().encode(`${data}\n`)); @@ -118,11 +118,11 @@ export class SerialOutputComponent implements AfterViewInit, OnInit { } public onViewTextOutputClicked() { - this.dialogState.setIsSerialGraphOutputSelected(false); + this.dialogState.isSerialGraphOutputSelected = false; } public onViewGraphOutputClicked() { - this.dialogState.setIsSerialGraphOutputSelected(true); + this.dialogState.isSerialGraphOutputSelected = true; } public onClearSerialDataClicked() { diff --git a/src/app/modules/shared/components/terminal/terminal.component.ts b/src/app/modules/shared/components/terminal/terminal.component.ts index 672b374b..bd8c6e91 100644 --- a/src/app/modules/shared/components/terminal/terminal.component.ts +++ b/src/app/modules/shared/components/terminal/terminal.component.ts @@ -24,10 +24,10 @@ export class TerminalComponent implements AfterViewInit { let currentLine = ''; let currentIndent = 0; this.child.onData().subscribe((input) => { - if (!this.robotWireState.getPythonDeviceConnected()) { + if (!this.robotWireState.pythonDeviceConnected) { return; } - if (this.robotWireState.getPythonSerialMonitorListening()) { + if (this.robotWireState.pythonSerialMonitorListening) { if (input === '\u0003') { // Send keyboard interrupt to Python code (async () => { @@ -90,11 +90,11 @@ export class TerminalComponent implements AfterViewInit { }); this.robotWireState.isPythonSerialMonitorListening$.subscribe(async (isRunning) => { - if (!this.robotWireState.getPythonDeviceConnected()) { + if (!this.robotWireState.pythonDeviceConnected) { return; } if (isRunning) { - const port = this.robotWireState.getSerialPort(); + const port = this.robotWireState.serialPort; const abortController = new AbortController(); const child = this.child; @@ -151,8 +151,8 @@ export class TerminalComponent implements AfterViewInit { decode(c); if (done) { - this.robotWireState.setPythonSerialMonitorListening(false); - this.robotWireState.setPythonCodeRunning(false); + this.robotWireState.pythonSerialMonitorListening = false; + this.robotWireState.pythonCodeRunning = false; } }, }); @@ -164,22 +164,22 @@ export class TerminalComponent implements AfterViewInit { pipePromise.catch((error) => { if (error.toString().includes('Upload started')) { - this.robotWireState.setPythonSerialMonitorListening(false); - this.robotWireState.setPythonCodeRunning(false); + this.robotWireState.pythonSerialMonitorListening = false; + this.robotWireState.pythonCodeRunning = false; console.log('Stream aborted'); } else if (error.toString().includes('The device has been lost.')) { - this.robotWireState.setSerialPort(null); + this.robotWireState.serialPort = null; console.log('Device disconnected'); } else if (error.toString().includes('Running code done')) { console.log('Running code done'); } else if (error.toString().includes('Successfully aborted')) { this.child.write('\x1b[31m' + 'Keyboard interrupt' + '\x1b[0m'); this.abortController = null; - this.robotWireState.setPythonSerialMonitorListening(false); - this.robotWireState.setPythonCodeRunning(false); + this.robotWireState.pythonSerialMonitorListening = false; + this.robotWireState.pythonCodeRunning = false; this.pythonUploader.sendKeyboardInterrupt(); } else { - this.robotWireState.setSerialPort(null); + this.robotWireState.serialPort = null; console.error('Error while piping stream:', error); } }) diff --git a/src/app/services/arduino-uploader/ArduinoUploader.ts b/src/app/services/arduino-uploader/ArduinoUploader.ts index 79998fac..2465db3f 100644 --- a/src/app/services/arduino-uploader/ArduinoUploader.ts +++ b/src/app/services/arduino-uploader/ArduinoUploader.ts @@ -13,6 +13,7 @@ class Arduino { uploadState: UploadState appState: AppState + /** * Create a new Arduino instance. * @param serialOptions The options to use when opening the serial port. @@ -58,10 +59,10 @@ class Arduino { * @param outputStream The stream to write to */ async serialMonitor(outputStream: WritableStream) { - if (this.robotWiredState.getSerialPort() == null) { + if (this.robotWiredState.serialPort == null) { return; } - this.port = this.robotWiredState.getSerialPort(); + this.port = this.robotWiredState.serialPort; try { if (this.port.readable != null && this.port.readable.locked) { @@ -81,7 +82,7 @@ class Arduino { await clearReadBuffer(this.readStream); this.readStream.releaseLock(); - this.robotWiredState.setSerialWrite(this.writeStream); + this.robotWiredState.serialWrite = this.writeStream; const pipePromise = readableStream.pipeTo(outputStream, { signal: abortController.signal }); pipePromise.catch((error) => { @@ -89,10 +90,10 @@ class Arduino { outputStream.abort("Upload started") console.log('Stream aborted'); } else if (error.toString().includes('The device has been lost.')) { - this.robotWiredState.setSerialPort(null); + this.robotWiredState.serialPort = null; console.log('Device disconnected'); } else { - this.robotWiredState.setSerialPort(null); + this.robotWiredState.serialPort = null; console.error('Error while piping stream:', error); } }).then( @@ -110,11 +111,11 @@ class Arduino { const port = await this.robotWiredState.requestSerialPort(false) if (!port) { this.port = null - this.robotWiredState.setSerialPort(null) + this.robotWiredState.serialPort = null return } - this.robotWiredState.setSerialPort(port) + this.robotWiredState.serialPort = port this.setPort(port) await this.port.open({baudRate: 115200}) @@ -122,7 +123,7 @@ class Arduino { } ); - this.robotWiredState.setAbortController(abortController); + this.robotWiredState.abortController = abortController; } catch (e) { console.log(e); if (this.port == null) { @@ -134,7 +135,7 @@ class Arduino { } this.port = null; - this.robotWiredState.setSerialPort(null); + this.robotWiredState.serialPort = null; console.log(e); } } @@ -148,7 +149,7 @@ class Arduino { if (this.port == null) throw new Error('No device selected') - const Uploader = this.appState.getSelectedRobotType().protocol.protocol + const Uploader = this.appState.selectedRobotType.protocol.protocol this.isUploading = true const upload = new Uploader(this.port, this.robotWiredState, this.uploadState, this) diff --git a/src/app/services/arduino-uploader/protocols/avrdude/index.ts b/src/app/services/arduino-uploader/protocols/avrdude/index.ts index c9f86435..0ba36e6e 100644 --- a/src/app/services/arduino-uploader/protocols/avrdude/index.ts +++ b/src/app/services/arduino-uploader/protocols/avrdude/index.ts @@ -30,7 +30,7 @@ export default class Avrdude extends BaseProtocol { avrdude.FS.writeFile('/tmp/avrdude.conf', avrdudeConfig) avrdude.FS.writeFile('/tmp/program.hex', response['hex']) // get board - const mcu = this.uploader.appState.getSelectedRobotType().protocol?.microcontroller + const mcu = this.uploader.appState.selectedRobotType.protocol?.microcontroller if (!supportedMicrocontrollers.includes(mcu)) { throw new Error('Unsupported microcontroller') } @@ -68,7 +68,7 @@ export default class Avrdude extends BaseProtocol { } throw new Error('Avrdude failed') } - this.uploadState.setStatusMessage("UPDATE_COMPLETE") + this.uploadState.statusMessage ="UPDATE_COMPLETE" return } } diff --git a/src/app/services/arduino-uploader/protocols/dfu/index.ts b/src/app/services/arduino-uploader/protocols/dfu/index.ts index a5982378..efc6320f 100644 --- a/src/app/services/arduino-uploader/protocols/dfu/index.ts +++ b/src/app/services/arduino-uploader/protocols/dfu/index.ts @@ -17,9 +17,9 @@ export default class DFU extends BaseProtocol { const port = await this.waitForPort() await port.open({ baudRate: 115200 }) - this.robotWiredState.setSerialPort(port) + this.robotWiredState.serialPort = port this.uploader.setPort(port) - this.uploadState.setStatusMessage("UPDATE_COMPLETE") + this.uploadState.statusMessage = "UPDATE_COMPLETE" } } diff --git a/src/app/services/arduino-uploader/protocols/pico/index.ts b/src/app/services/arduino-uploader/protocols/pico/index.ts index cd3a27d9..59232ea6 100644 --- a/src/app/services/arduino-uploader/protocols/pico/index.ts +++ b/src/app/services/arduino-uploader/protocols/pico/index.ts @@ -19,9 +19,9 @@ export default class Pico extends BaseProtocol { const port = await this.waitForPort() await port.open({ baudRate: 115200 }) - this.robotWiredState.setSerialPort(port) + this.robotWiredState.serialPort = port this.uploader.setPort(port) - this.uploadState.setStatusMessage("UPDATE_COMPLETE") + this.uploadState.statusMessage = "UPDATE_COMPLETE" } } diff --git a/src/app/services/python-uploader/PythonUploader.service.ts b/src/app/services/python-uploader/PythonUploader.service.ts index d906bd04..c650831a 100644 --- a/src/app/services/python-uploader/PythonUploader.service.ts +++ b/src/app/services/python-uploader/PythonUploader.service.ts @@ -24,14 +24,14 @@ export class PythonUploaderService { private async setPythonCodeRunning(isRunning: boolean) { - if (this.robotWiredState.getPythonCodeRunning() === isRunning && isRunning) { + if (this.robotWiredState.pythonCodeRunning === isRunning && isRunning) { throw new Error('There is already a program running') } if (!isRunning) { - this.robotWiredState.setPythonSerialMonitorListening(false); + this.robotWiredState.pythonSerialMonitorListening = false; } - this.robotWiredState.setPythonCodeRunning(isRunning); + this.robotWiredState.pythonCodeRunning = isRunning; } async sendKeyboardInterrupt() { @@ -79,7 +79,7 @@ export class PythonUploaderService { writer.releaseLock(); reader.releaseLock(); this.packageManager.port = port; - this.robotWiredState.setSerialPort(port); + this.robotWiredState.serialPort = port; try { await this.setPythonCodeRunning(false); } catch (error) {} @@ -117,7 +117,7 @@ export class PythonUploaderService { async runCode(code: string) { this.robotWiredState.addToUploadLog('Running code'); await this.setPythonCodeRunning(true) - this.robotWiredState.setPythonSerialMonitorListening(true); + this.robotWiredState.pythonSerialMonitorListening = true; if (this.port === null) throw new Error('Not connected') const writer = this.port.writable.getWriter(); diff --git a/src/app/services/workspace.service.ts b/src/app/services/workspace.service.ts index 46efc20b..0b24c97d 100644 --- a/src/app/services/workspace.service.ts +++ b/src/app/services/workspace.service.ts @@ -68,27 +68,26 @@ export class WorkspaceService { data: {message: 'WORKSPACE_RESTORING'} }) if (message.payload.type == 'advanced' || message.payload.type == 'python') { - this.codeEditorState.setOriginalCode(message.payload.data as string); - this.codeEditorState.setCode(message.payload.data as string); + this.codeEditorState.code = message.payload.data as string; if (message.payload.type == 'advanced') { - this.appState.setSelectedCodeEditor(CodeEditorType.CPP); + this.appState.selectedCodeEditor = CodeEditorType.CPP; } else if (message.payload.type == 'python') { - this.appState.setSelectedCodeEditor(CodeEditorType.Python); + this.appState.selectedCodeEditor = CodeEditorType.Python; } - this.blocklyState.setProjectFileHandle(message.payload.projectFilePath); + this.blocklyState.projectFileHandle = message.payload.projectFilePath; await this.loadWorkspace(); this.appState.setSelectedRobotType(genericRobotType, true); return; } this.appState.setSelectedRobotType(AppState.idToRobotType[message.payload.extension.replace('.', '')], true); - this.blocklyState.setWorkspaceJSON(message.payload.data as string); - this.blocklyState.setProjectFileHandle(message.payload.projectFilePath); + this.blocklyState.workspaceJSON = message.payload.data as string; + this.blocklyState.projectFileHandle = message.payload.projectFilePath; await this.loadWorkspace(); } public async switchCodeEditor() { - const editor = this.appState.getCurrentEditor() - if (!this.codeEditorState.getSaveState() && editor === CodeEditorType.CPP) { + const editor = this.appState.currentEditor + if (!this.codeEditorState.saveState && editor === CodeEditorType.CPP) { const confirmed = await firstValueFrom( this.dialog.open(ConfirmEditorDialog, { width: '300px' @@ -98,11 +97,11 @@ export class WorkspaceService { } if (editor === CodeEditorType.Beginner) { - this.appState.setSelectedCodeEditor(CodeEditorType.CPP); - this.codeEditorState.setSaveState(false) + this.appState.selectedCodeEditor = CodeEditorType.CPP; + this.codeEditorState.saveState = false } else { - this.appState.setSelectedCodeEditor(CodeEditorType.Beginner); - this.codeEditorState.setSaveState(true) + this.appState.selectedCodeEditor = CodeEditorType.Beginner; + this.codeEditorState.saveState = true } } @@ -117,7 +116,7 @@ export class WorkspaceService { public async saveWorkspaceAs(robotExtension: string) { let onPythonRobot = false; - if (this.appState.getCurrentEditor() == CodeEditorType.Python) { + if (this.appState.currentEditor == CodeEditorType.Python) { const result = await this.dialog.open(LocationSelectDialog, { width: '75vw', disableClose: true, data: {options: ["THIS_COMPUTER", "MICROCONTROLLER"]} @@ -137,7 +136,7 @@ export class WorkspaceService { fileNamesDialogRef.afterClosed().subscribe((name: string) => { if (name == null) return - if (this.appState.getCurrentEditor() == CodeEditorType.Beginner) { + if (this.appState.currentEditor == CodeEditorType.Beginner) { const data = this.blocklyState.workspaceJSON; const blob = new Blob([data], { type: 'text/plain' }); const url = window.URL.createObjectURL(blob); @@ -148,8 +147,8 @@ export class WorkspaceService { a.click(); window.URL.revokeObjectURL(url); a.remove(); - } else if (this.appState.getCurrentEditor() == CodeEditorType.CPP) { - const data = this.codeEditorState.getCode(); + } else if (this.appState.currentEditor == CodeEditorType.CPP) { + const data = this.codeEditorState.code; const blob = new Blob([data], { type: 'text/plain' }); const url = window.URL.createObjectURL(blob); const a = document.createElement('a'); @@ -160,17 +159,17 @@ export class WorkspaceService { window.URL.revokeObjectURL(url); // delete a after it is clicked a.remove(); - } else if (this.appState.getCurrentEditor() == CodeEditorType.Python) { + } else if (this.appState.currentEditor == CodeEditorType.Python) { if (onPythonRobot) { - if (!this.robotWiredState.getSerialPort()) { + if (!this.robotWiredState.serialPort) { this.uploaderService.connect().then(() => { - this.uploaderService.runFileSystemCommand('put', name + '.py', this.codeEditorState.getCode()); + this.uploaderService.runFileSystemCommand('put', name + '.py', this.codeEditorState.code); }); } else { - this.uploaderService.runFileSystemCommand('put', name + '.py', this.codeEditorState.getCode()); + this.uploaderService.runFileSystemCommand('put', name + '.py', this.codeEditorState.code); } } else { - const data = this.codeEditorState.getCode(); + const data = this.codeEditorState.code; const blob = new Blob([data], {type: 'text/plain'}); const url = window.URL.createObjectURL(blob); const a = document.createElement('a'); @@ -193,22 +192,22 @@ export class WorkspaceService { */ public async saveWorkspace() { - if (this.blocklyState.getProjectFileHandle()) { - console.log(this.blocklyState.getProjectFileHandle()); - const file = this.blocklyState.getProjectFileHandle(); + if (this.blocklyState.projectFileHandle) { + console.log(this.blocklyState.projectFileHandle); + const file = this.blocklyState.projectFileHandle; if (file instanceof PythonFile) { - await this.uploaderService.runFileSystemCommand('put', file.path, this.codeEditorState.getCode()); + await this.uploaderService.runFileSystemCommand('put', file.path, this.codeEditorState.code); return; } const writable = await file.createWritable(); - if (this.appState.getCurrentEditor() == CodeEditorType.Beginner) { + if (this.appState.currentEditor == CodeEditorType.Beginner) { await writable.write({type: 'write', data: this.blocklyState.workspaceJSON, position: 0}); } else { - await writable.write({type: 'write', data: this.codeEditorState.getCode(), position: 0}); + await writable.write({type: 'write', data: this.codeEditorState.code, position: 0}); } await writable.close(); } else { - await this.saveWorkspaceAs(this.appState.getSelectedRobotType().id); + await this.saveWorkspaceAs(this.appState.selectedRobotType.id); } this.codeEditorState.afterSave() @@ -216,12 +215,12 @@ export class WorkspaceService { public async saveWorkspaceTemp(data) { sessionStorage.setItem('workspace', data); - sessionStorage.setItem('robotType', this.appState.getSelectedRobotType().id); - if (this.appState.getCurrentEditor() == CodeEditorType.Beginner) { + sessionStorage.setItem('robotType', this.appState.selectedRobotType.id); + if (this.appState.currentEditor == CodeEditorType.Beginner) { sessionStorage.setItem('type', 'beginner'); - } else if (this.appState.getCurrentEditor() == CodeEditorType.CPP) { + } else if (this.appState.currentEditor == CodeEditorType.CPP) { sessionStorage.setItem('type', 'advanced'); - } else if (this.appState.getCurrentEditor() == CodeEditorType.Python) { + } else if (this.appState.currentEditor == CodeEditorType.Python) { sessionStorage.setItem('type', 'python'); } } @@ -234,7 +233,7 @@ export class WorkspaceService { * Restore the workspace from a file */ public async restoreWorkspace() { - if (this.appState.getCurrentEditor() == CodeEditorType.Python) { + if (this.appState.currentEditor == CodeEditorType.Python) { const result = await this.dialog.open(LocationSelectDialog, { width: '75vw', disableClose: true, data: {options: ["THIS_COMPUTER", "MICROCONTROLLER"]} @@ -247,9 +246,8 @@ export class WorkspaceService { }).afterClosed().subscribe(async (fileName) => { if (fileName) { const content = await this.uploaderService.runFileSystemCommand('get', fileName); - this.codeEditorState.setOriginalCode(content); - this.codeEditorState.setCode(content); - this.blocklyState.setProjectFileHandle(new PythonFile(fileName)); + this.codeEditorState.code = content; + this.blocklyState.projectFileHandle = new PythonFile(fileName); } }); return; @@ -290,26 +288,24 @@ export class WorkspaceService { const workspaceTemp = sessionStorage.getItem('workspace'); const robotType = sessionStorage.getItem('robotType'); const type = sessionStorage.getItem('type'); - this.blocklyState.setProjectFileHandle(null); - if (type == 'beginner' && this.appState.getCurrentEditor() == CodeEditorType.Beginner) { - if (robotType != this.appState.getSelectedRobotType().id) { + this.blocklyState.projectFileHandle = null; + if (type == 'beginner' && this.appState.currentEditor == CodeEditorType.Beginner) { + if (robotType != this.appState.selectedRobotType.id) { return; } this.restoreWorkspaceFromMessage({ payload: {projectFilePath: null, data: workspaceTemp, type: 'beginner', extension: robotType}, displayTimeout: 1000 }) - } else if (type == 'advanced' && this.appState.getCurrentEditor() == CodeEditorType.CPP) { + } else if (type == 'advanced' && this.appState.currentEditor == CodeEditorType.CPP) { try { - this.codeEditorState.setOriginalCode(workspaceTemp); - this.codeEditorState.setCode(workspaceTemp); + this.codeEditorState.code = workspaceTemp; } catch (error) { console.log('Error:', error.message); } - } else if (type == 'python' && this.appState.getCurrentEditor() == CodeEditorType.Python) { + } else if (type == 'python' && this.appState.currentEditor == CodeEditorType.Python) { try { - this.codeEditorState.setOriginalCode(workspaceTemp); - this.codeEditorState.setCode(workspaceTemp); + this.codeEditorState.code = workspaceTemp; } catch (error) { console.log('Error:', error.message); } @@ -329,27 +325,25 @@ export class WorkspaceService { const workspaceTemp = sessionStorage.getItem('workspace'); const robotType = sessionStorage.getItem('robotType'); const type = sessionStorage.getItem('type'); - this.blocklyState.setProjectFileHandle(null); + this.blocklyState.projectFileHandle = null; this.appState.setSelectedRobotType(AppState.idToRobotType[robotType], true); if (type == 'beginner') { - this.appState.setSelectedCodeEditor(CodeEditorType.Beginner); + this.appState.selectedCodeEditor = CodeEditorType.Beginner; this.restoreWorkspaceFromMessage({ payload: {projectFilePath: null, data: workspaceTemp, type: 'beginner', extension: robotType}, displayTimeout: 1000 }) } else if (type == 'advanced') { - this.appState.setSelectedCodeEditor(CodeEditorType.CPP); + this.appState.selectedCodeEditor = CodeEditorType.CPP; try { - this.codeEditorState.setOriginalCode(workspaceTemp); - this.codeEditorState.setCode(workspaceTemp); + this.codeEditorState.code = workspaceTemp; } catch (error) { console.log('Error:', error.message); } } else if (type == 'python') { - this.appState.setSelectedCodeEditor(CodeEditorType.Python); + this.appState.selectedCodeEditor = CodeEditorType.Python; try { - this.codeEditorState.setOriginalCode(workspaceTemp); - this.codeEditorState.setCode(workspaceTemp); + this.codeEditorState.code = workspaceTemp; } catch (error) { console.log('Error:', error.message); } @@ -361,7 +355,7 @@ export class WorkspaceService { * Load workspace */ public async loadWorkspace() { - const workspace = this.blocklyState.getWorkspace(); + const workspace = this.blocklyState.workspace; const workspaceXml = this.blocklyState.workspaceJSON; if (!workspace) return; if (!workspaceXml) return; diff --git a/src/app/state/app.state.ts b/src/app/state/app.state.ts index fc104203..cc9b4cdc 100644 --- a/src/app/state/app.state.ts +++ b/src/app/state/app.state.ts @@ -21,7 +21,8 @@ import { CodeEditorType } from '../domain/code-editor.type'; import { LocalStorageService } from '../services/localstorage.service'; import { version } from '../../../package.json'; import {MatDialog} from "@angular/material/dialog"; -import {ConfirmEditorDialog} from "../modules/core/dialogs/confirm-editor/confirm-editor.dialog"; +import * as Blockly from "blockly/core"; +import {VariableDialog} from "../modules/core/dialogs/variable/variable.dialog"; @Injectable({ providedIn: 'root' @@ -29,6 +30,11 @@ import {ConfirmEditorDialog} from "../modules/core/dialogs/confirm-editor/confir export class AppState { /* eslint-disable max-len */ + public robotRows : RobotType[][] = [ + [leaphyFlitzRobotType, leaphyOriginalRobotType, leaphyClickRobotType], + [arduinoNanoRobotType, arduinoUnoRobotType, arduinoMegaRobotType], + [genericRobotType, microPythonRobotType], + ]; public static idToRobotType = { 'l_original_uno': leaphyOriginalRobotType, @@ -117,34 +123,32 @@ export class AppState { public releaseInfoSubject$ = new BehaviorSubject(null); public releaseInfo$: Observable = this.releaseInfoSubject$.asObservable(); - public releaseVersionSubject$ = new BehaviorSubject(version); - public releaseVersion$: Observable = this.releaseVersionSubject$.asObservable(); - private robotChoiceSubject$ = new BehaviorSubject(null) public robotChoice$ = this.robotChoiceSubject$.asObservable() - /* eslint-enable max-len */ - private defaultLanguage = new Language('nl', 'Nederlands') - private availableLanguages = [new Language('en', 'English'), this.defaultLanguage] + public static defaultLanguage = new Language('nl', 'Nederlands') + public static availableLanguages = [new Language('en', 'English'), AppState.defaultLanguage] + constructor(private localStorage: LocalStorageService, private dialog: MatDialog) { - this.isDesktopSubject$ = new BehaviorSubject(true); - this.isDesktop$ = this.isDesktopSubject$.asObservable(); - this.availableRobotTypes$ = this.isDesktop$ - .pipe(map(isDesktop => { - if (isDesktop) { - return [ - [leaphyFlitzRobotType, leaphyOriginalRobotType, leaphyClickRobotType], - [arduinoNanoRobotType, arduinoUnoRobotType, arduinoMegaRobotType], - [genericRobotType, microPythonRobotType], - ] - } else {} - })); - - const currentLanguage = this.localStorage.fetch('currentLanguage') || this.defaultLanguage; + try { + Blockly.dialog.setPrompt((msg, defaultValue, callback) => { + this.dialog.open(VariableDialog, { + width: '400px', + data: { name: defaultValue } + }).afterClosed().subscribe(result => { + callback(result); + }); + }); + } catch (e) { + console.log(e); + throw e; + } + + const currentLanguage = this.localStorage.fetch('currentLanguage') || AppState.defaultLanguage; this.currentLanguageSubject$ = new BehaviorSubject(currentLanguage); this.currentLanguage$ = this.currentLanguageSubject$.asObservable(); @@ -153,17 +157,9 @@ export class AppState { .pipe(map(robotType => robotType !== genericRobotType)); } - private isDesktopSubject$: BehaviorSubject; - public isDesktop$: Observable; - - public availableRobotTypes$: Observable; - private selectedRobotTypeSubject$ = new BehaviorSubject(null); public selectedRobotType$ = this.selectedRobotTypeSubject$.asObservable(); - private availableLanguagesSubject$ = new BehaviorSubject(this.availableLanguages); - public availableLanguages$ = this.availableLanguagesSubject$.asObservable(); - private currentLanguageSubject$: BehaviorSubject; public currentLanguage$: Observable @@ -176,9 +172,6 @@ export class AppState { private codeEditorSubject$ = new BehaviorSubject(CodeEditorType.None); public codeEditor$ = this.codeEditorSubject$.asObservable(); - private saveStateSubject$ = new BehaviorSubject(true) - public saveState$ = this.saveStateSubject$.asObservable() - public canChangeCodeEditor$: Observable; public setSelectedRobotType(robotType: RobotType, skipPopup: boolean = false) { @@ -191,37 +184,37 @@ export class AppState { this.robotChoiceSubject$.next(selector) } - public setChangedLanguage(language: Language) { + set changedLanguage(language: Language) { this.localStorage.store('currentLanguage', language); this.changedLanguageSubject$.next(language); } - public setCurrentLanguage(language: Language) { + set currentLanguage(language: Language) { this.localStorage.store('currentLanguage', language); this.currentLanguageSubject$.next(language); } - public setIsCodeEditorToggleConfirmed(confirmed: boolean) { + set isCodeEditorToggleConfirmed(confirmed: boolean) { this.isCodeEditorToggleConfirmedSubject$.next(confirmed); } - public setSelectedCodeEditor(codeEditor: CodeEditorType) { + set selectedCodeEditor(codeEditor: CodeEditorType) { this.codeEditorSubject$.next(codeEditor); } - public getCurrentLanguageCode(): string { + get currentLanguageCode(): string { return this.currentLanguageSubject$.getValue().code; } - public getCurrentEditor(): CodeEditorType { + get currentEditor(): CodeEditorType { return this.codeEditorSubject$.getValue(); } - public getSelectedRobotType(): RobotType { + get selectedRobotType(): RobotType { return this.selectedRobotTypeSubject$.getValue(); } - public getReleaseVersion(): string { - return this.releaseVersionSubject$.getValue(); + get releaseVersion(): string { + return version; } } diff --git a/src/app/state/blockly-editor.state.ts b/src/app/state/blockly-editor.state.ts index 497450be..7022ccfc 100644 --- a/src/app/state/blockly-editor.state.ts +++ b/src/app/state/blockly-editor.state.ts @@ -19,9 +19,6 @@ export class BlocklyEditorState { this.isSoundOn$ = this.isSoundOnSubject$.asObservable(); } - private isSideNavOpenToggledSubject$ = new BehaviorSubject(false); - public isSideNavOpenToggled$ = this.isSideNavOpenToggledSubject$.asObservable(); - private isSideNavOpenSubject$ = new BehaviorSubject(false); public isSideNavOpen$ = this.isSideNavOpenSubject$.asObservable(); @@ -73,60 +70,60 @@ export class BlocklyEditorState { private playSoundFunctionSubject$ = new BehaviorSubject<(name: string, opt_volume: number) => void>(null); public playSoundFunction$ = this.playSoundFunctionSubject$.asObservable(); - public setIsSideNavOpen(status: boolean) { + set isSideNavOpen(status: boolean) { this.isSideNavOpenSubject$.next(status); } - public setBlocklyElement(element: ElementRef) { + get isSideNavOpen(): boolean { + return this.isSideNavOpenSubject$.getValue(); + } + + set blocklyElement(element: ElementRef) { this.blocklyElementSubject$.next(element); } - public setToolboxXml(toolboxXml: any) { + set toolboxXml(toolboxXml: any) { this.toolboxXmlSubject$.next(toolboxXml); } - public setWorkspace(workspace: any) { + set workspace(workspace: any) { workspace.resize(); this.workspaceSubject$.next(workspace); } - public getWorkspace(): any { + get workspace(): any { return this.workspaceSubject$.getValue(); } - public setWorkspaceJSON(workspaceXml: any) { + set workspaceJSON(workspaceXml: any) { this.workspaceJSONSubject$.next(workspaceXml); } - public setProjectFileHandle(path: FileSystemFileHandle | PythonFile) { + set projectFileHandle(path: FileSystemFileHandle | PythonFile) { this.projectFileHandleSubject$.next(path); } - public getProjectFileHandle(): FileSystemFileHandle | PythonFile { + get projectFileHandle(): FileSystemFileHandle | PythonFile { return this.projectFileHandleSubject$.getValue(); } - public setUndo(redo: boolean) { + set undo(redo: boolean) { this.undoSubject$.next(redo); } - public setIsSoundToggled() { + set isSoundToggled(_: any) { this.isSoundToggledSubject$.next(true); } - public setIsSoundOn(isSoundOn: boolean) { + set isSoundOn(isSoundOn: boolean) { this.localStorage.store("isSoundOn", isSoundOn); this.isSoundOnSubject$.next(isSoundOn); } - public setPlaySoundFunction(fn: (name: string, opt_volume: number) => void) { + set playSoundFunction(fn: (name: string, opt_volume: number) => void) { this.playSoundFunctionSubject$.next(fn); } - public setIsSideNavOpenToggled() { - this.isSideNavOpenToggledSubject$.next(true); - } - get workspaceJSON(): string { return this.workspaceJSONSubject$.getValue(); } diff --git a/src/app/state/code-editor.state.ts b/src/app/state/code-editor.state.ts index 5ac5c1cb..0dbc0437 100644 --- a/src/app/state/code-editor.state.ts +++ b/src/app/state/code-editor.state.ts @@ -1,6 +1,5 @@ import {Injectable,} from "@angular/core"; import {BehaviorSubject, Observable} from "rxjs"; -import {map, withLatestFrom} from "rxjs/operators"; import {InstalledLibrary, Library} from "src/app/domain/library-manager.types"; @Injectable({ @@ -18,71 +17,30 @@ void loop() { }`; - public readonly pythonProgram = `from leaphymicropython.utils.pins import set_pwm`; - - private startCodeSubject$: BehaviorSubject = new BehaviorSubject(''); - public startCode$: Observable; - private codeSubject$: BehaviorSubject = new BehaviorSubject(''); public code$: Observable = this.codeSubject$.asObservable(); - private saveStateSubject$: BehaviorSubject = new BehaviorSubject(true) - - private libraryCacheSubject$: BehaviorSubject = new BehaviorSubject([]); - private InstalledLibraries$: BehaviorSubject = new BehaviorSubject([]); - - public isDirty$: Observable; - + public saveState: boolean = true + public libraryCache: Library[] = []; + public installedLibraries: InstalledLibrary[] =[]; - constructor() { - this.isDirty$ = this.code$ - .pipe(withLatestFrom(this.startCode$)) - .pipe(map(([code, original]) => code !== original)) - } - - public setOriginalCode(program: string){ - this.startCodeSubject$.next(program); - } + constructor() { } - public setCode(program: string){ + set code(program: string){ if ( this.codeSubject$.value !== program && this.codeSubject$.value !== this.originalProgram ) - this.saveStateSubject$.next(false); + this.saveState = false this.codeSubject$.next(program); } public afterSave() { - this.saveStateSubject$.next(true) - } - - public setSaveState(saved: boolean) { - this.saveStateSubject$.next(saved) + this.saveState = true } - public getSaveState() { - return this.saveStateSubject$.value - } - - public getCode(){ + get code(){ return this.codeSubject$.value; } - - public setLibraryCache(cache: Library[]){ - this.libraryCacheSubject$.next(cache); - } - - public getLibraryCache(){ - return this.libraryCacheSubject$.value; - } - - public setInstalledLibraries(libraries: InstalledLibrary[]){ - this.InstalledLibraries$.next(libraries); - } - - public getInstalledLibraries(){ - return this.InstalledLibraries$.value; - } } diff --git a/src/app/state/dialog.state.ts b/src/app/state/dialog.state.ts index af632094..f522bbc6 100644 --- a/src/app/state/dialog.state.ts +++ b/src/app/state/dialog.state.ts @@ -27,35 +27,35 @@ export class DialogState { public isExamplesDialogVisibleSubject$ = new BehaviorSubject(false); public isExamplesDialogVisible$ = this.isExamplesDialogVisibleSubject$.asObservable() - public setIsSerialOutputWindowOpen(isOpen: boolean) { + set isSerialOutputWindowOpen(isOpen: boolean) { this.isSerialOutputWindowOpenSubject$.next(isOpen); } - public setIsSerialOutputListening(isFocus: boolean) { + set isSerialOutputListening(isFocus: boolean) { this.isSerialOutputListeningSubject$.next(isFocus); } - public setIsSerialGraphOutputSelected(isSelected: boolean) { + set isSerialGraphOutputSelected(isSelected: boolean) { this.isSerialGraphOutputSelectedSubject$.next(isSelected); } - public setIsInfoDialogVisible(isVisible: boolean) { + set isInfoDialogVisible(isVisible: boolean) { this.isInfoDialogVisibleSubject$.next(isVisible); } - public getIsSerialOutputWindowOpen() { + get isSerialOutputWindowOpen() { return this.isSerialOutputWindowOpenSubject$.getValue(); } - public setIsLibraryManagerWindowOpen(isOpen: boolean) { + set isLibraryManagerWindowOpen(isOpen: boolean) { this.isLibraryManagerWindowOpenSubject$.next(isOpen); } - public getIsLibraryManagerWindowOpen() { + get isLibraryManagerWindowOpen() { return this.isLibraryManagerWindowOpenSubject$.getValue(); } - public setIsExamplesDialogVisible(isVisible: boolean) { + set isExamplesDialogVisible(isVisible: boolean) { this.isExamplesDialogVisibleSubject$.next(isVisible) } } diff --git a/src/app/state/robot.wired.state.ts b/src/app/state/robot.wired.state.ts index 3987cc6f..da56ce43 100644 --- a/src/app/state/robot.wired.state.ts +++ b/src/app/state/robot.wired.state.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { ChartDataset } from 'chart.js'; import { ReplaySubject, BehaviorSubject, Observable} from 'rxjs'; -import { filter, map, scan } from 'rxjs/operators'; +import { map, scan } from 'rxjs/operators'; import { SerialPort as MockedSerialPort } from "web-serial-polyfill"; @@ -13,12 +13,14 @@ export type LeaphyPort = SerialPort|MockedSerialPort }) export class RobotWiredState { - public SUPPORTED_VENDORS = [0x1a86, 9025, 2341, 0x0403, 0x2e8a] - private serialPortSubject$: BehaviorSubject = new BehaviorSubject(null); - - private abortControllerSubject$: BehaviorSubject = new BehaviorSubject(null); + /* Variables */ + public static SUPPORTED_VENDORS = [0x1a86, 9025, 2341, 0x0403, 0x2e8a] + public serialPort: LeaphyPort = null; + public abortController: AbortController = null; + public serialWrite: WritableStreamDefaultWriter = null; + /* Observables */ // Upload log, a Log of list of strings private uploadLogSubject$ = new BehaviorSubject([]); public uploadLog$: Observable = this.uploadLogSubject$.asObservable(); @@ -34,9 +36,8 @@ export class RobotWiredState { private serialDataSubject$ = new ReplaySubject<{ time: Date, data: string }>(); public serialData$: Observable<{ time: Date, data: string }[]> = this.serialDataSubject$ - .pipe(filter(output => !!output)) .pipe(scan((all, incoming) => { - if (incoming.data === this.poisonPill) { + if (incoming == null) { return []; } if (all.length > 100) { @@ -46,7 +47,7 @@ export class RobotWiredState { }, [])); - private serialWriteSubject$ = new BehaviorSubject>(null); + public serialChartDataSets$: Observable = this.serialData$ .pipe(map(data => { @@ -64,8 +65,7 @@ export class RobotWiredState { // If it's already there, push a data point into it if (labelSet) labelSet.data.push(dataPoint) - // Else create the new dataset - else sets.push({ label, data: [dataPoint] }); + // Else create the new dataset else sets.push({ label, data: [dataPoint] }); return sets; }, []) @@ -73,20 +73,13 @@ export class RobotWiredState { })); - public setIncomingSerialData(data: { time: Date, data: string }): void { + /* Functions */ + set incomingSerialData(data: { time: Date, data: string }) { this.serialDataSubject$.next(data); } - public setSerialWrite(data: WritableStreamDefaultWriter): void { - this.serialWriteSubject$.next(data); - } - - public getSerialWrite(): WritableStreamDefaultWriter { - return this.serialWriteSubject$.getValue(); - } - public clearSerialData(): void { - this.setIncomingSerialData({ time: new Date(), data: this.poisonPill }); + this.serialDataSubject$.next(null); } public async requestSerialPort(forcePrompt = false, allowPrompt = true) { @@ -99,7 +92,7 @@ export class RobotWiredState { } if (!port && allowPrompt) { port = await navigator.serial.requestPort({ - filters: this.SUPPORTED_VENDORS.map(vendor => ({ + filters: RobotWiredState.SUPPORTED_VENDORS.map(vendor => ({ usbVendorId: vendor })) }) @@ -111,7 +104,7 @@ export class RobotWiredState { } if (!port && allowPrompt) { const device = await navigator.usb.requestDevice({ - filters: this.SUPPORTED_VENDORS.map(vendor => ({ + filters: RobotWiredState.SUPPORTED_VENDORS.map(vendor => ({ vendorId: vendor })) }) @@ -128,22 +121,6 @@ export class RobotWiredState { return port } - public setSerialPort(port: LeaphyPort): void { - this.serialPortSubject$.next(port); - } - - public getSerialPort(): LeaphyPort { - return this.serialPortSubject$.getValue(); - } - - public setAbortController(abortController: AbortController): void { - this.abortControllerSubject$.next(abortController); - } - - public getAbortController(): AbortController { - return this.abortControllerSubject$.getValue(); - } - public addToUploadLog(log: string): void { this.uploadLogSubject$.next([...this.uploadLogSubject$.getValue(), log]); } @@ -152,29 +129,28 @@ export class RobotWiredState { this.uploadLogSubject$.next([]); } - public setPythonCodeRunning(isRunning: boolean): void { + set pythonCodeRunning(isRunning: boolean) { this.isPythonCodeRunningSubject$.next(isRunning); } - public getPythonCodeRunning(): boolean { + get pythonCodeRunning(): boolean { return this.isPythonCodeRunningSubject$.getValue(); } - public setPythonDeviceConnected(isConnected: boolean): void { + set pythonDeviceConnected(isConnected: boolean) { this.isPythonDeviceConnectedSubject$.next(isConnected); } - public getPythonDeviceConnected(): boolean { + get pythonDeviceConnected(): boolean { return this.isPythonDeviceConnectedSubject$.getValue(); } - public setPythonSerialMonitorListening(isListening: boolean): void { + set pythonSerialMonitorListening(isListening: boolean) { this.isPythonSerialMonitorListeningSubject$.next(isListening); } - public getPythonSerialMonitorListening(): boolean { + get pythonSerialMonitorListening(): boolean { return this.isPythonSerialMonitorListeningSubject$.getValue(); } - private readonly poisonPill: string = "caaa61a6-a666-4c0b-83b4-ebc75b08fecb" } diff --git a/src/app/state/upload.state.ts b/src/app/state/upload.state.ts index 2ab4cf4d..71768707 100644 --- a/src/app/state/upload.state.ts +++ b/src/app/state/upload.state.ts @@ -32,22 +32,22 @@ export class UploadState { this.progressSubject$.next(this.progressSubject$.getValue() + progress) } - public setStatusMessage(message: string) { + set statusMessage(message: string) { const translation = this.translate.instant(message); this.stateMessageSubject$.next(translation !== null ? translation : message.replace(/_/g, " ")); } - public setDone(done: boolean) { + set done(done: boolean) { this.doneSubject$.next(done) } - public setError(error: string) { - this.setFailed(true) + set error(error: string) { + this.failed = true this.errorSubject$.next(error) } - public setFailed(failed: boolean) { - this.setDone(true) + set failed(failed: boolean) { + this.done = true this.failedSubject$.next(failed) }