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

Fix unpredictable connection issues #44

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
7 changes: 4 additions & 3 deletions src/common/AppConsoleMessage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { randomUUID } from 'crypto';

/**
* A type of AppConsoleMessage.
*/
Expand Down Expand Up @@ -31,6 +29,9 @@ export default class AppConsoleMessage {
constructor(type: MessageType, text: string) {
this.type = type;
this.text = text;
this.uuid = randomUUID();
this.uuid = '';
for (let i = 0; i < 8; i += 1) {
this.uuid += `${Math.floor(Math.random() * 10000000)}-`;
}
}
}
56 changes: 44 additions & 12 deletions src/common/IpcEventTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ export type RendererChannels =
| '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'
| 'main-update-robot-mode'
| 'main-connection-config'
| 'main-robot-input';

/**
Expand Down Expand Up @@ -52,6 +54,7 @@ export interface RendererInitData {
*/
showDirtyUploadWarning: boolean;
}

/**
* Data for a specialization of the renderer-file-control event, sent when the main process wants to
* try saving the code and needs to ask the renderer process for the content of the editor.
Expand All @@ -67,6 +70,7 @@ export interface RendererFileControlPromptSaveData {
*/
forceDialog: boolean;
}

/**
* Data for a specialization of the renderer-file-control event, sent when the main process wants to
* try loading a file into the editor and needs to ask the renderer process if this is ok (if there
Expand All @@ -78,6 +82,7 @@ export interface RendererFileControlPromptLoadData {
*/
type: 'promptLoad';
}

/**
* Data for a specialization of the renderer-file-control event, sent when the main process has
* successfully saved the code and the renderer should clear the dirty editor indicator.
Expand All @@ -88,6 +93,7 @@ export interface RendererFileControlSaveData {
*/
type: 'didSave';
}

/**
* Data for a specialization of the renderer-file-control event, sent when the main process has
* successfully loaded code and the renderer should store the retrieved content in the editor.
Expand All @@ -107,6 +113,7 @@ export interface RendererFileControlOpenData {
*/
isCleanFile: boolean;
}

/**
* Data for a specialization of the renderer-file-control event, sent when the main process has
* successfully saved or loaded code and the renderer should update the path shown in the editor.
Expand All @@ -121,6 +128,7 @@ export interface RendererFileControlPathData {
*/
path: string;
}

/**
* Data for a specialization of the renderer-file-control event, sent when the main process detects
* external changes to the currently open file and the renderer should set the dirty editor
Expand All @@ -132,6 +140,7 @@ export interface RendererFileControlExtChangeData {
*/
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
Expand All @@ -143,6 +152,7 @@ export interface RendererFileControlPromptUploadData {
*/
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
Expand All @@ -154,13 +164,15 @@ export interface RendererFileControlPromptDownloadData {
*/
type: 'promptDownload';
}

/**
* Data for a specialization of the renderer-file-control event, sent when the main process wants to
* close the file open in the editor.
*/
interface RendererFileControlPromptCreateNewFile {
type: 'promptCreateNewFile';
}

/**
* 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 @@ -175,26 +187,31 @@ export type RendererFileControlData =
| RendererFileControlPromptUploadData
| RendererFileControlPromptDownloadData
| RendererFileControlPromptCreateNewFile;

/**
* Data for the renderer-post-console event sent by the main process to add a console message to the
* AppConsole.
*/
export type RendererPostConsoleData = AppConsoleMessage;

/**
* Data for the renderer-battery-update event sent by the main process to update the robot's battery
* voltage.
*/
export type RendererBatteryUpdateData = number;

/**
* Data for the renderer-latency-update event sent by the main process to update the displayed robot
* connection latency.
*/
export type RendererLatencyUpdateData = number;

/**
* Data for the renderer-devices-update event sent by the main process to update the state of
* connected lowcar devices.
*/
export type RendererDevicesUpdateData = DeviceInfoState[];

/**
* Data for a specialization of the main-file-control event, sent by the renderer to
* initiate/respond to a request to save the code.
Expand All @@ -214,6 +231,7 @@ export interface MainFileControlSaveData {
*/
content: string;
}

/**
* Data for a specialization of the main-file-control event, sent by the renderer to
* initiate/authorize a request to load code into the editor.
Expand All @@ -224,6 +242,7 @@ export interface MainFileControlLoadData {
*/
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.
Expand All @@ -238,6 +257,7 @@ export interface MainFileControlUploadData {
*/
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.
Expand All @@ -252,6 +272,7 @@ export interface MainFileControlDownloadData {
*/
robotSSHAddress: string;
}

/**
* Data for a specialization of the main-file-control event, sent by the renderer to
* inititate/respond to a request to clear the save path (so the next request to save must prompt
Expand All @@ -263,6 +284,7 @@ export interface MainFileControlClearSavePathData {
*/
type: 'clearSavePath';
}

/**
* Data for the main-file-control event sent by the renderer process to submit information related
* to the code file and editor.
Expand All @@ -273,34 +295,44 @@ export type MainFileControlData =
| MainFileControlUploadData
| MainFileControlDownloadData
| MainFileControlClearSavePathData;

/**
* 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.
*/
export interface MainQuitData {
/**
* The IP address used to communicate with the robot's runtime, to be saved to persistent config.
*/
robotIPAddress: string;
/**
* The IP address of the field controller, to be saved to persistent config.
*/
fieldIPAddress: string;
/**
* The field station number to connect to, to be saved to persistent config.
*/
fieldStationNumber: string;
/**
* Whether the user should be warned when uploading code with unsaved changes in the editor (since
* these won't be uploaded), to be saved to persistent config.
*/
showDirtyUploadWarning: boolean;
}

/**
* Data for the main-update-robot-mode event sent by the renderer to stop the robot or start it with
* a specified opmode.
*/
export type MainUpdateRobotModeData = RobotRunMode;

/**
* Data for the main-connection-config event sent by the renderer to notify the main process of a
* change in the Runtime or field connection config.
*/
export interface MainConnectionConfigData {
/**
* The IP address used to communicate with the robot's runtime.
*/
robotIPAddress: string;
/**
* The IP address of the field controller.
*/
fieldIPAddress: string;
/**
* The field station number to connect to.
*/
fieldStationNumber: string;
}

/**
* Data for the main-robot-input event sent by the renderer with gamepad or keyboard inputs bound
* for the robot.
Expand Down
Loading
Loading