Skip to content

Commit

Permalink
🔀 Merge branch '#198-refactor_notebook'
Browse files Browse the repository at this point in the history
  • Loading branch information
frostime committed Oct 9, 2024
2 parents 18f0ee7 + 5343280 commit bce3ce1
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"minimist": "^1.2.8",
"rollup-plugin-livereload": "^2.0.5",
"sass": "^1.72.0",
"siyuan": "1.0.2",
"siyuan": "1.0.3",
"siyuan-plugin-cli": "^1.2.0",
"svelte": "^4.2.19",
"sy-plugin-changelog": "^0.0.7",
Expand Down
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
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/event-bus.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
* Copyright (c) 2024 by frostime. All Rights Reserved.
* @Author : frostime
* @Date : 2023-05-28 18:05:39
* @FilePath : /src/event-bus.ts
* @LastEditTime : 2024-10-09 17:07:56
* @Description : For old time compatibility.
*/

class EventBus {
events: { [key: string]: Function[] } = {};
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 bce3ce1

Please sign in to comment.