Skip to content

Commit

Permalink
✨ feat: 自动更新 box 状态 close #198
Browse files Browse the repository at this point in the history
  • Loading branch information
frostime committed Oct 9, 2024
1 parent effcc8b commit 5343280
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"url": "https://github.com/frostime/siyuan-dailynote-today",
"version": "1.6.9",
"minAppVersion": "3.0.0",
"minAppVersion": "3.1.7",
"description": {
"zh_CN": "自动创建日记 + 快速打开日记 + 日程 TODO 管理 + 移动块功能",
"en_US": "Automatically open today's notes + Quickly open today's notes + TODO mangagement for today + Move blocks"
Expand Down
20 changes: 16 additions & 4 deletions src/func/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { settings } from '@/global-status';
import { autoOpenDailyNote, checkDuplicateDiary } from './dailynote';

import type DailyNoteTodayPlugin from '@/index';
import type { EventBus } from 'siyuan';
import type { EventBus, IEventBusMap } from 'siyuan';
import { debouncer } from '@/utils';
import { isTodayReserved, updateTodayReservation } from './reserve';
import { updateStyleSheet } from './style';
Expand All @@ -28,6 +28,7 @@ export class RoutineEventHandler {
eventBus: EventBus;

onSyncEndBindThis = this.onSyncEnd.bind(this);
onNotebookChangedBindThis = this.onNotebookChanged.bind(this);

flag = {
hasOpened: false,
Expand All @@ -53,15 +54,17 @@ export class RoutineEventHandler {
); // 防抖, 避免频繁检查
}

bindSyncEvent() {
private bindSyncEvent() {
this.eventBus.on('sync-end', this.onSyncEndBindThis);
}

unbindSyncEvent() {
private unbindSyncEvent() {
this.eventBus.off('sync-end', this.onSyncEndBindThis);
}

async onPluginLoad() {
public async onPluginLoad() {
this.plugin.eventBus.on('opened-notebook', this.onNotebookChangedBindThis);
this.plugin.eventBus.on('closed-notebook', this.onNotebookChangedBindThis);

this.updateResvIconStyle();
const SYNC_ENABLED = window.siyuan.config.sync.enabled;
Expand All @@ -77,6 +80,10 @@ export class RoutineEventHandler {
this.bindSyncEvent();
}
}
public onPluginUnload() {
this.plugin.eventBus.off('opened-notebook', this.onNotebookChangedBindThis);
this.plugin.eventBus.off('closed-notebook', this.onNotebookChangedBindThis);
}

async onSyncEnd({ detail }) {
console.debug('on-sync-end');
Expand All @@ -90,6 +97,11 @@ export class RoutineEventHandler {
}
}

async onNotebookChanged(e: CustomEvent<IEventBusMap['opened-notebook'] | IEventBusMap['closed-notebook']>) {
console.debug('on-notebook-changed', e.detail);
await notebooks.update();
}


public resetStatusFlag() {
this.flag.isSyncChecked = false; //重置同步检查状态
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ export default class DailyNoteTodayPlugin extends Plugin {
this.gutterMenu.release();
}
toggleGeneralDailynoteKeymap(true);

//TODO 后面把这些乱七八糟的事件绑定全都放到这里面去
this.routineHandler.onPluginUnload();
}
}

Expand Down

0 comments on commit 5343280

Please sign in to comment.