Skip to content

Commit dc9bebf

Browse files
committed
refactor(pio): update initialization logic and type definitions
- Changed the type of `pendingInit` to `number | undefined` for better type safety. - Simplified the requestIdleCallback handling by using a local variable for window type. - Improved readability and maintainability of the initialization scheduling logic.
1 parent 1f1aeed commit dc9bebf

3 files changed

Lines changed: 267 additions & 268 deletions

File tree

src/components/features/pio/Pio.astro

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const isRight = config.position === "right";
114114
let isTransitioning = false;
115115
let initSent = false;
116116
let currentConfigKey = "";
117-
let pendingInit = 0;
117+
let pendingInit: number | undefined;
118118
let swupHooksRegistered = false;
119119

120120
function applyVisibility() {
@@ -138,18 +138,17 @@ const isRight = config.position === "right";
138138

139139
function scheduleInit() {
140140
window.clearTimeout(pendingInit);
141+
const _window = window as Window & {
142+
requestIdleCallback?: (
143+
callback: IdleRequestCallback,
144+
options?: IdleRequestOptions,
145+
) => number;
146+
};
141147
const run = () => {
142148
pendingInit = window.setTimeout(postInit, 0);
143149
};
144-
if ("requestIdleCallback" in window) {
145-
(
146-
window as Window & {
147-
requestIdleCallback: (
148-
callback: IdleRequestCallback,
149-
options?: IdleRequestOptions,
150-
) => number;
151-
}
152-
).requestIdleCallback(run, { timeout: 2000 });
150+
if (_window.requestIdleCallback) {
151+
_window.requestIdleCallback(run, { timeout: 2000 });
153152
} else {
154153
pendingInit = window.setTimeout(postInit, 500);
155154
}

src/config/pioConfig.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ import type { PioConfig } from "../types/config";
22

33
// Pio 看板娘配置
44
export const pioConfig: PioConfig = {
5-
enable: true, // 启用看板娘
6-
models: ["/pio/models/NOIR/noir.model3.json"], // 默认模型路径
7-
position: "left", // 模型位置
8-
width: 280, // 默认宽度
9-
height: 250, // 默认高度
10-
mode: "draggable", // 默认为可拖拽模式
11-
hiddenOnMobile: true, // 默认在移动设备上隐藏
12-
hideAboutMenu: false, // 隐藏内置 About 菜单按钮
13-
dialog: {
14-
welcome: "Welcome to Mizuki Website!", // 欢迎词
15-
touch: [
16-
"What are you doing?",
17-
"Stop touching me!",
18-
"HENTAI!",
19-
"Don't bully me like that!",
20-
], // 触摸提示
21-
home: "Click here to go back to homepage!", // 首页提示
22-
skin: ["Want to see my new outfit?", "The new outfit looks great~"], // 换装提示
23-
close: "QWQ See you next time~", // 关闭提示
24-
link: "https://github.com/LyraVoid/Mizuki", // 关于链接
25-
},
5+
enable: true, // 启用看板娘
6+
models: ["/pio/models/NOIR/noir.model3.json"], // 默认模型路径
7+
position: "left", // 模型位置
8+
width: 280, // 默认宽度
9+
height: 250, // 默认高度
10+
mode: "draggable", // 默认为可拖拽模式
11+
hiddenOnMobile: true, // 默认在移动设备上隐藏
12+
hideAboutMenu: false, // 隐藏内置 About 菜单按钮
13+
dialog: {
14+
welcome: "Welcome to Mizuki Website!", // 欢迎词
15+
touch: [
16+
"What are you doing?",
17+
"Stop touching me!",
18+
"HENTAI!",
19+
"Don't bully me like that!",
20+
], // 触摸提示
21+
home: "Click here to go back to homepage!", // 首页提示
22+
skin: ["Want to see my new outfit?", "The new outfit looks great~"], // 换装提示
23+
close: "QWQ See you next time~", // 关闭提示
24+
link: "https://github.com/LyraVoid/Mizuki", // 关于链接
25+
},
2626
};

0 commit comments

Comments
 (0)