-
Notifications
You must be signed in to change notification settings - Fork 93
[WIP] feat: 添加计时器功能以跟踪阅读时间并提供显示选项 #207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { useSettingStore } from '@/stores/setting'; | ||
| /** 启动和销毁计时器 hooks */ | ||
| export const userTimer = () => { | ||
| const settingStore = useSettingStore(); | ||
|
|
||
| const timerId = ref(); | ||
|
|
||
| onMounted(() => { | ||
| timerId.value = setInterval(() => { | ||
| settingStore.readTime += 1; | ||
| }, 1000); | ||
| }); | ||
|
|
||
| onBeforeUnmount(() => { | ||
| if (timerId.value) { | ||
| clearInterval(timerId.value); | ||
| } | ||
| }); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -53,6 +53,7 @@ | |||||||
| import { ContentType } from '@any-reader/rule-utils'; | ||||||||
| import { useContent, useTheme } from '@/pages/common/content'; | ||||||||
| import { useReadStore } from '@/stores/read'; | ||||||||
| import { userTimer } from '@/pages/common/timer'; | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Update import name and add error handling. The import should be updated to match the corrected function name from the timer module. -import { userTimer } from '@/pages/common/timer';
+import { useTimer } from '@/pages/common/timer';📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
|
|
||||||||
| const contentRef = ref(); | ||||||||
|
|
||||||||
|
|
@@ -62,6 +63,8 @@ const { content, contentType, settingStore, lastChapter, nextChapter, onPageUp, | |||||||
| useContent(contentRef); | ||||||||
|
|
||||||||
| useTheme(contentRef); | ||||||||
|
|
||||||||
| userTimer(); | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Update function call and consider error handling. Update the function call to match the corrected name and consider adding error handling. -userTimer();
+useTimer();Consider wrapping the timer initialization with error handling: try {
useTimer();
} catch (error) {
console.warn('Failed to initialize reading timer:', error);
}🤖 Prompt for AI Agents |
||||||||
| </script> | ||||||||
|
|
||||||||
| <style scoped> | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,8 +8,9 @@ | |||||||||||||||||||||||||||||||||||||
| <component :is="Component" v-if="!routev.meta.keepAlive" :key="routev.fullPath" /> | ||||||||||||||||||||||||||||||||||||||
| </RouterView> | ||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||
| <div v-if="!hideBtmBar" class="flex gap-4 px-8 py-4"> | ||||||||||||||||||||||||||||||||||||||
| <div v-if="!hideBtmBar" class="flex items-center gap-4 px-8 py-4"> | ||||||||||||||||||||||||||||||||||||||
| <div class="codicon codicon-arrow-left vsc-toolbar-btn" @click="router.back()"></div> | ||||||||||||||||||||||||||||||||||||||
| <div v-if="settingStore.timeIsShow">已摸鱼:{{ showTIme }}</div> | ||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Update template to use corrected computed property name. Update the template binding to match the corrected computed property name. - <div v-if="settingStore.timeIsShow">已摸鱼:{{ showTIme }}</div>
+ <div v-if="settingStore.timeIsShow">已摸鱼:{{ showTime }}</div>📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
| <div class="flex-1"></div> | ||||||||||||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||||||||||||
| class="codicon codicon-github-alt vsc-toolbar-btn" | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -31,9 +32,22 @@ | |||||||||||||||||||||||||||||||||||||
| import '@/plugins/vsc-ui'; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import { executeCommand } from '@/api/modules/vsc'; | ||||||||||||||||||||||||||||||||||||||
| import { useSettingStore } from '@/stores/setting'; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const route = useRoute(); | ||||||||||||||||||||||||||||||||||||||
| const router = useRouter(); | ||||||||||||||||||||||||||||||||||||||
| const settingStore = useSettingStore(); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const hideBtmBar = computed(() => route.meta?.hideBtmBar); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| console.log('settingStore.readTime:', settingStore.readTime); | ||||||||||||||||||||||||||||||||||||||
| const showTIme = computed(() => { | ||||||||||||||||||||||||||||||||||||||
| const readTime = settingStore.readTime; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (readTime <= 0) return 0; | ||||||||||||||||||||||||||||||||||||||
| const hours = Math.floor(readTime / 3600); | ||||||||||||||||||||||||||||||||||||||
| const minutes = Math.floor((readTime % 3600) / 60); | ||||||||||||||||||||||||||||||||||||||
| const seconds = readTime % 60; | ||||||||||||||||||||||||||||||||||||||
| return `${hours}:${minutes}:${seconds}`; | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+44
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Fix typo in computed property name and improve formatting. The computed property has a typo and the time formatting could be improved. Apply this diff to fix the typo and improve formatting: -const showTIme = computed(() => {
+const showTime = computed(() => {
const readTime = settingStore.readTime;
if (readTime <= 0) return 0;
const hours = Math.floor(readTime / 3600);
const minutes = Math.floor((readTime % 3600) / 60);
const seconds = readTime % 60;
- return `${hours}:${minutes}:${seconds}`;
+ return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
| </script> | ||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,9 @@ | |||||||||||||||||||||||
| <SettingRow title="缓存"> | ||||||||||||||||||||||||
| <vscode-button @click="clearCache">删除缓存</vscode-button> | ||||||||||||||||||||||||
| </SettingRow> | ||||||||||||||||||||||||
| <SettingRow title="摸鱼时间"> | ||||||||||||||||||||||||
| <vscode-checkbox :checked="settingStore.timeIsShow" @input="handleInput">显示/隐藏</vscode-checkbox> | ||||||||||||||||||||||||
| </SettingRow> | ||||||||||||||||||||||||
|
Comment on lines
+12
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix checkbox binding and event handling. The current implementation has issues with the two-way binding:
Apply this diff to fix the checkbox binding: - <SettingRow title="摸鱼时间">
- <vscode-checkbox :checked="settingStore.timeIsShow" @input="handleInput">显示/隐藏</vscode-checkbox>
- </SettingRow>
+ <SettingRow title="摸鱼时间">
+ <vscode-checkbox
+ :checked="settingStore.timeIsShow"
+ @input="(event) => settingStore.timeIsShow = event.target.checked"
+ >
+ 显示/隐藏
+ </vscode-checkbox>
+ </SettingRow>📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||
| </template> | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -29,4 +32,9 @@ function clearCache() { | |||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const handleInput = (event) => { | ||||||||||||||||||||||||
| console.log('event:', event); | ||||||||||||||||||||||||
| console.log('event.target.checked:', event.target.checked); | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
|
Comment on lines
+36
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove unused event handler. The -const handleInput = (event) => {
- console.log('event:', event);
- console.log('event.target.checked:', event.target.checked);
-};📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| </script> | ||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,7 @@ import type { FontData } from '@/utils/font'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export type ReadStyle = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 字体 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| font: FontData; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| font?: FontData; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 字体大小 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fontSize: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 字体粗细 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -65,6 +65,10 @@ export const useSettingStore = defineStore('setting', () => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bookDir: '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** 是否显示摸鱼时间 */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const timeIsShow = ref<boolean>(true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const readTime = ref<number>(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+69
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider adding timer state to persistent configuration. The new
Consider moving these properties into the export type Setting = {
readStyle: ReadStyle;
keyboardShortcuts: KeyboardShortcuts;
sidebar: Sidebar;
bookDir: string;
+ timeIsShow: boolean;
+ readTime: number;
};
export const useSettingStore = defineStore('setting', () => {
const data = reactive<Setting>({
readStyle: {
// ...existing properties
},
keyboardShortcuts: {
// ...existing properties
},
sidebar: 'left',
- bookDir: ''
+ bookDir: '',
+ timeIsShow: true,
+ readTime: 0
});
- /** 是否显示摸鱼时间 */
- const timeIsShow = ref<boolean>(true);
- const readTime = ref<number>(0);
return {
data,
- readTime,
- timeIsShow,
sync
};
});Then access them via 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 同步 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async function sync() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const res = await readConfig().catch(() => {}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -81,6 +85,8 @@ export const useSettingStore = defineStore('setting', () => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| readTime, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| timeIsShow, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sync | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix missing imports and consider timer behavior.
Several critical issues need to be addressed:
userTimershould probably beuseTimerApply this diff to fix the missing imports:
Consider adding pause/resume functionality for when the user is inactive:
🤖 Prompt for AI Agents