Skip to content

Commit

Permalink
feat: 1. base framework for chatGPT and bing chat 2. rename plugin name
Browse files Browse the repository at this point in the history
  • Loading branch information
JuckZ committed Feb 17, 2023
1 parent cd1db51 commit 73d2c57
Show file tree
Hide file tree
Showing 18 changed files with 334 additions and 124 deletions.
4 changes: 2 additions & 2 deletions .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ tag-version-prefix=""
registry = https://registry.npm.taobao.org
electron_mirror=https://npmmirror.com/mirrors/electron/
# proxy=http:https://localhost:7890
# https-proxy=http:https://localhost:7890
# https_proxy=http:https://localhost:7890
https-proxy=http:https://localhost:7890
https_proxy=http:https://localhost:7890
3 changes: 3 additions & 0 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ await esbuild
'@lezer/common',
'@lezer/highlight',
'@lezer/lr',
'node:readline',
'node:process',
'node:crypto',
...builtins,
],
format: 'cjs',
Expand Down
220 changes: 152 additions & 68 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
"jsonfile": "^6.1.0",
"naive-ui": "^2.34.3",
"obsidian-daily-notes-interface": "^0.9.4",
"openai": "^3.1.0",
"ora": "^6.1.2",
"party-js": "^2.2.0",
"rrule": "^2.7.1",
"sql.js": "^1.8.0",
Expand Down
12 changes: 6 additions & 6 deletions src/dispatch/spaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type ObsidianManagerPlugin from 'main';
import type AwesomeBrainManagerPlugin from 'main';
import { VaultItem, vaultSchema } from 'schemas/spaces';
import { SpaceChange, eventTypes } from 'types/types';
import { deleteFromDB, execQuery, insertIntoDB, updateDB } from 'utils/db/db';
Expand All @@ -14,7 +14,7 @@ export const dispatchSpaceDatabaseFileChanged = (type: SpaceChange) => {
window.dispatchEvent(evt);
};

export const onFileCreated = async (plugin: ObsidianManagerPlugin, newPath: string, folder: boolean) => {
export const onFileCreated = async (plugin: AwesomeBrainManagerPlugin, newPath: string, folder: boolean) => {
const parent = getAbstractFileAtPath(app, newPath)?.parent?.path;
const db = plugin.spaceDBInstance();
insertIntoDB(db, {
Expand All @@ -34,15 +34,15 @@ export const onFileCreated = async (plugin: ObsidianManagerPlugin, newPath: stri
dispatchSpaceDatabaseFileChanged('vault');
};

export const onFileDeleted = (plugin: ObsidianManagerPlugin, oldPath: string) => {
export const onFileDeleted = (plugin: AwesomeBrainManagerPlugin, oldPath: string) => {
const db = plugin.spaceDBInstance();
deleteFromDB(db, 'vault', `path = '${sanitizeSQLStatement(oldPath)}'`);
deleteFromDB(db, 'spaceItems', `path = '${sanitizeSQLStatement(oldPath)}'`);
plugin.saveSpacesDB();
dispatchSpaceDatabaseFileChanged('vault');
};

export const onFileChanged = (plugin: ObsidianManagerPlugin, oldPath: string, newPath: string) => {
export const onFileChanged = (plugin: AwesomeBrainManagerPlugin, oldPath: string, newPath: string) => {
const newFolderPath = getFolderPathFromString(newPath);
const db = plugin.spaceDBInstance();
updateDB(
Expand Down Expand Up @@ -73,7 +73,7 @@ export const onFileChanged = (plugin: ObsidianManagerPlugin, oldPath: string, ne
dispatchSpaceDatabaseFileChanged('vault');
};

export const onFolderChanged = (plugin: ObsidianManagerPlugin, oldPath: string, newPath: string) => {
export const onFolderChanged = (plugin: AwesomeBrainManagerPlugin, oldPath: string, newPath: string) => {
const newFolderPath = getFolderFromPath(app, newPath)?.parent.path;
const db = plugin.spaceDBInstance();
updateDB(
Expand Down Expand Up @@ -116,7 +116,7 @@ export const onFolderChanged = (plugin: ObsidianManagerPlugin, oldPath: string,
dispatchSpaceDatabaseFileChanged('vault');
};

export const onFolderDeleted = (plugin: ObsidianManagerPlugin, oldPath: string) => {
export const onFolderDeleted = (plugin: AwesomeBrainManagerPlugin, oldPath: string) => {
const db = plugin.spaceDBInstance();
deleteFromDB(
db,
Expand Down
12 changes: 7 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import {
updateDBConditionally,
} from 'utils/db/db';
import { insertAfterHandler, setBanner } from 'utils/content';
import { changeChatPopover, getEditorPositionFromIndex } from 'utils/editor';
import { changeChatPopover, getEditorPositionFromIndex, loadChatEl, unloadChatEl } from 'utils/editor';
import { getLocalRandom, searchPicture } from 'utils/genBanner';
import { loadSQL } from 'utils/db/sqljs';
import { PomodoroStatus, initiateDB } from 'utils/promotodo';
Expand All @@ -77,7 +77,7 @@ import t from './i18n';
import './main.scss';

const media = window.matchMedia('(prefers-color-scheme: dark)');
export default class ObsidianManagerPlugin extends Plugin {
export default class AwesomeBrainManagerPlugin extends Plugin {
override app: ExtApp;
pluginDataIO: PluginDataIO;
public docDirSettings = new DocumentDirectionSettings();
Expand Down Expand Up @@ -333,7 +333,7 @@ export default class ObsidianManagerPlugin extends Plugin {
/*** Next, if it is a valid daily note, but we don't have daily notes enabled, we must alert the user ***/
if (!this.isDailyNotesEnabled()) {
new Notice(
'ObsidianManagerPlugin unable to rollover unfinished todos: Please enable Daily Notes, or Periodic Notes (with daily notes enabled).',
'AwesomeBrainManagerPlugin unable to rollover unfinished todos: Please enable Daily Notes, or Periodic Notes (with daily notes enabled).',
10000,
);
} else {
Expand Down Expand Up @@ -528,8 +528,8 @@ export default class ObsidianManagerPlugin extends Plugin {
// Logger.log(`Unable to find text "${clipboardText}" in current editor`);
// } else {
// const end = start + clipboardText.length;
// const startPos = ObsidianManagerPlugin.getEditorPositionFromIndex(text, start);
// const endPos = ObsidianManagerPlugin.getEditorPositionFromIndex(text, end);
// const startPos = AwesomeBrainManagerPlugin.getEditorPositionFromIndex(text, start);
// const endPos = AwesomeBrainManagerPlugin.getEditorPositionFromIndex(text, end);
// editor.replaceRange(newLine, startPos, endPos);
// return;
// }
Expand Down Expand Up @@ -1026,6 +1026,7 @@ export default class ObsidianManagerPlugin extends Plugin {
}

private setupUI() {
loadChatEl();
this.style = document.head.createEl('style', {
attr: { id: 'OBSIDIAN_MANAGER_CUSTOM_STYLE_SHEET' },
});
Expand Down Expand Up @@ -1120,6 +1121,7 @@ export default class ObsidianManagerPlugin extends Plugin {
}

override async onunload(): Promise<void> {
unloadChatEl();
toggleBlast('0');
this.app.workspace.detachLeavesOfType(POMODORO_HISTORY_VIEW);
this.style.detach();
Expand Down
59 changes: 52 additions & 7 deletions src/ui/ChatView.vue
Original file line number Diff line number Diff line change
@@ -1,26 +1,71 @@
<template>
<h2>safsadfsdfsdah2</h2>
<div>
聊天历史在这里哦1
<div>
<div @click="clickHandle('bing')">问问bing chat</div>
<div @click="clickHandle('chatGpt')">问问chatGPT</div>
<div @click="clickHandle('genImageWithChatGPT')">chatGPT生成图</div>
<div>百度一下</div>
<div>Google</div>
</div>
</div>
</template>

<script setup lang="ts">
import { Ref, onMounted, onUnmounted, ref, toRefs } from 'vue';
import { NNotificationProvider, NSpace, useNotification } from 'naive-ui';
import t from '../i18n';
import { chatWithBing, chatWithChatGPT, genImageWithChatGPT } from '../utils/ThirdPartyService';
import Title from './Title';
const props = defineProps<{}>();
const props = defineProps<{
keyword: string;
}>();
const index = ref(0);
const notification = useNotification();
const clickHandle = async (type: string) => {
console.log(notification);
switch (type) {
case 'bing':
conversation('chatGpt', 'jahajhjahas');
break;
case 'chatGpt':
conversation('chatGpt', await chatWithChatGPT());
break;
case 'genImageWithChatGpt':
console.log(await genImageWithChatGPT());
break;
default:
return;
}
};
const conversation = (owner: string, content: string) => {
index.value++;
notification.info({
// TODO,使用tsx
// avatar: () => '',
title: `${owner}: 这是第 ${index.value}个对话`,
content,
});
};
onMounted(async () => {
console.log('ssss');
console.log('onMounted');
});
onUnmounted(() => {
console.log('4444');
console.log('onUnmounted');
});
</script>

<style scoped lang="scss">
.radialTimeText {
font-size: 32px;
font-weight: 600;
#chatHistory {
position: fixed;
top: 50px;
right: 20px;
color: yellow;
}
</style>
29 changes: 29 additions & 0 deletions src/ui/ChatViewContainer.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<template>
<div>
<NNotificationProvider :max="3"> <ChatView :keyword="'xxxx'" /> </NNotificationProvider>
</div>
</template>

<script setup lang="ts">
import { Ref, onMounted, onUnmounted, ref, toRefs } from 'vue';
import { NNotificationProvider, NSpace, useNotification } from 'naive-ui';
import t from '../i18n';
import ChatView from '../ui/ChatView.vue';
onMounted(async () => {
console.log('onMounted');
});
onUnmounted(() => {
console.log('onUnmounted');
});
</script>

<style scoped lang="scss">
#chatHistory {
position: fixed;
top: 50px;
right: 20px;
color: yellow;
}
</style>
4 changes: 2 additions & 2 deletions src/ui/PomodoroHistory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import DoughnutChart from './DoughnutChart.vue';
import LineChart from './LineChart.vue';
import { pomodoroDB } from '../utils/constants';
import { selectDB } from '../utils/db/db';
import type ObsidianManagerPlugin from '../main';
import type AwesomeBrainManagerPlugin from '../main';
import { eventTypes } from '../types/types';
// const darkTheme = createTheme([inputDark, datePickerDark]);
Expand Down Expand Up @@ -83,7 +83,7 @@ const darkThemeOverrides: GlobalThemeOverrides = {
};
const props = defineProps<{
plugin: ObsidianManagerPlugin;
plugin: AwesomeBrainManagerPlugin;
}>();
let H1Title = () => (
Expand Down
4 changes: 2 additions & 2 deletions src/ui/TimeLine.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ import { NDropdown, NEmpty, NIcon, NSpace, NTag, NTimeline, NTimelineItem, useMe
import { Airplane, RadioButtonOffOutline } from '@vicons/ionicons5';
import { onUpdated, toRefs } from 'vue';
import moment from 'moment';
import type ObsidianManagerPlugin from '../main';
import type AwesomeBrainManagerPlugin from '../main';
import { Pomodoro } from '../schemas/spaces';
import { PomodoroStatus } from '../utils/promotodo';
import t from '../i18n';
const props = defineProps<{
pomodoroList: Pomodoro[];
plugin: ObsidianManagerPlugin;
plugin: AwesomeBrainManagerPlugin;
}>();
const { pomodoroList, plugin } = toRefs(props);
Expand Down
6 changes: 3 additions & 3 deletions src/ui/modal/customModals.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type ObsidianManagerPlugin from 'main';
import type AwesomeBrainManagerPlugin from 'main';
import { App, FuzzySuggestModal, Modal, Notice, Setting, SuggestModal, TAbstractFile } from 'obsidian';
import type { Pomodoro } from 'schemas/spaces';
import t from '../../i18n';
Expand Down Expand Up @@ -41,9 +41,9 @@ const ALL_BOOKS = [

export class ImageOriginModal extends FuzzySuggestModal<ImageOrigin> {
selectedPath: TAbstractFile | null;
plugin: ObsidianManagerPlugin;
plugin: AwesomeBrainManagerPlugin;

constructor(app: App, plugin: ObsidianManagerPlugin, path: TAbstractFile | null) {
constructor(app: App, plugin: AwesomeBrainManagerPlugin, path: TAbstractFile | null) {
super(app);
this.plugin = plugin;
this.selectedPath = path;
Expand Down
6 changes: 3 additions & 3 deletions src/ui/view/ChatView.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { HoverPopover, ItemView, WorkspaceLeaf } from 'obsidian';
import { App as VueApp, createApp } from 'vue';
import type ObsidianManagerPlugin from 'main';
import type AwesomeBrainManagerPlugin from 'main';
import Title from '../Title';
import t from '../../i18n';

export const CHAT_VIEW = 'chat-view';

export class ChartView extends ItemView {
vueapp: VueApp;
plugin: ObsidianManagerPlugin;
plugin: AwesomeBrainManagerPlugin;
hoverPopover: HoverPopover | null;

constructor(leaf: WorkspaceLeaf, plugin: ObsidianManagerPlugin) {
constructor(leaf: WorkspaceLeaf, plugin: AwesomeBrainManagerPlugin) {
super(leaf);
this.plugin = plugin;
}
Expand Down
6 changes: 3 additions & 3 deletions src/ui/view/LedgerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { HoverPopover, ItemView, WorkspaceLeaf } from 'obsidian';
import { App as VueApp, createApp } from 'vue';
import { selectDB } from 'utils/db/db';
import type { Ledger } from 'schemas/spaces';
import type ObsidianManagerPlugin from 'main';
import type AwesomeBrainManagerPlugin from 'main';
import { eventTypes } from 'types/types';
import type { DBRows } from 'types/mdb';
import PomodoroHistory from '../PomodoroHistory.vue';
Expand All @@ -11,10 +11,10 @@ export const Ledger_HISTORY_VIEW = 'Ledger-history-view';

export class LedgerHistoryView extends ItemView {
vueapp: VueApp;
plugin: ObsidianManagerPlugin;
plugin: AwesomeBrainManagerPlugin;
hoverPopover: HoverPopover | null;

constructor(leaf: WorkspaceLeaf, plugin: ObsidianManagerPlugin) {
constructor(leaf: WorkspaceLeaf, plugin: AwesomeBrainManagerPlugin) {
super(leaf);
this.plugin = plugin;
}
Expand Down
6 changes: 3 additions & 3 deletions src/ui/view/PomodoroHistoryView.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { HoverPopover, ItemView, WorkspaceLeaf } from 'obsidian';
import { App as VueApp, createApp } from 'vue';
import type ObsidianManagerPlugin from 'main';
import type AwesomeBrainManagerPlugin from 'main';
import PomodoroHistory from '../PomodoroHistory.vue';
import t from '../../i18n';

export const POMODORO_HISTORY_VIEW = 'pomodoro-history-view';

export class PomodoroHistoryView extends ItemView {
vueapp: VueApp;
plugin: ObsidianManagerPlugin;
plugin: AwesomeBrainManagerPlugin;
hoverPopover: HoverPopover | null;

constructor(leaf: WorkspaceLeaf, plugin: ObsidianManagerPlugin) {
constructor(leaf: WorkspaceLeaf, plugin: AwesomeBrainManagerPlugin) {
super(leaf);
this.plugin = plugin;
}
Expand Down
6 changes: 3 additions & 3 deletions src/ui/view/PomodoroView.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { HoverPopover, ItemView, WorkspaceLeaf } from 'obsidian';
import { App as VueApp, createApp } from 'vue';
import type ObsidianManagerPlugin from 'main';
import type AwesomeBrainManagerPlugin from 'main';
import Title from '../Title';
import t from '../../i18n';

export const POMODORO_VIEW = 'pomodoro-view';

export class PomodoroView extends ItemView {
vueapp: VueApp;
plugin: ObsidianManagerPlugin;
plugin: AwesomeBrainManagerPlugin;
hoverPopover: HoverPopover | null;

constructor(leaf: WorkspaceLeaf, plugin: ObsidianManagerPlugin) {
constructor(leaf: WorkspaceLeaf, plugin: AwesomeBrainManagerPlugin) {
super(leaf);
this.plugin = plugin;
}
Expand Down
Loading

0 comments on commit 73d2c57

Please sign in to comment.