Skip to content

Commit

Permalink
feat: support wifi
Browse files Browse the repository at this point in the history
  • Loading branch information
oeyoews committed Jul 7, 2024
1 parent 4fc8e84 commit 4962936
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 15 deletions.
39 changes: 33 additions & 6 deletions entrypoints/sidepanel/Sidepanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import {
} from '@/utils/storage';
// import getAI from '@/utils/openai';
const isOnline = ref(false);
const ports = [8000, 8080, 8001, 8081];
const devMode = import.meta.env.DEV;
// const devMode = import.meta.env.DEV;
const isDarkMode = ref(false);
const editRef = ref<HTMLInputElement>();
const isChecking = ref(false);
Expand Down Expand Up @@ -107,7 +108,7 @@ onMounted(async () => {
isCheckTw5.value = await isCheckTw5Storage.getValue();
if (isCheckTw5.value) {
await checkStatus(port!, status, isChecking, username, password);
await checkStatus(port!, status, isChecking, username, password, isOnline);
}
});
Expand Down Expand Up @@ -169,21 +170,29 @@ const vanillaStatus: IStatus = {
tiddlywiki_version: '',
};
// tiddlywiki status field
const status = ref<IStatus>(vanillaStatus);
async function checkTwStatus() {
// 关闭连接tw5时, 直接关闭, 不进行检查网络连接是否成功
if (isCheckTw5.value) {
status.value.tiddlywiki_version = '';
status.value.username = '';
isOnline.value = false;
await isCheckTw5Storage.setValue(false);
return true;
}
await isCheckTw5Storage.setValue(true);
const value = await isCheckTw5Storage.getValue();
let res = false;
res = await checkStatus(port!, status, isChecking, username, password);
res = await checkStatus(
port!,
status,
isChecking,
username,
password,
isOnline
);
return res;
}
Expand Down Expand Up @@ -238,7 +247,14 @@ async function savePort(port: number) {
await portStorage.setValue(port);
if (isCheckTw5.value) {
// 更新status
await checkStatus(toRef(port), status, isChecking, username, password);
await checkStatus(
toRef(port),
status,
isChecking,
username,
password,
isOnline
);
} else {
notify({
message: '保存成功',
Expand All @@ -259,7 +275,7 @@ async function saveAuth(option: { username: string; password: string }) {
}
await authStorage.setValue(option);
if (isCheckTw5.value) {
await checkStatus(port, status, isChecking, username, password);
await checkStatus(port, status, isChecking, username, password, isOnline);
} else {
notify({
message: '保存成功',
Expand Down Expand Up @@ -342,6 +358,17 @@ const toggleInfoDialog = () => {
<div class="inset-x-0 top-0 fixed z-[10]">
<div
class="backdrop-blur-sm z-[999] flex justify-end items-center inset-x-0 gap-1 p-2 px-6">
<el-tag size="large">
<!-- <WI.SvgSpinnersWifi
class="text-gray-500"
v-if="isChecking && !isOnline" /> -->
<WI.RiWifiFill
class="text-emerald-600"
v-if="isOnline" />
<WI.MdiWifiOff
class="text-rose-600"
v-else />
</el-tag>
<el-dropdown
size="default"
split-button
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": "3.8.5",
"version": "3.9.0",
"type": "module",
"scripts": {
"dev": "wxt",
Expand Down Expand Up @@ -62,6 +62,7 @@
"@iconify-json/ri": "^1.1.21",
"@iconify-json/simple-icons": "^1.1.108",
"@iconify-json/streamline": "^1.1.8",
"@iconify-json/svg-spinners": "^1.1.2",
"@iconify-json/tdesign": "^1.1.6",
"@iconify-json/zondicons": "^1.1.8",
"@vitejs/plugin-vue": "^5.0.5",
Expand Down
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions utils/checkStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export async function checkStatus(
status: Ref<IStatus>,
isChecking: Ref<boolean>,
username: Ref<string>,
password: Ref<string>
password: Ref<string>,
isOnline: Ref<boolean>
) {
const baseURL = `http://localhost:${port.value}`;
const token = 'Basic ' + btoa(username.value + ':' + password.value);
Expand All @@ -23,14 +24,16 @@ export async function checkStatus(
},
onResponse({ request, response, options }) {
if (response.ok) {
notify({
title: '连接成功',
type: 'success',
position: 'bottom-left',
showClose: false,
duration: 1500,
});
// notify({
// title: '连接成功',
// type: 'success',
// position: 'bottom-left',
// showClose: false,
// duration: 1500,
// });
isOnline.value = true;
} else {
isOnline.value = false;
if (response.status == 401) {
// response.statusText,
notify({
Expand All @@ -42,6 +45,7 @@ export async function checkStatus(
}
},
async onRequestError({ error, request, response, options }) {
isOnline.value = false;
notify({
// + error.message,
title: '请检查端口号是否正确',
Expand Down
3 changes: 3 additions & 0 deletions utils/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ export { default as PhPencil } from '~icons/ph/pencil';
export { default as ZondiconsCopy } from '~icons/zondicons/copy';
export { default as LetsIconsSettingAltLine } from '~icons/lets-icons/setting-alt-line';
export { default as FluentDarkTheme24Filled } from '~icons/fluent/dark-theme-24-filled';
export { default as RiWifiFill } from '~icons/ri/wifi-fill';
export { default as SvgSpinnersWifi } from '~icons/svg-spinners/wifi';
export { default as MdiWifiOff } from '~icons/mdi/wifi-off';

0 comments on commit 4962936

Please sign in to comment.