Skip to content

Commit

Permalink
feat: 1.ntfy support 2.server host config
Browse files Browse the repository at this point in the history
  • Loading branch information
JuckZ committed Mar 3, 2023
1 parent dd18cf4 commit 8939289
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 114 deletions.
178 changes: 90 additions & 88 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,88 +1,90 @@
# vscode
.vscode

# Intellij
*.iml
.idea

# npm
node_modules

# Don't include the compiled main.js file in the repo.
# They should be uploaded to GitHub releases instead.

# Exclude sourcemaps
*.map

dest
awesome-brain-manager

# obsidian
data.json

# Exclude macOS Finder (System Explorer) View States
.DS_Store

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http:https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

dist/**
# vscode
.vscode

# Intellij
*.iml
.idea

# npm
node_modules

# Don't include the compiled main.js file in the repo.
# They should be uploaded to GitHub releases instead.

# Exclude sourcemaps
*.map

dest
awesome-brain-manager

# obsidian
data.json

# Exclude macOS Finder (System Explorer) View States
.DS_Store

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http:https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

dist/**

.env.local
35 changes: 15 additions & 20 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Notice } from 'obsidian';
import { request } from '../utils/request';
import Logger from '../utils/logger';
import { SETTINGS } from '../settings';

export type ServiceName = 'Bing' | 'OpenAI' | 'ChatGPT' | 'GenImageWithChatGPT' | 'Baidu' | 'Google';
export const ServiceNames = {
Expand All @@ -14,30 +16,23 @@ export const ServiceNames = {
export const chatWith = async (type: string, keyword: string) => {
// TODO保证不同人进来,是不同的会话
const res = await request({
url: `http:https://localhost:8080/aichat/${type}?keyword=${keyword}`,
// url: `https://vercel-express-juckz.vercel.app/aichat/${type}?keyword=${keyword}`,
url: `${SETTINGS.serverHost.value}/api/aichat/${type}?keyword=${keyword}`,
method: 'get',
});
return res;
};

export const notify = (msg: any, config: any) => {
let auth = config.NTFY_AUTH;
if (!auth) {
auth = process.env.NTFY_AUTH;
}
if (auth) {
request({
url: 'https://ntfy.ihave.cool/test',
method: 'post',
body: 'msg',
headers: {
Authorization: `Basic ${auth}`,
},
})
.then(res => Logger.log('Ntfy sent the message successfully'))
.catch(error => Logger.error('Please check the ntfy configuration first'));
} else {
Logger.warn('Please configure ntfy first');
export const notify = (msg: any) => {
const headers = {};
if (SETTINGS.ntfyToken.value) {
headers['Authorization'] = `Basic ${SETTINGS.ntfyToken.value}`;
}
request({
url: `${SETTINGS.ntfyServerHost.value}`,
method: 'post',
body: msg,
headers,
})
.then(res => Logger.log('Ntfy sent the message successfully'))
.catch(error => Logger.error('Please check the ntfy configuration first'));
};
9 changes: 9 additions & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ declare const electron: any;
declare global {
function moment(): Moment;
}
interface ImportMetaEnv {
readonly VITE_APP_TITLE: string;
readonly env: string;
// more env variables...
}

interface ImportMeta {
readonly env: ImportMetaEnv;
}
21 changes: 18 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import type { ExtApp } from './types/types';
import { onCodeMirrorChange, toggleBlast, toggleShake } from './render/Blast';
import { pomodoroSchema } from './schemas/spaces';
import type { Pomodoro } from './schemas/spaces';
import { notify } from './api';
import t from './i18n';
import './main.scss';

Expand Down Expand Up @@ -215,6 +216,20 @@ export default class AwesomeBrainManagerPlugin extends Plugin {
new ImageOriginModal(this.app, this, this.app.workspace.getActiveFile()).open();
});
});
menu.addItem(item => {
item.setTitle('Notify this to ntfy')
.setIcon('bell')
.onClick(async () => {
const cursorPos = editor.getCursor();
let content = editor.getSelection();
if (!content) {
if (cursorPos) {
content = editor.getLine(cursorPos.line);
}
}
notify(content)
});
});
menu.addItem(item => {
item.setTitle('Query openAI')
.setIcon('bot')
Expand Down Expand Up @@ -468,7 +483,7 @@ export default class AwesomeBrainManagerPlugin extends Plugin {

this.addCommand({
id: 'query-openai',
name: t.command['query-openai'],
name: t.command['query-openai'],
hotkeys: [{ modifiers: ['Mod', 'Shift'], key: 'o' }],
// 带条件的编辑器指令
// editorCheckCallback: (checking: boolean, editor: Editor, view: MarkdownView) => {}
Expand Down Expand Up @@ -620,8 +635,8 @@ export default class AwesomeBrainManagerPlugin extends Plugin {
this.registerDomEvent(activeDocument, 'mouseup', async (e: MouseEvent) => {
changeToolbarPopover(this.app, e, SETTINGS.toolbar);
});
this.registerDomEvent(activeDocument, 'click', async (e: MouseEvent) => {
toggleMouseClickEffects(e, SETTINGS.clickString);
this.registerDomEvent(activeDocument, 'click', async (e: MouseEvent) => {
toggleMouseClickEffects(e, SETTINGS.clickString);
});
window.addEventListener(eventTypes.pomodoroChange, this.pomodoroChange.bind(this));
[
Expand Down
33 changes: 30 additions & 3 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ class Settings {
powerMode: SettingModel<string, string>;
shakeMode: SettingModel<boolean, boolean>;
toolbar: SettingModel<boolean, boolean>;
debugEnable: SettingModel<boolean, boolean>;
expectedTime: SettingModel<number, number>;
clickString: SettingModel<string, string>;
debugEnable: SettingModel<boolean, boolean>;
serverHost: SettingModel<string, string>;
ntfyServerHost: SettingModel<string, string>;
ntfyToken: SettingModel<string, string>;

constructor() {
this.cursorEffectBuilder = this.settings
Expand Down Expand Up @@ -74,7 +77,6 @@ class Settings {
.name('Show something on click')
.desc('input something you want to show, separated by commas')
.text('富强,民主,文明,和谐,自由,平等,公正,法治,爱国,敬业,诚信,友善')
.placeHolder('富强,民主,文明,和谐,自由,平等,公正,法治,爱国,敬业,诚信,友善')
.build(new RawSerde());

this.toolbar = this.settings
Expand All @@ -93,6 +95,30 @@ class Settings {
.toggle(false)
.build(new RawSerde());

this.serverHost = this.settings
.newSettingBuilder()
.key('serverHost')
.name('Server Host')
.desc('input your server address')
.text('https://vercel.ihave.cool')
.build(new RawSerde());

this.ntfyServerHost = this.settings
.newSettingBuilder()
.key('ntfyServerHost')
.name('Ntfy Server Host')
.desc('input your ntfy server address, or use the ntfy official address by default')
.text('https://ntfy.sh/change_to_your_topic_name')
.build(new RawSerde());

this.ntfyToken = this.settings
.newSettingBuilder()
.key('ntfyToken')
.name('Ntfy Token')
.desc('input your ntfy token')
.text('')
.build(new RawSerde());

this.settings
.newGroup(t.setting.title.effects)
.addSettings(this.cursorEffect, this.clickString, this.powerMode, this.shakeMode);
Expand All @@ -101,7 +127,8 @@ class Settings {

this.settings.newGroup(t.setting.title.toolbar).addSettings(this.toolbar);

this.settings.newGroup('Advanced').addSettings(this.debugEnable);
this.settings.newGroup('Notification').addSettings(this.ntfyServerHost, this.ntfyToken);
this.settings.newGroup('Advanced').addSettings(this.serverHost, this.debugEnable);
}

public forEach(consumer: (setting: SettingModel<any, any>) => void) {
Expand Down

0 comments on commit 8939289

Please sign in to comment.