Skip to content

Commit

Permalink
feat: support callback for playsound
Browse files Browse the repository at this point in the history
  • Loading branch information
oeyoews committed Oct 24, 2024
1 parent 8c821e3 commit 191c09e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 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": "1.4.0",
"version": "1.5.0",
"private": true,
"packageManager": "[email protected]",
"description": "",
Expand Down
16 changes: 7 additions & 9 deletions packages/react/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef, useState, type KeyboardEvent } from 'react';
import { useEffect, useRef, useState, type KeyboardEvent } from 'react';
import './App.css';
import {
ContextMenu,
Expand Down Expand Up @@ -100,17 +100,15 @@ function App() {
function submitInput() {
if (!inputValue) return;
messenger.send('sendWiki', { text: inputValue });
// NOTE: 如果需要确保发送成功后触发声音需要使用双向通信, vscode 本身不支持播放声音???
// TODO: 添加配置, 同样需要借助双向通信拿到vscode 配置
// messenger.send('playSound', {});

playSound();
setInputValue('');
inputRef.current?.focus();
}
// messenger.on('playSound', () => {
// playSound();
// });

useEffect(() => {
messenger.on('playSound', () => {
playSound();
});
}, []);

return (
// vscode-dark
Expand Down
1 change: 1 addition & 0 deletions src/sendTiddler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ export default async function sendTiddler(text: string) {
}
} catch (error) {
notify((error as Error).message, 'error');
throw Error((error as Error).message);
}
}
16 changes: 5 additions & 11 deletions src/webviews/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,16 @@ export class usewikiViewProvider implements vscode.WebviewViewProvider {
webviewView.webview.html = this.getWebviewContent(webviewView.webview);
const messenger = new WebviewMessenger({ context: this._view });

// 直接写 callback,处理来自 Webview 的 Ping 消息
// messenger.on('ping', (data) => {
// vscode.window.showInformationMessage(data.text); // 直接处理消息
// messenger.send('pong', { text: 'Pong from VSCode!' });
// });

// messenger.send('startup', { text: 'Startup from VSCode!' });

messenger.on('openLink', (data) => {
vscode.env.openExternal(vscode.Uri.parse(data.link));
});
messenger.on('openWiki', (data) => {
messenger.on('openWiki', () => {
openWikiCmd.cli();
});
messenger.on('sendWiki', (data) => {
sendTiddler(data.text);
messenger.on('sendWiki', ({ text }) => {
sendTiddler(text).then(() => {
messenger.send('playSound');
});
});
}
private getWebviewContent(webview: vscode.Webview) {
Expand Down

0 comments on commit 191c09e

Please sign in to comment.