Skip to content

Commit

Permalink
feat: support meteors config
Browse files Browse the repository at this point in the history
  • Loading branch information
oeyoews committed Nov 1, 2024
1 parent 48f3529 commit 68b1042
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 7 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"publisher": "oeyoews",
"name": "usewiki2",
"displayName": "usewiki2",
"version": "2.8.1",
"version": "2.8.2",
"private": true,
"packageManager": "pnpm@9.0.6",
"description": "",
Expand Down Expand Up @@ -38,6 +38,11 @@
"type": "object",
"title": "UseWiki2",
"properties": {
"usewiki2.enableMeteors": {
"type": "boolean",
"default": false,
"description": "%usewiki2.enableMeteors%"
},
"usewiki2.enableSendSound": {
"type": "boolean",
"default": false,
Expand Down
3 changes: 2 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"usewiki2.port": "Port",
"usewiki2.enableHttps": "Enable HTTPS",
"usewiki2.lang": "Setup Usewiki2 Language",
"usewiki2.type": "saved type"
"usewiki2.type": "saved type",
"usewiki2.enableMeteors": "Enable Meteors"
}
3 changes: 2 additions & 1 deletion package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"usewiki2.port": "端口号",
"usewiki2.enableHttps": "使用 Https",
"usewiki2.lang": "设置太微助手语言",
"usewiki2.type": "保存类型"
"usewiki2.type": "保存类型",
"usewiki2.enableMeteors": "开启流星特效"
}
16 changes: 14 additions & 2 deletions packages/react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function App() {
const inputRef = useRef<HTMLTextAreaElement>(null);
const [placeholder, setPlaceholder] = useState(t('placeholder'));
const [dark, setDark] = useState(false);
const [enableMeteors, setEnableMeteors] = useState(false);

function changeLanguage(lang: ILanguage) {
i18n.changeLanguage(lang);
Expand Down Expand Up @@ -80,6 +81,18 @@ function App() {
inputRef.current?.focus();
}

useEffect(() => {
messenger.send('enableMeteors');
messenger.on('enableMeteors', ({ text }) => {
console.log('enableMeteors', text);
if (text === true) {
setEnableMeteors(true);
} else {
setEnableMeteors(false);
}
});
}, []);

useEffect(() => {
if (localStorage.getItem('text')) {
setInputValue(localStorage.getItem('text')!);
Expand Down Expand Up @@ -167,8 +180,7 @@ function App() {
</ContextMenuContent>
</ContextMenu>
{/* meeteors */}
{/* TODO: 添加开关配置 */}
{dark && (
{dark && enableMeteors && (
<div className="flex w-full flex-col items-center justify-center overflow-hidden pointer-events-none">
<Meteors number={20} />
</div>
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const config = () => workspace.getConfiguration('usewiki2');
export const enableSendSound = () => config().get('enableSendSound', false);

export const enableHttps = () => config().get('enableHttps', false);
export const enableMeteors = () => config().get('enableMeteors', false);
export const defaultTag = () => config().get('defaultTag', 'Journal');
export const defaultUsername = () => config().get('defaultUsername', '');
export const getLang = () => config().get('lang', 'en');
Expand Down
15 changes: 15 additions & 0 deletions src/generated/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const commands = {
* Type union of all configs
*/
export type ConfigKey =
| "usewiki2.enableMeteors"
| "usewiki2.enableSendSound"
| "usewiki2.defaultTag"
| "usewiki2.defaultUsername"
Expand All @@ -52,6 +53,7 @@ export type ConfigKey =
| "usewiki2.type"

export interface ConfigKeyTypeMap {
"usewiki2.enableMeteors": boolean,
"usewiki2.enableSendSound": boolean,
"usewiki2.defaultTag": string,
"usewiki2.defaultUsername": string,
Expand All @@ -63,6 +65,7 @@ export interface ConfigKeyTypeMap {
}

export interface ConfigShorthandMap {
enableMeteors: "usewiki2.enableMeteors",
enableSendSound: "usewiki2.enableSendSound",
defaultTag: "usewiki2.defaultTag",
defaultUsername: "usewiki2.defaultUsername",
Expand All @@ -83,6 +86,16 @@ export interface ConfigItem<T extends keyof ConfigKeyTypeMap> {
* Configs map registed by `oeyoews.usewiki2`
*/
export const configs = {
/**
* %usewiki2.enableMeteors%
* @key `usewiki2.enableMeteors`
* @default `false`
* @type `boolean`
*/
enableMeteors: {
key: "usewiki2.enableMeteors",
default: false,
} as ConfigItem<"usewiki2.enableMeteors">,
/**
* %usewiki2.enableSendSound.title%
* @key `usewiki2.enableSendSound`
Expand Down Expand Up @@ -166,6 +179,7 @@ export const configs = {
}

export interface ScopedConfigKeyTypeMap {
"enableMeteors": boolean,
"enableSendSound": boolean,
"defaultTag": string,
"defaultUsername": string,
Expand All @@ -179,6 +193,7 @@ export interface ScopedConfigKeyTypeMap {
export const scopedConfigs = {
scope: "usewiki2",
defaults: {
"enableMeteors": false,
"enableSendSound": false,
"defaultTag": "Journal",
"defaultUsername": "",
Expand Down
15 changes: 13 additions & 2 deletions src/webviews/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sendTiddler from '../sendTiddler';
import * as openWikiCmd from '../commands/openWikiCmd';
import { WebviewMessenger } from '../utils/extensionMessenger';
import { enableSendSound, getLang } from '../config';
import { enableMeteors, enableSendSound, getLang } from '../config';
import { showLanguagePicker } from './showLangPicker';
import {
Uri,
Expand Down Expand Up @@ -38,17 +38,28 @@ export class usewikiViewProvider implements WebviewViewProvider {
localResourceRoots: [this._extensionUri],
};

const messenger = new WebviewMessenger({ context: this._view });
webviewView.webview.html = this.getWebviewContent(webviewView.webview);

messenger.on('enableMeteors', () => {
messenger.send('enableMeteors', { text: enableMeteors() });
});

workspace.onDidChangeConfiguration((e) => {
// switch meteors
if (e.affectsConfiguration('usewiki2.enableMeteors')) {
messenger.send('enableMeteors', {
text: enableMeteors(),
});
}
// lang switch
if (e.affectsConfiguration('usewiki2.lang')) {
messenger.send('changeLanguage', { text: getLang() });
// 全局刷新, 但是需要webview 主动检查语言配置
// webviewView.webview.html = this.getWebviewContent(webviewView.webview);
}
});

const messenger = new WebviewMessenger({ context: this._view });
this._messenger = messenger;
messenger.on('changeTheme', () => {
this.checkTheme();
Expand Down

0 comments on commit 68b1042

Please sign in to comment.