From 9551dde7160f83f86a907014594c236db416a54c Mon Sep 17 00:00:00 2001
From: HenryC-3 <2324375439@qq.com>
Date: Fri, 3 Mar 2023 10:55:14 +0800
Subject: [PATCH] snapshot: relate
https://github.com/vuejs/language-tools/issues/1815
---
README.md | 21 +++------------------
src/background.ts | 32 ++++++++++++++++++++++++--------
src/components/AddBookPage.vue | 7 ++++++-
src/message.ts | 24 ++++++++++++++++++++++++
src/types.ts | 5 +++++
tsconfig.json | 8 +-------
6 files changed, 63 insertions(+), 34 deletions(-)
create mode 100644 src/message.ts
diff --git a/README.md b/README.md
index ef72fd5..c18f232 100644
--- a/README.md
+++ b/README.md
@@ -1,18 +1,3 @@
-# Vue 3 + TypeScript + Vite
-
-This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `
diff --git a/src/message.ts b/src/message.ts
new file mode 100644
index 0000000..ef7235e
--- /dev/null
+++ b/src/message.ts
@@ -0,0 +1,24 @@
+export const { sendTriggered, watchTriggered } = getMessenger("triggered");
+
+type MessageType =
+ | "wrongPage" // current page doesn't match https://book.douban.com/subject/27594044/
+ | "ready" // content script has collected book information
+ | "triggered" // user triggers the save book button
+ | "failed" // background script fails to send the book to notion
+ | "success" // background script sends the book to notion successfully
+ | "duplicate"; // background scripts detects a duplicate book in notion
+
+function getMessenger(type: MessageType) {
+ return {
+ ["send" + type.toUpperCase()]: (data: T) => {
+ chrome.runtime.sendMessage({ type, data });
+ },
+ ["watch" + type.toUpperCase()]: (action: (data: T) => void) => {
+ chrome.runtime.onMessage.addListener((message) => {
+ if (message.type === type) {
+ action(message.data);
+ }
+ });
+ },
+ };
+}
diff --git a/src/types.ts b/src/types.ts
index d069053..67f09ae 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -12,3 +12,8 @@ export interface Book {
ratingCount: number; // 评价人数
cover: string;
}
+
+export interface BackgroundRes {
+ success: boolean;
+ error?: Error;
+}
diff --git a/tsconfig.json b/tsconfig.json
index 5ff65d3..3ccd35b 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -14,12 +14,6 @@
"skipLibCheck": true,
"noEmit": true
},
- "include": [
- "src/**/*.ts",
- "src/**/*.d.ts",
- "src/**/*.tsx",
- "src/**/*.vue",
- "src/**.ts"
- ],
+ "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.vite.json" }]
}