Skip to content

Commit

Permalink
feat: update port
Browse files Browse the repository at this point in the history
  • Loading branch information
oeyoews committed Mar 22, 2024
1 parent 135cf9d commit 6ac3bd2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* 完成 welcome page
* tour: https://element-plus.org/zh-CN/component/tour.html
* tag
* port 改变检测
* port 通知优化
* extension icon
* 统计大小
* darkmode
Expand Down
4 changes: 2 additions & 2 deletions entrypoints/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineBackground(() => {
});
});

chrome.runtime.onInstalled.addListener(function () {
/* chrome.runtime.onInstalled.addListener(function () {
chrome.contextMenus.create({
id: 'tiddlywiki',
title: '添加到 TiddlyWiki(WIP)',
Expand All @@ -26,5 +26,5 @@ export default defineBackground(() => {
if (info.menuItemId === 'tiddlywiki') {
// 处理右键菜单点击事件的逻辑
}
});
}); */
});
61 changes: 48 additions & 13 deletions entrypoints/popup/Popup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ const link = ref('')
const faviconUrl = ref('')
const title = ref('')
const username = ref('oeyoews')
const port = ref('8000')
const port = ref('')
chrome.storage.local.get(['port'], function (result) {
port.value = result.port || '8080'
});
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
const tab = tabs[0]
Expand All @@ -43,29 +49,53 @@ chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
})
watch(md, async () => {
html.value = (await md2html(md.value))
})
const status = ref<{
username: string, tiddlywiki_version: string
}>({
username: '',
tiddlywiki_version: ''
})
fetch(`http://localhost:${port.value}/status`).then((res) => {
return res.json()
}).then((data) => {
status.value = data;
if (!data.tiddlywiki_version) {
function checkStatus() {
fetch(`http://localhost:${port.value}/status`).then((res) => {
return res.json()
}).then((data) => {
if (!data) {
return
}
status.value = data
if (!data.tiddlywiki_version) {
ElMessage({
message: 'TiddlyWiki 未连接',
type: 'error'
})
} else {
// ElMessage({
// message: 'TiddlyWiki 连接成功',
// type: 'success'
// })
}
}).catch((e) => {
ElMessage({
message: 'TiddlyWiki 未连接',
message: "TiddlyWiki 未成功连接" + e,
type: 'error'
})
}
})
}
watch(md, async () => {
html.value = (await md2html(md.value))
})
watch(port, () => {
chrome.storage.local.set({ port: port.value })
checkStatus()
})
const save2TiddlyWiki = async (title: string, text: string, port: string, url: string) => {
if (!status.value.tiddlywiki_version) {
Expand Down Expand Up @@ -95,6 +125,11 @@ const save2TiddlyWiki = async (title: string, text: string, port: string, url: s
type: 'success'
})
}
}).catch((e) => {
ElMessage({
message: '保存失败' + e,
type: 'error'
})
})
}
Expand Down Expand Up @@ -163,7 +198,7 @@ const save2TiddlyWiki = async (title: string, text: string, port: string, url: s
<div>
端口
</div>
<ElInput v-model="port" />
<ElInput v-model.trim.number="port" />
</div>


Expand Down

0 comments on commit 6ac3bd2

Please sign in to comment.