cleanup path management

This commit is contained in:
marlon-erler
2024-07-25 16:44:08 +02:00
parent 1dc2da2514
commit c9d74972b8
10 changed files with 57 additions and 67 deletions
+9 -9
View File
@@ -2,7 +2,7 @@
import { ChatMessage, ChatMessageReference } from "../Chat/chatModel";
import { Handler, HandlerManager, stringify } from "../Utility/utility";
import StorageModel, { filePaths } from "./storageModel";
import StorageModel, { StorageModelSubPath, filePaths } from "./storageModel";
import UDNFrontend, { Message } from "udn-frontend";
export default class ConnectionModel {
@@ -34,7 +34,7 @@ export default class ConnectionModel {
this.connectionChangeHandlerManager.trigger();
if (this.isConnected == false) return;
if (!this.address) return;
if (this.address == undefined) return;
this.connectMailbox();
this.storeAddress(this.address);
@@ -52,7 +52,7 @@ export default class ConnectionModel {
// do not reconnect
const reconnectAddressPath: string[] = StorageModel.getPath(
"connectionModel",
StorageModelSubPath.ConnectionModel,
filePaths.connectionModel.reconnectAddress
);
this.storageModel.remove(reconnectAddressPath);
@@ -61,7 +61,7 @@ export default class ConnectionModel {
// mailbox
getMailboxPath = (address: string): string[] => {
const mailboxDirPath = StorageModel.getPath(
"connectionModel",
StorageModelSubPath.ConnectionModel,
filePaths.connectionModel.mailboxes
);
const mailboxFilePath = [...mailboxDirPath, address];
@@ -69,7 +69,7 @@ export default class ConnectionModel {
};
requestNewMailbox = (): void => {
console.log("requesting mailbox");
console.log("requesting new mailbox");
this.udn.requestMailbox();
};
@@ -107,7 +107,7 @@ export default class ConnectionModel {
// outbox
getOutboxPath = (): string[] => {
return StorageModel.getPath(
"connectionModel",
StorageModelSubPath.ConnectionModel,
filePaths.connectionModel.outbox
);
};
@@ -173,7 +173,7 @@ export default class ConnectionModel {
// storage
getPreviousAddressPath = (): string[] => {
return StorageModel.getPath(
"connectionModel",
StorageModelSubPath.ConnectionModel,
filePaths.connectionModel.previousAddresses
);
};
@@ -185,7 +185,7 @@ export default class ConnectionModel {
getReconnectAddressPath = (): string[] => {
return StorageModel.getPath(
"connectionModel",
StorageModelSubPath.ConnectionModel,
filePaths.connectionModel.reconnectAddress
);
};
@@ -209,7 +209,7 @@ export default class ConnectionModel {
const dirPath = this.getPreviousAddressPath();
return this.storageModel.list(dirPath);
}
// init
constructor(storageModel: StorageModel) {
// create frontend
+5 -5
View File
@@ -1,6 +1,6 @@
// this file is responsible for all settings.
import StorageModel, { filePaths } from "./storageModel";
import StorageModel, { StorageModelSubPath, filePaths } from "./storageModel";
export default class SettingsModel {
storageModel: StorageModel;
@@ -13,7 +13,7 @@ export default class SettingsModel {
setName(newValue: string): void {
this.username = newValue;
const path = StorageModel.getPath(
"settingsModel",
StorageModelSubPath.SettingsModel,
filePaths.settingsModel.username
);
this.storageModel.write(path, newValue);
@@ -22,7 +22,7 @@ export default class SettingsModel {
setFirstDayOfWeek(newValue: string): void {
this.firstDayOfWeek = newValue;
const path = StorageModel.getPath(
"settingsModel",
StorageModelSubPath.SettingsModel,
filePaths.settingsModel.firstDayOfWeek
);
this.storageModel.write(path, newValue);
@@ -31,7 +31,7 @@ export default class SettingsModel {
// load
loadUsernam(): void {
const path = StorageModel.getPath(
"settingsModel",
StorageModelSubPath.SettingsModel,
filePaths.settingsModel.username
);
const content = this.storageModel.read(path);
@@ -40,7 +40,7 @@ export default class SettingsModel {
loadFirstDayofWeek(): void {
const path = StorageModel.getPath(
"settingsModel",
StorageModelSubPath.SettingsModel,
filePaths.settingsModel.firstDayOfWeek
);
const content = this.storageModel.read(path);
+9 -14
View File
@@ -1,9 +1,6 @@
// this file is responsible for reading and writing persistent data.
import {
DATA_VERSION,
ValidObject,
} from "../Utility/typeSafety";
import { DATA_VERSION, ValidObject } from "../Utility/typeSafety";
import { localeCompare, parseValidObject, stringify } from "../Utility/utility";
export const PATH_COMPONENT_SEPARATOR = "\\";
@@ -84,7 +81,6 @@ export default class StorageModel {
const content: string | null = this.read(sourcePathComponents);
if (content == null) return false;
this.write(destinationPathComponents, content);
this.remove(sourcePathComponents);
@@ -212,10 +208,10 @@ export default class StorageModel {
};
static getPath(
locationName: keyof typeof storageLocations,
locationName: StorageModelSubPath,
filePath: string[]
): string[] {
return [DATA_VERSION, storageLocations[locationName], ...filePath];
return [DATA_VERSION, locationName, ...filePath];
}
}
@@ -223,13 +219,12 @@ export default class StorageModel {
export type StorageEntry = { [key: string]: StorageEntry };
// locations
const storageLocations = {
connectionModel: "connection",
chat: "chat",
settingsModel: "settings",
};
export enum StorageModelSubPath {
Chat = "chat",
ConnectionModel = "connection",
SettingsModel = "settings",
}
export const filePaths = {
connectionModel: {