134dd063c3
- Implemented Dongchedi adapter for user detection and publishing. - Implemented Jianshu adapter for user detection and publishing. - Implemented Juejin adapter for user detection and publishing. - Implemented Qiehao adapter for user detection and publishing. - Implemented Smzdm adapter for user detection and publishing. - Implemented Sohuhao adapter for user detection and publishing. - Implemented Toutiaohao adapter for user detection and publishing. - Implemented Wangyihao adapter for user detection and publishing. - Implemented Weixin Gzh adapter for user detection and publishing. - Implemented Zol adapter for user detection and publishing. - Added documentation for manual testing of media publishing.
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
import { browser } from "wxt/browser";
|
|
import { defineBackground } from "wxt/utils/define-background";
|
|
|
|
import { handlePublisherAction } from "../src/runtime";
|
|
import { getExtensionState } from "../src/storage";
|
|
|
|
type BackgroundSuccessResponse = {
|
|
ok: true;
|
|
data: Awaited<ReturnType<typeof handlePublisherAction>>;
|
|
};
|
|
|
|
type BackgroundErrorResponse = {
|
|
ok: false;
|
|
error: string;
|
|
};
|
|
|
|
export default defineBackground(() => {
|
|
void getExtensionState();
|
|
|
|
browser.runtime.onInstalled.addListener(() => {
|
|
void getExtensionState();
|
|
browser.alarms.create("geo.publisher.background-heartbeat", {
|
|
periodInMinutes: 60,
|
|
});
|
|
});
|
|
|
|
browser.alarms.onAlarm.addListener(async (alarm) => {
|
|
if (alarm.name !== "geo.publisher.background-heartbeat") {
|
|
return;
|
|
}
|
|
await getExtensionState();
|
|
});
|
|
|
|
chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
|
|
if (!message || message.type !== "geo.publisher.request") {
|
|
return undefined;
|
|
}
|
|
|
|
void handlePublisherAction(message.action, message.payload)
|
|
.then((data) => {
|
|
sendResponse({
|
|
ok: true,
|
|
data,
|
|
} satisfies BackgroundSuccessResponse);
|
|
})
|
|
.catch((error: unknown) => {
|
|
sendResponse({
|
|
ok: false,
|
|
error: error instanceof Error ? error.message : "publisher_plugin_unknown_error",
|
|
} satisfies BackgroundErrorResponse);
|
|
});
|
|
|
|
return true;
|
|
});
|
|
});
|