Skip to content

Commit

Permalink
Refactor app data storage to use single key in local storage.
Browse files Browse the repository at this point in the history
  • Loading branch information
gbmhunter committed Jun 14, 2024
1 parent 5939e2b commit 370a440
Show file tree
Hide file tree
Showing 14 changed files with 934 additions and 122 deletions.
715 changes: 715 additions & 0 deletions local-storage-data/profiles-2ce70b.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions src/model/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class App {
if (this.portState === PortState.CLOSED_BUT_WILL_REOPEN) {
// Check to see if this is the serial port we want to reopen

const lastUsedPortInfo = this.profileManager.currentAppConfig.lastUsedSerialPort;
const lastUsedPortInfo = this.profileManager.appData.currentAppConfig.lastUsedSerialPort;
if (lastUsedPortInfo === null) {
return;
}
Expand All @@ -233,7 +233,7 @@ export class App {
let approvedPorts = await navigator.serial.getPorts();

// const lastUsedSerialPort = this.appStorage.data.lastUsedSerialPort;
const lastUsedSerialPort = this.profileManager.currentAppConfig.lastUsedSerialPort;
const lastUsedSerialPort = this.profileManager.appData.currentAppConfig.lastUsedSerialPort;
if (lastUsedSerialPort === null) {
// Did not find last used serial port data in local storage, so do nothing
return;
Expand Down Expand Up @@ -303,9 +303,9 @@ export class App {
this.serialPortInfo = this.port.getInfo();
// Save the info for this port, so we can automatically re-open
// it on app re-open in the future
let lastUsedSerialPort = this.profileManager.currentAppConfig.lastUsedSerialPort;
let lastUsedSerialPort = this.profileManager.appData.currentAppConfig.lastUsedSerialPort;
lastUsedSerialPort.serialPortInfo = JSON.parse(JSON.stringify(this.serialPortInfo));
this.profileManager.saveAppConfig();
this.profileManager.saveAppData();
});
if (this.settings.portConfiguration.connectToSerialPortAsSoonAsItIsSelected) {
await this.openPort();
Expand Down Expand Up @@ -404,9 +404,9 @@ export class App {
this.closedPromise = this.readUntilClosed();
});

const lastUsedSerialPort = this.profileManager.currentAppConfig.lastUsedSerialPort;
const lastUsedSerialPort = this.profileManager.appData.currentAppConfig.lastUsedSerialPort;
lastUsedSerialPort.portState = PortState.OPENED;
this.profileManager.saveAppConfig();
this.profileManager.saveAppData();

// Create custom GA4 event to see how many ports have
// been opened in NinjaTerm :-)
Expand Down Expand Up @@ -553,9 +553,9 @@ export class App {
}
this.reader = null;
this.closedPromise = null;
const lastUsedSerialPort = this.profileManager.currentAppConfig.lastUsedSerialPort;
const lastUsedSerialPort = this.profileManager.appData.currentAppConfig.lastUsedSerialPort;
lastUsedSerialPort.portState = PortState.CLOSED;
this.profileManager.saveAppConfig();
this.profileManager.saveAppData();
} else if (this.lastSelectedPortType === PortType.FAKE) {
this.fakePortController.closePort();
} else {
Expand All @@ -575,7 +575,7 @@ export class App {
* - Pressing "f" while on the Port Configuration settings.
*/
async handleKeyDown(event: React.KeyboardEvent) {
console.log('handleKeyDown() called. event.key=', event.key);
// console.log('handleKeyDown() called. event.key=', event.key);
// SPECIAL TESTING "FAKE PORTS"
if (this.shownMainPane === MainPanes.SETTINGS && this.settings.activeSettingsCategory === SettingsCategories.PORT_CONFIGURATION && event.key === 'f') {
this.fakePortController.setIsDialogOpen(true);
Expand Down
8 changes: 4 additions & 4 deletions src/model/ProfileManager/ProfileManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ describe("profile manager tests", () => {
test("default profile should be created", () => {
const app = new App();
const profileManager = new ProfileManager(app);
expect(profileManager.profiles.length).toEqual(1);
expect(profileManager.profiles[0].name).toEqual("Default profile");
expect(profileManager.appData.profiles.length).toEqual(1);
expect(profileManager.appData.profiles[0].name).toEqual("Default profile");
});

test("new profile can be created", () => {
const app = new App();
const profileManager = new ProfileManager(app);
profileManager.newProfile();
expect(profileManager.profiles.length).toEqual(2);
expect(profileManager.profiles[1].name).toEqual("New profile 1");
expect(profileManager.appData.profiles.length).toEqual(2);
expect(profileManager.appData.profiles[1].name).toEqual("New profile 1");
});
});
Loading

0 comments on commit 370a440

Please sign in to comment.