Skip to content

Commit 385e3e0

Browse files
committed
feat: save code
1 parent 31baba4 commit 385e3e0

File tree

6 files changed

+90
-27
lines changed

6 files changed

+90
-27
lines changed

src/App.vue

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script setup lang="ts">
2+
import { useEventListener } from "@vueuse/core";
23
import { defineAsyncComponent, onBeforeMount, provide, shallowReactive } from "vue";
34
45
import ErrorBoundary from "@/components/general/errors/ErrorBoundary.vue";
@@ -11,6 +12,7 @@ import {
1112
ApplicationNamespace,
1213
GlobalStatesContextKey,
1314
} from "@/constants/application.ts";
15+
import { DevelopmentModeHelpers } from "@/lib/development-mode-helpers";
1416
import GlobalStateHelpers from "@/lib/global-state-helpers";
1517
import { __changeGlobalState } from "@/lib/global-state-helpers/scopes/change-global-state.ts";
1618
import { log } from "@/lib/logging/scopes/log.ts";
@@ -102,6 +104,16 @@ onBeforeMount(async () => {
102104
globalStates[key as "locale"] = value as GlobalStatesType["locale"];
103105
}
104106
});
107+
108+
/**
109+
* Handles 'F5', 'Ctrl+R', and 'Command+R' key binds that reload the launcher
110+
*/
111+
useEventListener("keydown", (event: KeyboardEvent) => (
112+
DevelopmentModeHelpers.handleNativeReloadKeyBinds(
113+
event,
114+
globalStates.development.enableNativeReloadKeyBinds,
115+
)
116+
));
105117
</script>
106118

107119
<template>
@@ -118,7 +130,7 @@ onBeforeMount(async () => {
118130
<LogViewer v-if="globalStates.logs.show" />
119131
</Transition>
120132

121-
<DevelopmentMode v-if="globalStates.development.enabled" />
133+
<DevelopmentMode v-if="true || globalStates.development.enabled" />
122134
<NonBundledClasses />
123135
</Layout>
124136
</template>

src/components/general/development-mode/DevelopmentMode.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
import { inject, onUnmounted, watchEffect } from "vue";
33
4+
import FramesPerSecond from "@/components/general/development-mode/FramesPerSecondCounter.vue";
45
import { GlobalStatesContextKey } from "@/constants/application.ts";
56
import { DevelopmentModeHelpers } from "@/lib/development-mode-helpers";
67
import type { ContextGlobalStatesType } from "@/types/application/global-states.type.ts";
@@ -23,6 +24,5 @@ onUnmounted(() => {
2324
</script>
2425

2526
<template>
26-
<NativeReloadKeyBinds v-if="globalStates?.development?.enableNativeReloadKeyBinds" />
27-
<FpsCounter v-if="globalStates?.development?.showFPS" />
27+
<FramesPerSecond v-if="true || globalStates?.development?.showFPS" />
2828
</template>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<script setup lang="ts">
2+
import { onMounted, onUnmounted, ref } from "vue";
3+
4+
const aborted = ref<boolean>(false);
5+
const fps = ref<number>(0);
6+
7+
onMounted(() => {
8+
const times: Array<number> = [];
9+
10+
function countFrame(): void {
11+
if (aborted.value) {
12+
return;
13+
}
14+
15+
requestAnimationFrame(() => {
16+
const now = performance.now();
17+
18+
while (times.length > 0 && times[0] <= now - 1000) {
19+
times.shift();
20+
}
21+
22+
times.push(now);
23+
24+
fps.value = times.length;
25+
26+
countFrame();
27+
});
28+
}
29+
30+
countFrame();
31+
});
32+
onUnmounted(() => {
33+
aborted.value = true;
34+
});
35+
</script>
36+
37+
<template>
38+
<div id="__dev-fps-counter__wrapper" class="fixed right-4 top-4 z-65000 bg-[theme(colors.black/.5)]">
39+
{{ fps }}
40+
</div>
41+
</template>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { disableDebugMode } from "@/lib/development-mode-helpers/scopes/disable-debug-mode.ts";
22
import { enableDebugMode } from "@/lib/development-mode-helpers/scopes/enable-debug-mode.ts";
3+
import {
4+
handleNativeReloadKeyBinds,
5+
} from "@/lib/development-mode-helpers/scopes/handle-native-reload-key-binds.ts";
36

47
export const DevelopmentModeHelpers = {
58
disableDebugMode,
69
enableDebugMode,
10+
handleNativeReloadKeyBinds,
711
} as const;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { log } from "@/lib/logging/scopes/log.ts";
2+
3+
export function handleNativeReloadKeyBinds(event: KeyboardEvent, ignore: boolean): void {
4+
// If user has enabled native reload key binds, then do not prevent them from firing
5+
if (ignore) {
6+
return;
7+
}
8+
9+
if (
10+
event.key === "F5" ||
11+
(event.ctrlKey && event.key === "r") ||
12+
(event.metaKey && event.key === "r")
13+
) {
14+
log.debug("Prevented native behaviour when triggering reload key binds");
15+
event.preventDefault();
16+
}
17+
}

src/main.ts

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Import UnoCSS essentials
22
import "virtual:uno.css";
3-
// Reset all CSS styles in a Tailwind style
3+
// Reset all CSS styles in a Tailwind-like way
44
import "@unocss/reset/tailwind.css";
55
// Import custom CSS styles
66
import "@/globals.css";
@@ -22,37 +22,35 @@ import Logging from "@/lib/logging";
2222
import { log } from "@/lib/logging/scopes/log.ts";
2323
import type { ConfigType } from "@/types/application/config.type.ts";
2424

25-
// Get the exact timestamp in milliseconds before initialization
26-
const startTime = performance.now();
27-
28-
// Share the 'portable' status between other functions
25+
// Check if launcher is in a portable version
2926
const portable: boolean = await General.checkIsPortable();
30-
// Get launcher base directory
27+
// Get the launcher base directory
3128
const baseDirectory: string = await General.getBaseDirectory(portable);
3229

33-
// No need to log yet, all logs will go into the previous launch log file
30+
// No need to log yet since all logs will go into the previous launch log file
3431
await Logging.prepareLogFile(baseDirectory).catch((error: unknown) => {
3532
log.error("Failed to prepare a log file:", Errors.prettify(error));
3633
});
3734

38-
log.debug("Extending global window object in the app namespace");
35+
/*
36+
* Now the log file preparation is done (unless something threw an error).
37+
*
38+
* Previous code doesn't access the 'window' object, but config reading does
39+
*/
40+
log.debug("Extending global window object with the app namespace");
3941
Globals.declareWindow();
4042

4143
// Get user's launcher configuration
4244
const config: ConfigType = await Configs.getSafe(baseDirectory);
4345

46+
// Show a pretty ASCII art with the launcher name :3
47+
log.info(getASCIIArt(portable, config.development.enableDebugMode));
48+
4449
// Enabling debug mode means that debug-level messages will be logged
4550
if (config.development.enableDebugMode) {
4651
DevelopmentModeHelpers.enableDebugMode();
4752
}
4853

49-
/*
50-
* Now the log file preparation is done (unless something threw an error).
51-
*
52-
* Show a pretty ASCII art with the launcher name :3
53-
*/
54-
log.info(getASCIIArt(portable, config.development.enableDebugMode));
55-
5654
if (config.showBeforeInitialization) {
5755
try {
5856
log.debug("Showing webview window before initialization according to user's config");
@@ -79,12 +77,3 @@ log.debug("Initializing launcher");
7977
await General.initializeLauncher(config).catch((error: unknown) => {
8078
log.error("Failed to initialize launcher:", Errors.prettify(error));
8179
});
82-
83-
// Get the exact timestamp in milliseconds after initialization
84-
const endTime = performance.now();
85-
86-
log.info(
87-
"Launcher was initialized in",
88-
(endTime - startTime).toFixed(2),
89-
"ms",
90-
);

0 commit comments

Comments
 (0)