Skip to content

Commit

Permalink
fix: 1.构建库模式,不允许pinia动态修改process.env,因为会导致手机端报错 process not found: ht…
Browse files Browse the repository at this point in the history
  • Loading branch information
JuckZ committed Mar 5, 2023
1 parent d9729d0 commit 6e71794
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 46 deletions.
18 changes: 5 additions & 13 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 @@ -508,14 +508,6 @@ export default class AwesomeBrainManagerPlugin extends Plugin {
},
});

this.addCommand({
id: 'query-baidu',
name: t.command['query-baidu'] || '百度一下',
editorCallback: (editor: Editor, view: MarkdownView) => {
this.openBrowser(`https://baidu.com/s?wd=${editor.getSelection()}`)
},
});

this.addCommand({
id: 'query-openai',
name: t.command['query-openai'],
Expand Down Expand Up @@ -591,7 +583,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 @@ -629,7 +621,7 @@ export default class AwesomeBrainManagerPlugin extends Plugin {
// Remove listener when we unload
this.register(() => media.removeEventListener('change', callback));
this.registerDomEvent(activeDocument, 'mouseup', async (e: MouseEvent) => {
// editorUtil.changeToolbarPopover(e, SETTINGS.toolbar);
editorUtil.changeToolbarPopover(e, SETTINGS.toolbar);
});
this.registerDomEvent(activeDocument, 'click', async (e: MouseEvent) => {
toggleMouseClickEffects(e, SETTINGS.clickString);
Expand All @@ -653,7 +645,7 @@ export default class AwesomeBrainManagerPlugin extends Plugin {
}

override async onunload(): Promise<void> {
// editorUtil.unloadCustomViewContainer();
editorUtil.unloadCustomViewContainer();
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 @@ -105,7 +105,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
3 changes: 2 additions & 1 deletion src/stores/editor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { defineStore } from 'pinia';

import { reactive, ref } from 'vue';
import type { EditorState } from '../types/types';

export const useEditorStore = defineStore('pomodoro', () => {
export const useEditorStore = defineStore('editor', () => {
const totalTask = ref(0);

const editorState: EditorState = reactive({
Expand Down
13 changes: 3 additions & 10 deletions src/stores/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import { createApp } from 'vue';
import { createPinia } from 'pinia';
import { usePomodoroStore } from '@/stores/pomodoro';
import { useEditorStore } from '@/stores/editor';

import CustomViewContainer from '../ui/CustomViewContainer.vue';

const customViewVueApp = createApp(CustomViewContainer);

customViewVueApp.use(createPinia())
export { usePomodoroStore, useEditorStore, customViewVueApp };
import { useEditorStore } from './editor';
export default createPinia();
export { useEditorStore };
32 changes: 14 additions & 18 deletions src/ui/Toolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
</template>

<script setup lang="ts">
import { onMounted, onUnmounted, ref, onUpdated, toRefs, watchEffect } from 'vue';
import { onMounted, onUnmounted, ref, onUpdated, watchEffect } from 'vue';
import { NTooltip, NIcon, useNotification } from 'naive-ui';
import { ServiceNames, chatWith } from '../api';
import OpenAI from './components/icon/OpenAI.vue';
Expand All @@ -72,12 +72,10 @@ import { useEditorStore } from '../stores';
import { storeToRefs } from 'pinia';
import { customTitle, customContent, customAvatar, customDescription } from './CustomContent';
import type AwesomeBrainManagerPlugin from '../main';
import { eventTypes } from '../types/types';
import Logger from '../utils/logger';
const store = useEditorStore();
const { editorState: currentState } = storeToRefs(store);
const { editorState: currentState } = storeToRefs(useEditorStore());
const isShow = ref(false);
const notification = useNotification();
let oldSelection = '';
Expand Down Expand Up @@ -125,22 +123,20 @@ const clickHandle = async (type: string, keyword: string) => {
conversation(type, await chatWith(type, keyword));
break;
case ServiceNames.Baidu:
const baiduSearchEvent = new CustomEvent(eventTypes.openBrowser, {
detail: {
url: `https://baidu.com/s?wd=${keyword}`
}
});
console.log('ererer');
window.dispatchEvent(baiduSearchEvent);
const baiduSearchEvent = new CustomEvent(eventTypes.openBrowser, {
detail: {
url: `https://baidu.com/s?wd=${keyword}`,
},
});
window.dispatchEvent(baiduSearchEvent);
break;
case ServiceNames.Google:
const googleSearchEvent = new CustomEvent(eventTypes.openBrowser, {
detail: {
url: `https://www.google.com/search?q=${keyword}`
}
});
window.dispatchEvent(googleSearchEvent);
const googleSearchEvent = new CustomEvent(eventTypes.openBrowser, {
detail: {
url: `https://www.google.com/search?q=${keyword}`,
},
});
window.dispatchEvent(googleSearchEvent);
break;
default:
return;
Expand Down
11 changes: 9 additions & 2 deletions src/utils/editor.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import type { Editor } from 'obsidian';
import { createApp, type App } from 'vue';
import type AwesomeBrainManagerPlugin from '../main';
import type { SettingModel } from 'model/settings';
import { customViewVueApp, useEditorStore } from '@/stores';
import CustomViewContainer from '../ui/CustomViewContainer.vue';
import { buildTagRules } from '../render/Tag';
import { Tag, type ExtApp } from '@/types/types';
import pinia, { useEditorStore } from '@/stores'

export const elId = 'custom-view-container';



export class EditorUtils {
plugin: AwesomeBrainManagerPlugin;
app: ExtApp;
ele: HTMLDivElement;
loaded: boolean = false;
customViewVueApp: App;

constructor() {}

Expand All @@ -26,7 +31,9 @@ export class EditorUtils {
id: elId,
},
});
customViewVueApp.mount(`#${elId}`);
this.customViewVueApp = createApp(CustomViewContainer);
this.customViewVueApp.use(pinia)
this.customViewVueApp.mount(`#${elId}`);
this.loaded = true;
}

Expand Down
3 changes: 3 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ export default defineConfig({
],
},
},
define: {
'process.env.NODE_ENV': '"production"'
},
plugins: [
viteStaticCopy({
targets: [
Expand Down

0 comments on commit 6e71794

Please sign in to comment.