Skip to content

Commit

Permalink
fix: some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
JuckZ committed Mar 6, 2023
1 parent c3343f1 commit b9867da
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
13 changes: 8 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import { notifyNtfy } from './api';
import t from './i18n';
import './main.scss';
import { NotifyUtil } from './utils/notify';
import { editorUtil } from './utils/editor';
import { EditorUtil } from './utils/editor';

export const OpenUrl = ref('https://baidu.com');
const media = window.matchMedia('(prefers-color-scheme: dark)');
Expand Down Expand Up @@ -318,7 +318,7 @@ export default class AwesomeBrainManagerPlugin extends Plugin {

override async onload(): Promise<void> {
await this.pluginDataIO.load();
editorUtil.init(this);
EditorUtil.init(this);
NotifyUtil.init(this);
this.setupUI();
this.setupCommands();
Expand Down Expand Up @@ -577,7 +577,7 @@ export default class AwesomeBrainManagerPlugin extends Plugin {
this.registerView(POMODORO_HISTORY_VIEW, leaf => new PomodoroHistoryView(leaf, this));
this.registerView(BROWSER_VIEW, leaf => new BrowserView(leaf, this, OpenUrl));

editorUtil.addTags(JSON.parse(SETTINGS.customTag.value));
EditorUtil.addTags(JSON.parse(SETTINGS.customTag.value));

// 左侧菜单,使用自定义图标
this.addRibbonIcon('settings-2', 'Awesome Brain Manager', event => {
Expand Down Expand Up @@ -615,7 +615,9 @@ export default class AwesomeBrainManagerPlugin extends Plugin {
// Remove listener when we unload
this.register(() => media.removeEventListener('change', callback));
this.registerDomEvent(activeDocument, 'selectionchange', async (e: MouseEvent) => {
editorUtil.changeToolbarPopover(e, SETTINGS.toolbar);
console.log('selectionchange');

EditorUtil.changeToolbarPopover(e, SETTINGS.toolbar);
});
this.registerDomEvent(activeDocument, 'click', async (e: MouseEvent) => {
toggleMouseClickEffects(e, SETTINGS.clickString);
Expand All @@ -639,7 +641,8 @@ export default class AwesomeBrainManagerPlugin extends Plugin {
}

override async onunload(): Promise<void> {
editorUtil.unloadCustomViewContainer();
EditorUtil.unload();
NotifyUtil.onload();
toggleBlast('0');
this.app.workspace.detachLeavesOfType(POMODORO_HISTORY_VIEW);
this.style.detach();
Expand Down
4 changes: 2 additions & 2 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { PluginDataIO } from './data';
import { toggleCursorEffects } from './render/CursorEffects';
import { toggleBlast } from './render/Blast';
import t from './i18n';
import { editorUtil } from './utils/editor';
import { EditorUtil } from './utils/editor';

class Settings {
settings: SettingTabModel = new SettingTabModel();
Expand Down Expand Up @@ -107,7 +107,7 @@ class Settings {
.desc('Customized label configuration')
.text(JSON.stringify(defaultTag))
.onAnyValueChanged(context => {
editorUtil.addTags(JSON.parse(SETTINGS.customTag.value));
EditorUtil.addTags(JSON.parse(SETTINGS.customTag.value));
})
.build(new RawSerde());

Expand Down
6 changes: 4 additions & 2 deletions src/ui/Toolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ import { getNumberFromStr } from '../utils/common';
const { editorState: currentState } = storeToRefs(useEditorStore());
const isShow = ref(false);
const notification = useNotification();
let oldSelection = '';
// TODO 优化性能,还有实现方式
// watch(
Expand Down Expand Up @@ -142,7 +141,10 @@ function getElementViewTop(element) {
}
const getComputedStyle = () => {
const activeLine = activeDocument.querySelector(".cm-focused .cm-active.cm-line") as Element
if (!isShow.value) {
return;
}
const activeLine = activeDocument.querySelector('.cm-focused .cm-active.cm-line') as Element;
const getTop = () => {
let topOffset = 20;
let lineHeight = activeLine?.getCssPropertyValue('line-height') || activeLine?.getCssPropertyValue('height');
Expand Down
6 changes: 3 additions & 3 deletions src/utils/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class EditorUtils {
this.loaded = true;
}

unloadCustomViewContainer() {
unload() {
if (this.ele) {
document.body.removeChild(this.ele);
}
Expand All @@ -48,7 +48,7 @@ export class EditorUtils {
return;
}
if (!this.loaded) {
editorUtil.loadCustomViewContainer();
EditorUtil.loadCustomViewContainer();
}
const editor = this.app.workspace.activeEditor?.editor;
if (!editor) return;
Expand Down Expand Up @@ -84,4 +84,4 @@ export class EditorUtils {
};
}

export const editorUtil = new EditorUtils();
export const EditorUtil = new EditorUtils();
4 changes: 4 additions & 0 deletions src/utils/notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export class NotifyUtils {
});
}

onload() {
document.body.removeChild(this.audioEle)
}

playNoticeAudio() {
if (this.audioEle.currentSrc !== SETTINGS.noticeAudio.value) {
this.audioEle.src = SETTINGS.noticeAudio.value;
Expand Down

0 comments on commit b9867da

Please sign in to comment.