Skip to content

Commit 63f404e

Browse files
committed
feat: implement route reading from search params
1 parent 64c55e7 commit 63f404e

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

docs/README.ru.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
1+
<details>
2+
3+
```ts
4+
function handleNavigation(path: RouteType): void {
5+
const webviewId = path === "home" ? "main" : `navigation_window_${path}`;
6+
7+
new WebviewWindow(webviewId, {
8+
"url" : `/?route=${path}`,
9+
"visible": false,
10+
"title" : "Kaede - " + General.capitalize(path),
11+
});
12+
}
13+
14+
export async function temporaryShit(): Promise<void> {
15+
window.__KAEDE__.libs.GlobalStateHelpers.Pages.navigate = handleNavigation;
16+
17+
const currentWebviewWindow = getCurrentWebviewWindow();
18+
const currentId = currentWebviewWindow.label;
19+
20+
if (currentId !== "navigationWindow") {
21+
return;
22+
}
23+
24+
document.head.insertAdjacentHTML(
25+
"beforeend",
26+
"<style>" +
27+
"#__sidebar__wrapper {" +
28+
"display: none" +
29+
"}" +
30+
"#__page-wrapper {" +
31+
"left: 8px" +
32+
"}" +
33+
"</style>",
34+
);
35+
}
36+
```
37+
38+
</details>
39+
140
A video demonstration of the isolated plugin that renders an interactive Live2D of [Misono Mika](https://bluearchive.wiki/wiki/Mika). Isolated plugin has the access to DOM (`document`); also can use `window.log` (a custom logger function that wraps tauri-plugin-log), `Math`, `Date`, `URL`, `Buffer`, `window["__core-js_shared__"]`, `console`, etc. This list is not full because it is really long, and the key thing here is that we can manually pass down global variables, so important and dangerous `window.__TAURI__.*` functions are not accessible.
241

342
Isolation was done using the [Secure ECMAScript](https://github.com/endojs/endo). All globals were frozen using the `lockdown` function that `ses` library provides. So plugins can't rewrite any globals, prototypes, etc.

src/lib/global-state-helpers/scopes/get-config-global-states.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import type { ConfigType } from "@/types/application/config.type.ts";
1212
import type { GlobalStatesType } from "@/types/application/global-states.type.ts";
1313

1414
export async function getConfigGlobalStates(fresh?: boolean): Promise<GlobalStatesType> {
15+
const searchParameters = new URLSearchParams(location.search);
16+
1517
/*
1618
* We are saving at least 30 ms by re-using already fetched config, portable and base directory.
1719
*
@@ -59,7 +61,7 @@ export async function getConfigGlobalStates(fresh?: boolean): Promise<GlobalStat
5961
},
6062
},
6163
"pages": {
62-
"current": Routes.Home,
64+
"current": GlobalStateHelpers.Pages.getRouteFromSearchParameters(searchParameters),
6365
"states" : {
6466
"home" : {},
6567
"library" : {},

src/lib/global-state-helpers/scopes/get-default-global-states.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import GlobalStateHelpers from "@/lib/global-state-helpers";
55
import type { GlobalStatesType } from "@/types/application/global-states.type.ts";
66

77
export function getDefaultGlobalStates(): GlobalStatesType {
8+
const searchParameters = new URLSearchParams(location.search);
9+
810
return {
911
"translations": EnglishTranslations,
1012
"fileSystem" : undefined,
@@ -29,7 +31,7 @@ export function getDefaultGlobalStates(): GlobalStatesType {
2931
},
3032
},
3133
"pages": {
32-
"current": Routes.Home,
34+
"current": GlobalStateHelpers.Pages.getRouteFromSearchParameters(searchParameters),
3335
"states" : {
3436
"home" : {},
3537
"library" : {},

src/lib/global-state-helpers/scopes/pages.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Routes } from "@/constants/routes.ts";
12
import GlobalStateHelpers from "@/lib/global-state-helpers";
23
import type { GlobalStatesType } from "@/types/application/global-states.type.ts";
34
import type { RouteType } from "@/types/application/route.type.ts";
@@ -47,11 +48,27 @@ const replaceState = <Key extends keyof GlobalStatesType["pages"]["states"]>(
4748
"states": newStates,
4849
});
4950
};
51+
const getRouteFromSearchParameters = (searchParameters: URLSearchParams): RouteType => {
52+
const route: string | null = searchParameters.get("route");
53+
54+
if (!route) {
55+
return Routes.Home;
56+
}
57+
58+
for (const path of Object.values(Routes)) {
59+
if (route === path) {
60+
return path;
61+
}
62+
}
63+
64+
return Routes.Home;
65+
};
5066

5167
export const Pages = {
5268
navigate,
5369
getState,
5470
getAllStates,
5571
addToState,
5672
replaceState,
73+
getRouteFromSearchParameters,
5774
};

0 commit comments

Comments
 (0)