Skip to content

Commit ee1fe0c

Browse files
committed
feat: show launcher initialization time only after webview visibility change
1 parent 80df329 commit ee1fe0c

File tree

6 files changed

+65
-34
lines changed

6 files changed

+65
-34
lines changed

src/components/general/extensions/ExtensionLoader.vue

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script setup lang="ts">
2-
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
32
import { inject, onMounted, ref } from "vue";
43
54
import PermissionsHandler from "@/components/general/extensions/PermissionsHandler.vue";
@@ -87,13 +86,9 @@ onMounted(async () => {
8786
if (!hasSandboxedPlugins) {
8887
log.debug("User does not have sandboxed plugins. Environment lockdown is not needed");
8988
90-
if (globalStates?.misc?.showAfterExtensionsInitialization) {
91-
log.debug(
92-
"User has enabled 'show-after-extensions-initialization';",
93-
"Showing the webview now",
94-
);
95-
await getCurrentWebviewWindow().show();
96-
}
89+
await ExtensionsManager.showWebviewWindow(
90+
globalStates?.misc?.showAfterExtensionsInitialization,
91+
);
9792
9893
return;
9994
}
@@ -111,13 +106,9 @@ onMounted(async () => {
111106
});
112107
}
113108
114-
if (globalStates?.misc?.showAfterExtensionsInitialization) {
115-
log.debug(
116-
"User has enabled 'show-after-extensions-initialization';",
117-
"Showing the webview now",
118-
);
119-
await getCurrentWebviewWindow().show();
120-
}
109+
await ExtensionsManager.showWebviewWindow(
110+
globalStates?.misc?.showAfterExtensionsInitialization,
111+
);
121112
});
122113
123114
/*

src/declarations.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ declare global {
105105
"initialBaseDirectory": string;
106106
// A temporary storage for the 'At a Glance' widget
107107
"atAGlance" ?: AtAGlanceType;
108+
// A timestamp for the application's JavaScript code initialization
109+
"startTime" ?: number;
108110
};
109111

110112
/**

src/lib/extensions-manager/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { readAllExtensions } from "@/lib/extensions-manager/scopes/read-all-exte
99
import { readAllMetadata } from "@/lib/extensions-manager/scopes/read-all-metadata.ts";
1010
import { runInSandbox } from "@/lib/extensions-manager/scopes/run-in-sandbox.ts";
1111
import { runInUnrestricted } from "@/lib/extensions-manager/scopes/run-in-unrestricted.ts";
12+
import { showWebviewWindow } from "@/lib/extensions-manager/scopes/show-webview-window.ts";
1213
import type { PermissionType } from "@/types/extensions/permission.type.ts";
1314

1415
export default {
@@ -27,4 +28,5 @@ export default {
2728
readAllMetadata,
2829
runInSandbox,
2930
runInUnrestricted,
31+
showWebviewWindow,
3032
} as const;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
2+
3+
import { ApplicationNamespace } from "@/constants/application.ts";
4+
import { log } from "@/lib/logging/scopes/log.ts";
5+
6+
export async function showWebviewWindow(show: boolean | undefined): Promise<void> {
7+
if (show) {
8+
const startTime: number | undefined = window[ApplicationNamespace].__internals?.startTime;
9+
10+
log.debug(
11+
"User has enabled 'show-after-extensions-initialization';",
12+
"Showing the webview now",
13+
);
14+
await getCurrentWebviewWindow().show();
15+
16+
const timeDifference: string = startTime === undefined
17+
? "-1"
18+
: (performance.now() - startTime).toFixed(1);
19+
20+
log.info(
21+
"Launcher successfully initialized in:",
22+
timeDifference,
23+
"ms",
24+
);
25+
}
26+
}

src/lib/general/scopes/initialize-launcher.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
22
import { exists, mkdir } from "@tauri-apps/plugin-fs";
33

4+
import { ApplicationNamespace } from "@/constants/application.ts";
45
import { FileStructure } from "@/constants/file-structure.ts";
56
import General from "@/lib/general";
67
import { log } from "@/lib/logging/scopes/log.ts";
@@ -19,20 +20,28 @@ export async function initializeLauncher({
1920
config.extensions.enabled &&
2021
config.misc.showAfterExtensionsInitialization;
2122

22-
if (!afterExtensions) {
23+
if (afterExtensions) {
24+
/*
25+
* Making the webview window visible determines that the launcher successfully started.
26+
*
27+
* Clearly, the 'startTime' variable is not accessible by the deeply nested
28+
* 'ExtensionLoader.vue' component without exposing that variable through the 'window' object.
29+
*/
30+
window[ApplicationNamespace].__internals.startTime = startTime;
31+
} else {
2332
/*
2433
* Webview window is still hidden, so make it visible now
25-
* Because frontend is already loaded by this time
34+
* because frontend is already loaded by this time
2635
*/
2736
log.debug("Making current webview window visible");
2837
await getCurrentWebviewWindow().show();
29-
}
3038

31-
log.info(
32-
"Launcher successfully started in:",
33-
(performance.now() - startTime).toFixed(1),
34-
"ms",
35-
);
39+
log.info(
40+
"Launcher successfully initialized in:",
41+
(performance.now() - startTime).toFixed(1),
42+
"ms",
43+
);
44+
}
3645

3746
log.debug("Checking if all directories present");
3847
const directoriesStartTime = performance.now();

src/main.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,19 @@ if (config.development?.enableDebugMode) {
7676
DevelopmentModeHelpers.enableDebugMode(
7777
DevelopmentModeHelpers.getDefault(),
7878
);
79-
}
8079

81-
// Log user's launcher configuration
82-
log.debug(
83-
"Config contents:",
84-
"\n" + JSON.stringify(config, null, 2),
85-
);
86-
// Log user's instances metadata
87-
log.debug(
88-
"Instances metadata contents:",
89-
"\n" + JSON.stringify(instances, null, 2),
90-
);
80+
// Log user's launcher configuration
81+
log.debug(
82+
"Config contents:",
83+
// 'JSON#stringify' is not so fast
84+
"\n" + JSON.stringify(config, null, 2),
85+
);
86+
// Log user's instances metadata
87+
log.debug(
88+
"Instances metadata contents:",
89+
"\n" + JSON.stringify(instances, null, 2),
90+
);
91+
}
9192

9293
log.debug("Creating a Vue instance");
9394
// 'App' is the 'App.vue' entry

0 commit comments

Comments
 (0)