Skip to content
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

Upload/download robot code #9

Merged
merged 4 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
'@typescript-eslint/no-shadow': 'error',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'no-redeclare': 'off', // False positives on typescript's function overloads
},
parserOptions: {
ecmaVersion: 2022,
Expand Down
181 changes: 180 additions & 1 deletion release/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion release/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
"postinstall": "npm run rebuild && npm run link-modules",
"link-modules": "node -r ts-node/register ../../.erb/scripts/link-modules.ts"
},
"dependencies": {}
"dependencies": {
"@types/ssh2": "^1.15.0",
"ssh2": "^1.15.0"
}
}
10 changes: 5 additions & 5 deletions src/common/AppConsoleMessage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* A type of AppConsoleMessage.
*/
export type MessageType = 'dawn-err' | 'robot-err' | 'robot-info';
export type MessageType = 'dawn-err' | 'dawn-info' | 'robot-err' | 'robot-info';

/**
* Represents a formatted message in the AppConsole.
Expand All @@ -10,19 +10,19 @@ export default class AppConsoleMessage {
/**
* The type of the message.
*/
#type: MessageType;
readonly type: MessageType;

/**
* The text content of the message.
*/
#text: string;
readonly text: string;

/**
* @param type - the type of the message
* @param text - the text content of the message
*/
constructor(type: MessageType, text: string) {
this.#type = type;
this.#text = text;
this.type = type;
this.text = text;
}
}
72 changes: 67 additions & 5 deletions src/common/IpcEventTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
import type AppConsoleMessage from './AppConsoleMessage';

/**
* IPC event channels used for communication from the main process to the renderer.
*/
export type RendererChannels =
| 'renderer-init'
| 'renderer-robot-update'
| 'renderer-post-console'
| 'renderer-file-control'
| 'renderer-quit-request';
/**
* IPC event channels used for communication from the renderer to the main process.
*/
export type MainChannels = 'main-file-control' | 'main-quit';

/**
* Data for the renderer-init event, sent when the renderer process has finished initializing and is
* 'ready-to-show'.
Expand All @@ -10,6 +24,7 @@ export interface RendererInitData {
robotSSHAddress: string;
fieldIPAddress: string;
fieldStationNumber: string;
showDirtyUploadWarning: boolean;
}
/**
* Data for a specialization of the renderer-file-control event, sent when the main process wants to
Expand Down Expand Up @@ -40,7 +55,15 @@ interface RendererFcSaveData {
*/
interface RendererFcOpenData {
type: 'didOpen';
/**
* The loaded code.
*/
content: string;
/**
* Whether the content has just been read from the save path. False if the code is downloaded and
* may not match the contents of the save path.
*/
isCleanFile: boolean;
}
/**
* Data for a specialization of the renderer-file-control event, sent when the main process has
Expand All @@ -58,6 +81,22 @@ interface RendererFcPathData {
interface RendererFcExtChangeData {
type: 'didExternalChange';
}
/**
* Data for a specialization of the renderer-file-control event, sent when the main process wants to
* upload code from the last saved file to the robot and needs to ask the renderer process to notify
* the user in case this would ignore unsaved changes in the editor.
*/
interface RendererFcPrmtUploadData {
type: 'promptUpload';
}
/**
* Data for a specialization of the renderer-file-control event, sent when the main process wants to
* download code from the robot into the editor and needs to ask the renderer if this is ok (if
* there are no unsaved changes).
*/
interface RendererFcPrmtDownloadData {
type: 'promptDownload';
}
/**
* Data for the renderer-file-control event sent by the main process to request or submit
* information related to the code file and editor.
Expand All @@ -68,7 +107,9 @@ export type RendererFileControlData =
| RendererFcSaveData
| RendererFcOpenData
| RendererFcPathData
| RendererFcExtChangeData;
| RendererFcExtChangeData
| RendererFcPrmtUploadData
| RendererFcPrmtDownloadData;
/**
* Data for the renderer-post-console event sent by the main process to add a console message to the
* AppConsole.
Expand All @@ -79,9 +120,9 @@ export type RendererPostConsoleData = AppConsoleMessage;
* changes.
*/
export interface RendererRobotUpdateData {
newRuntimeVersion?: string;
newRobotBatteryVoltage?: number;
newRobotLatencyMs?: number;
runtimeVersion?: string;
robotBatteryVoltage?: number;
robotLatencyMs?: number;
}

/**
Expand All @@ -100,11 +141,31 @@ interface MainFcSaveData {
interface MainFcLoadData {
type: 'load';
}
/**
* Data for a specialization of the main-file-control event, sent by the renderer to
* initiate/respond to a request to upload the last opened file to the robot.
*/
interface MainFcUploadData {
type: 'upload';
robotSSHAddress: string;
}
/**
* Data for a specialization of the main-file-control event, sent by the renderer to
* initiate/respond to a request to download the code on the robot into the editor.
*/
interface MainFcDownloadData {
type: 'download';
robotSSHAddress: string;
}
/**
* Data for the main-file-control event sent by the renderer process to submit information related
* to the code file and editor.
*/
export type MainFileControlData = MainFcSaveData | MainFcLoadData;
export type MainFileControlData =
| MainFcSaveData
| MainFcLoadData
| MainFcUploadData
| MainFcDownloadData;
/**
* Data for the main-quit event sent by the renderer both to authorize a request to quit and to send
* updated configuration data that should be saved before the program closes.
Expand All @@ -114,4 +175,5 @@ export interface MainQuitData {
robotSSHAddress: string;
fieldIPAddress: string;
fieldStationNumber: string;
showDirtyUploadWarning: boolean;
}
7 changes: 7 additions & 0 deletions src/main/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default interface Config {
robotSSHAddress: string;
fieldIPAddress: string;
fieldStationNumber: string;
showDirtyUploadWarning: boolean;
}

/**
Expand Down Expand Up @@ -48,5 +49,11 @@ export function coerceToConfig(template: unknown): Config {
) {
config.fieldStationNumber = '4';
}
if (
!('showDirtyUploadWarning' in config) ||
typeof config.showDirtyUploadWarning !== 'boolean'
) {
config.showDirtyUploadWarning = true;
}
return config as Config; // By now we're sure all the fields (and maybe some more) are set
}
Loading
Loading