Skip to content

Commit 31baba4

Browse files
committed
refactor!: re-implement initialization code
1 parent 634ef46 commit 31baba4

File tree

24 files changed

+209
-60
lines changed

24 files changed

+209
-60
lines changed

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@
292292

293293
<div align="center">
294294

295-
<img width="128" height="128" align="center" src="../src-tauri/icons/128x128.png" alt="Favicon">
295+
<img width="128" height="128" align="center" src="../src-tauri/icons/128x128.png" alt="Tendou Arisu's halo recreation (Blue Archive)">
296296

297297
<h1>
298298
<a style="color:#a1fee4" href="https://github.com/kaede-basement/kaede">Kaede</a>

src/App.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ const LogViewer = defineAsyncComponent(
2828
const ExtensionLoader = defineAsyncComponent(
2929
() => import("@/components/general/extensions/ExtensionLoader.vue"),
3030
);
31+
const DevelopmentMode = defineAsyncComponent(
32+
() => import("@/components/general/development-mode/DevelopmentMode.vue"),
33+
);
3134
3235
/**
3336
* Contains all global application states.
@@ -115,6 +118,7 @@ onBeforeMount(async () => {
115118
<LogViewer v-if="globalStates.logs.show" />
116119
</Transition>
117120

121+
<DevelopmentMode v-if="globalStates.development.enabled" />
118122
<NonBundledClasses />
119123
</Layout>
120124
</template>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<script setup lang="ts">
2+
import { inject, onUnmounted, watchEffect } from "vue";
3+
4+
import { GlobalStatesContextKey } from "@/constants/application.ts";
5+
import { DevelopmentModeHelpers } from "@/lib/development-mode-helpers";
6+
import type { ContextGlobalStatesType } from "@/types/application/global-states.type.ts";
7+
8+
const globalStates = inject<ContextGlobalStatesType>(GlobalStatesContextKey);
9+
10+
watchEffect(() => {
11+
if (globalStates?.development?.enableDebugMode) {
12+
DevelopmentModeHelpers.enableDebugMode();
13+
14+
return;
15+
}
16+
17+
DevelopmentModeHelpers.disableDebugMode();
18+
});
19+
20+
onUnmounted(() => {
21+
DevelopmentModeHelpers.disableDebugMode();
22+
});
23+
</script>
24+
25+
<template>
26+
<NativeReloadKeyBinds v-if="globalStates?.development?.enableNativeReloadKeyBinds" />
27+
<FpsCounter v-if="globalStates?.development?.showFPS" />
28+
</template>

src/components/home/Home.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import Image from "@/components/general/base/Image.vue";
33
import MaterialRipple from "@/components/general/base/MaterialRipple.vue";
44
import PageWrapper from "@/components/general/layout/PageWrapper.vue";
5+
import GlobalStateHelpers from "@/lib/global-state-helpers";
56
</script>
67

78
<template>
@@ -36,7 +37,7 @@ import PageWrapper from "@/components/general/layout/PageWrapper.vue";
3637
>
3738
<Image
3839
id="__"
39-
class-names="rounded-md size-12 transition-none p-1"
40+
class-names="rounded-md size-12 p-1"
4041
src="https://media.forgecdn.net/avatars/thumbnails/286/772/64/64/637305737753885398.png"
4142
alt="Fabulously optimized"
4243
/>
@@ -68,7 +69,11 @@ import PageWrapper from "@/components/general/layout/PageWrapper.vue";
6869
</button>
6970
</div>
7071
<div class="flex flex-nowrap gap-1 p-2">
71-
<button class="relative w-fit rounded-l-md rounded-r-sm bg-white px-4 py-2 text-black">
72+
<button @click="() => GlobalStateHelpers.change('development', {
73+
...GlobalStateHelpers.get().development,
74+
'enabled' : true,
75+
'enableDebugMode': !GlobalStateHelpers.get().development.enableDebugMode,
76+
})" class="relative w-fit rounded-l-md rounded-r-sm bg-white px-4 py-2 text-black">
7277
<span class="block">
7378
Launch
7479
</span>

src/constants/ascii-art.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ import { arch, platform, version } from "@tauri-apps/plugin-os";
22

33
import { ApplicationName } from "@/constants/application.ts";
44

5-
export function getASCIIArt(portable: boolean): string {
5+
export function getASCIIArt(portable: boolean, debug: boolean): string {
66
return (
77
"\n __ __ " +
88
" me@" + ApplicationName.toLowerCase() +
99
"\n / /______ ____ ____/ /__ " +
10-
" os " + platform() + " " + version() +
10+
" os " + platform() + " " + version() +
1111
"\n / //_/ __ `/ _ \\/ __ / _ \\" +
12-
" arch " + arch() +
12+
" arch " + arch() +
1313
"\n / ,< / /_/ / __/ /_/ / __/" +
14-
" mode " + (portable ? "portable" : "non-portable") +
14+
" mode " + (portable ? "portable" : "non-portable") +
1515
"\n/_/|_|\\__,_/\\___/\\__,_/\\___/ " +
16-
" online " + (
17-
(navigator?.onLine ?? "unknown") ? "yes" : "no"
16+
" debug " + (
17+
debug ? "yes" : "no"
1818
) +
1919
"\n "
2020
);
21-
}
21+
}

src/constants/hooks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ export const HookMappings = {
66
"logs" : "onLogsChange",
77
"sidebarItems" : "onSidebarItemsChange",
88
"contextMenuItems": "onContextMenuItemsChange",
9+
"development" : "onDevelopmentChange",
910
} as const;
1011
export const HookMappingKeys = Object.keys(HookMappings) as Array<keyof typeof HookMappings>;
1112

1213
export const HookResponseStatus = {
1314
"Stop" : "stop",
1415
"Continue": "continue",
15-
} as const;
16+
} as const;

src/declarations.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,18 @@ declare global {
175175
>;
176176
"after": HookReturnType<GlobalStatesType["contextMenuItems"], "nothing">;
177177
};
178+
"onDevelopmentChange": {
179+
"before": HookReturnType<
180+
GlobalStatesType["development"],
181+
GlobalStatesType["development"],
182+
"non-promise"
183+
>;
184+
"after": HookReturnType<GlobalStatesType["development"], "nothing">;
185+
};
178186
};
179187
};
180188
}
181189
}
182190

183191
/* Export the Kaede namespace type */
184-
export type KaedeNamespaceType = Window["__KAEDE__"];
192+
export type KaedeNamespaceType = Window["__KAEDE__"];

src/lib/configs/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { getConfigFile } from "@/lib/configs/scopes/get-config-file.ts";
22
import { getDefaultConfig } from "@/lib/configs/scopes/get-default-config.ts";
3+
import { getSafeConfigFile } from "@/lib/configs/scopes/get-safe-config-file.ts";
34
import { initializeConfigFile } from "@/lib/configs/scopes/initialize-config-file.ts";
45

56
export default {
67
"get" : getConfigFile,
78
"getDefault": getDefaultConfig,
9+
"getSafe" : getSafeConfigFile,
810
"initialize": initializeConfigFile,
9-
} as const;
11+
} as const;

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@ import { log } from "@/lib/logging/scopes/log.ts";
1010
import Schemas from "@/lib/schemas";
1111
import type { ConfigType } from "@/types/application/config.type.ts";
1212

13-
export async function getConfigFile(portableStatus?: boolean): Promise<ConfigType> {
13+
export async function getConfigFile(passedBaseDirectory?: string): Promise<ConfigType> {
1414
const hooksArray = window[ApplicationNamespace].hooks.getConfigFile.before;
15+
let baseDirectory: string | undefined = passedBaseDirectory;
1516

16-
log.debug("Checking if launcher is in portable version");
17-
const portable = portableStatus ?? await General.checkIsPortable();
17+
if (!baseDirectory) {
18+
log.debug("No base directory was passed");
19+
log.debug("Checking if launcher is in portable version");
20+
const portable = await General.checkIsPortable();
21+
22+
log.debug("Getting base directory");
23+
baseDirectory = await General.getBaseDirectory(portable);
24+
}
1825

19-
log.debug("Getting base directory");
20-
const baseDirectory = await General.getBaseDirectory(portable);
2126
const configFileDirectory = await join(baseDirectory, FileStructure.Config.Name);
2227

2328
log.debug(log.templates.hooks.iterate.start(

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,9 @@ export async function getDefaultConfig(): Promise<ConfigType> {
3232
"locale" : "en",
3333
"minecraftWindowHeight": 480,
3434
"minecraftWindowWidth" : 854,
35+
"development" : {
36+
"enableDebugMode": true,
37+
},
38+
"showBeforeInitialization": false,
3539
};
3640
}

0 commit comments

Comments
 (0)