Skip to content

Commit cfc88bc

Browse files
committed
refactor: re-write everything to a new file structure
1 parent 9dc46d1 commit cfc88bc

File tree

18 files changed

+80
-152
lines changed

18 files changed

+80
-152
lines changed

src/components/general/extensions/ExtensionLoader.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ const knownExtensions = ref<Array<ExtensionMetadataType>>([]);
1818
const unknownExtensions = ref<Array<ExtensionInfoType>>([]);
1919
2020
onMounted(async () => {
21-
log.debug("Initializing extensions loader");
22-
await ExtensionsManager.initializeDirectory();
23-
2421
log.debug("Getting all stored extensions");
2522
const extensions: Array<ExtensionInfoType> = await ExtensionsManager.readAllExtensions();
2623

src/components/general/misc/ConfigSyncer.vue

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ import { useIntervalFn } from "@vueuse/core";
44
import { inject, ref, watchEffect } from "vue";
55
66
import { ApplicationNamespace, GlobalStatesContextKey } from "@/constants/application.ts";
7+
import { FileStructure } from "@/constants/file-structure.ts";
78
import Configs from "@/lib/configs";
89
import Errors from "@/lib/errors";
10+
import General from "@/lib/general";
911
import GlobalStateHelpers from "@/lib/global-state-helpers";
1012
import { log } from "@/lib/logging/scopes/log.ts";
11-
import type { ContextGlobalStatesType } from "@/types/application/global-states.type.ts";
13+
import type {
14+
ContextGlobalStatesType,
15+
GlobalStatesType,
16+
} from "@/types/application/global-states.type.ts";
1217
import type { ConfigType } from "@/types/configs/config.type.ts";
1318
1419
const globalStates = inject<ContextGlobalStatesType>(GlobalStatesContextKey);
@@ -21,31 +26,38 @@ async function handleConfigSync(): Promise<void> {
2126
syncing.value = true;
2227
2328
log.debug("Getting current global states");
24-
const currentGlobalStates = GlobalStateHelpers.get();
25-
const configPath = currentGlobalStates.fileSystem?.files?.config;
26-
27-
if (!configPath) {
28-
log.warn("No config path was found in global states. Aborting config sync");
29-
syncing.value = false;
30-
31-
return;
32-
}
29+
const currentGlobalStatesDetached: ConfigType & Partial<GlobalStatesType> = {
30+
// Spread the global states to re-create one-level deep properties
31+
...GlobalStateHelpers.get(),
32+
};
33+
const configPath = General.cachedJoin(
34+
General.getCachedBaseDirectory(),
35+
FileStructure.Files.Config,
36+
);
3337
3438
log.debug("Getting current user config");
3539
const config = await Configs.getSafe();
3640
41+
// Remove all non-config properties
42+
delete currentGlobalStatesDetached.translations;
43+
delete currentGlobalStatesDetached.sidebarItems;
44+
delete currentGlobalStatesDetached.contextMenuItems;
45+
delete currentGlobalStatesDetached.pages;
46+
3747
log.debug("Creating a 'ConfigType' typed object with the global states contents");
3848
const configOnlyGlobalStates: ConfigType = {
49+
// Spread the global states since there might be additional properties by extensions
50+
...globalStates,
3951
// Arrange these properties in a way that the config itself arranges them
40-
"development": currentGlobalStates.development,
41-
"extensions" : currentGlobalStates.extensions,
42-
"layout" : currentGlobalStates.layout,
52+
"development": currentGlobalStatesDetached.development,
53+
"extensions" : currentGlobalStatesDetached.extensions,
54+
"layout" : currentGlobalStatesDetached.layout,
4355
"logs" : {
44-
...currentGlobalStates.logs,
56+
...currentGlobalStatesDetached.logs,
4557
"show": false,
4658
},
47-
"minecraft": currentGlobalStates.minecraft,
48-
"misc" : currentGlobalStates.misc,
59+
"minecraft": currentGlobalStatesDetached.minecraft,
60+
"misc" : currentGlobalStatesDetached.misc,
4961
};
5062
const stringyConfig = JSON.stringify(config);
5163
const stringyGlobalStates = JSON.stringify(configOnlyGlobalStates);

src/components/logging/LogViewer.vue

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import LogControls from "@/components/logging/controls/LogControls.vue";
99
import LogEntry from "@/components/logging/lines/LogEntry.vue";
1010
import NonVirtualizedLogs from "@/components/logging/NonVirtualizedLogs.vue";
1111
import { ApplicationNamespace, GlobalStatesContextKey } from "@/constants/application.ts";
12+
import { FileStructure } from "@/constants/file-structure.ts";
13+
import General from "@/lib/general";
1214
import GlobalStateHelpers from "@/lib/global-state-helpers";
1315
import { log } from "@/lib/logging/scopes/log.ts";
1416
import type { ContextGlobalStatesType } from "@/types/application/global-states.type.ts";
@@ -157,17 +159,14 @@ onMounted(async () => {
157159
mountedKey.value = Math.random();
158160
159161
log.debug("LogViewer.vue mounted");
160-
log.debug("Getting 'latest.log' file path");
161-
const latestLogPath: string | undefined = globalStates?.fileSystem?.files?.log;
162-
163-
if (!latestLogPath) {
164-
log.warn("'latest.log' file path is missing");
165-
166-
return;
167-
}
162+
const latestLogAbsolutePath = General.cachedJoin(
163+
General.getCachedBaseDirectory(),
164+
FileStructure.Folders.Logs.Path,
165+
FileStructure.Folders.Logs.Files.LatestLog,
166+
);
168167
169168
log.debug("Reading 'latest.log' file");
170-
const existingLogs: string = await readTextFile(latestLogPath);
169+
const existingLogs: string = await readTextFile(latestLogAbsolutePath);
171170
172171
if (existingLogs === "") {
173172
log.warn("Log file is empty");

src/components/logging/controls/LogControls.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { computed, ref, shallowRef, watchEffect } from "vue";
66
import CustomButton from "@/components/general/base/CustomButton.vue";
77
import LogFilterer from "@/components/logging/controls/LogFilterer.vue";
88
import LogSearcher from "@/components/logging/controls/LogSearcher.vue";
9+
import { FileStructure } from "@/constants/file-structure.ts";
10+
import General from "@/lib/general";
911
import GlobalStateHelpers from "@/lib/global-state-helpers";
1012
import Logging from "@/lib/logging";
1113
import type { LogButtonType } from "@/types/logging/log-button.type.ts";
@@ -72,11 +74,11 @@ async function copyTextSelection(): Promise<void> {
7274
);
7375
}
7476
async function viewInExplorer(): Promise<void> {
75-
const latestLogAbsolutePath = GlobalStateHelpers.get().fileSystem?.files?.log;
76-
77-
if (!latestLogAbsolutePath) {
78-
return;
79-
}
77+
const latestLogAbsolutePath = General.cachedJoin(
78+
General.getCachedBaseDirectory(),
79+
FileStructure.Folders.Logs.Path,
80+
FileStructure.Folders.Logs.Files.LatestLog,
81+
);
8082
8183
await revealItemInDir(latestLogAbsolutePath);
8284
}

src/constants/application.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { BaseDirectory } from "@tauri-apps/plugin-fs";
22
import { revealItemInDir } from "@tauri-apps/plugin-opener";
33

4+
import { FileStructure } from "@/constants/file-structure.ts";
45
import Errors from "@/lib/errors";
6+
import General from "@/lib/general";
57
import GlobalStateHelpers from "@/lib/global-state-helpers";
68
import { log } from "@/lib/logging/scopes/log.ts";
79

@@ -33,7 +35,10 @@ export const ContextMenuItems = [
3335
"action": (): void => {
3436
window[ApplicationNamespace].libs.ContextMenu.close();
3537
revealItemInDir(
36-
GlobalStateHelpers.get().fileSystem?.files?.config ?? "",
38+
General.cachedJoin(
39+
General.getCachedBaseDirectory(),
40+
FileStructure.Files.Config,
41+
),
3742
).catch((error: unknown) => {
3843
log.error("Failed to reveal the config file in the explorer:", Errors.prettify(error));
3944
});

src/constants/hooks.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export const HookMappings = {
22
"translations" : "onTranslationsChange",
3-
"fileSystem" : "onFileSystemChange",
43
"layout" : "onLayoutChange",
54
"pages" : "onPagesChange",
65
"logs" : "onLogsChange",

src/declarations.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -329,41 +329,6 @@ declare global {
329329
"after": HookReturnType<TranslationsType, "nothing">;
330330
};
331331

332-
/**
333-
* Executed on the 'fileSystem' field replacement in global states
334-
*/
335-
"onFileSystemChange": {
336-
337-
/**
338-
* Executes 'sync'-only functions before the 'fileSystem' property
339-
* in the global states will change.
340-
*
341-
* 'GlobalStatesType["fileSystem"]' typed object is passed as the argument.
342-
*
343-
* If the hook returns a 'stop' status,
344-
* it should also return a 'GlobalStatesType["fileSystem"]' typed object
345-
* in the 'response' field.
346-
*
347-
* If the hook returns a 'continue' status,
348-
* code execution will continue as if that hook did not exist.
349-
*/
350-
"before": HookReturnType<
351-
GlobalStatesType["fileSystem"],
352-
GlobalStatesType["fileSystem"],
353-
"non-promise"
354-
>;
355-
356-
/**
357-
* Executes 'async' or 'sync' functions on the next Vue tick,
358-
* after the 'fileSystem' property in the global states has changed.
359-
*
360-
* 'GlobalStatesType["fileSystem"]' typed object is passed as the argument.
361-
*
362-
* Hook should not return anything since the response will not be read.
363-
*/
364-
"after": HookReturnType<GlobalStatesType["fileSystem"], "nothing">;
365-
};
366-
367332
/**
368333
* Executed on the 'layout' field replacement in global states
369334
*/

src/lib/configs/scopes/get-config-file.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function getConfigFile(passedBaseDirectory?: string): Promise<Confi
2323
baseDirectory = await General.getBaseDirectory(portable);
2424
}
2525

26-
const configFileDirectory = General.cachedJoin(baseDirectory, FileStructure.Config.Name);
26+
const configFileDirectory = General.cachedJoin(baseDirectory, FileStructure.Files.Config);
2727

2828
log.debug(log.templates.hooks.iterate.start(
2929
"getConfigFile",
@@ -61,7 +61,7 @@ export async function getConfigFile(passedBaseDirectory?: string): Promise<Confi
6161
const configExists = await exists(configFileDirectory);
6262

6363
if (!configExists) {
64-
log.info("Config file does not exist");
64+
log.warn("Config file does not exist");
6565
log.debug("Initializing a config file");
6666
await initializeConfigFile(configFileDirectory);
6767

src/lib/extensions-manager/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
} from "@/lib/extensions-manager/scopes/grant-static-permissions.ts";
55
import { handleCssTheme } from "@/lib/extensions-manager/scopes/handle-css-theme.ts";
66
import { handlePermission } from "@/lib/extensions-manager/scopes/handle-permission.ts";
7-
import { initializeDirectory } from "@/lib/extensions-manager/scopes/initialize-directory.ts";
87
import { lockdownEnvironment } from "@/lib/extensions-manager/scopes/lockdown-environment.ts";
98
import { readAllExtensions } from "@/lib/extensions-manager/scopes/read-all-extensions.ts";
109
import { readAllMetadata } from "@/lib/extensions-manager/scopes/read-all-metadata.ts";
@@ -23,7 +22,6 @@ export default {
2322
grantStaticPermissions,
2423
handleCssTheme,
2524
handlePermission,
26-
initializeDirectory,
2725
lockdownEnvironment,
2826
readAllExtensions,
2927
readAllMetadata,

src/lib/extensions-manager/scopes/initialize-directory.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)