Skip to content

Commit

Permalink
feat: support open tiddlywiki
Browse files Browse the repository at this point in the history
  • Loading branch information
oeyoews committed Apr 4, 2024
1 parent 32f3742 commit 253bb43
Show file tree
Hide file tree
Showing 4 changed files with 567 additions and 69 deletions.
18 changes: 17 additions & 1 deletion entrypoints/background/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { menus, type MenuIds } from './menu';
import save2TiddlyWiki from '../../utils/save2TiddlyWiki';
// import save2TiddlyWiki from '../../utils/save2TiddlyWiki';
import * as constant from '../../utils/constant';

export default defineBackground(() => {
Expand Down Expand Up @@ -54,6 +54,22 @@ export default defineBackground(() => {
chrome.contextMenus.onClicked.addListener((info, tab) => {
const { menuItemId } = info;
switch (menuItemId as MenuIds) {
case 'usewiki2-open':
chrome.storage.local.get('port', function (result) {
if (result.port) {
chrome.tabs.create({
url: 'http://localhost:' + result.port,
});
} else {
chrome.notifications.create({
type: 'basic',
title: constant.default_name,
message: '请先连接 TiddlyWiki',
iconUrl: constant.tiddlywiki_icon,
});
}
});
break;
case 'usewiki2-save':
// TODO: 需要检查连接状态
chrome.tabs.sendMessage(
Expand Down
7 changes: 6 additions & 1 deletion entrypoints/background/menu.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
export const menus = [
{
id: 'usewiki2-open',
title: '直接打开 TiddlyWiki',
contexts: ['all'],
},
{
id: 'usewiki2-save',
title: '保存当前页面到 tiddlywiki',
title: '保存当前页面到 TiddlyWiki',
contexts: ['all'],
},
{
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "usewiki2",
"description": "Convert HTML to Markdown, and save to your computer, support nodejs tiddlywiki",
"private": true,
"version": "2.5.2",
"version": "2.6.0",
"type": "module",
"scripts": {
"dev": "wxt",
Expand Down Expand Up @@ -42,6 +42,7 @@
"unplugin-auto-import": "^0.17.5",
"unplugin-icons": "^0.18.5",
"unplugin-vue-components": "^0.26.0",
"vite-plugin-vue-devtools": "^7.0.25",
"vue": "^3.4.21"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 253bb43

Please sign in to comment.