diff --git a/src/containers/header/component.tsx b/src/containers/header/component.tsx index 84e13f36..2bb0d2d2 100644 --- a/src/containers/header/component.tsx +++ b/src/containers/header/component.tsx @@ -26,7 +26,6 @@ import DatabaseService from "../../utils/storage/databaseService"; import CoverUtil from "../../utils/file/coverUtil"; import BookUtil from "../../utils/file/bookUtil"; import { - addChatBox, checkBrokenDatabase, checkMissingBook, generateSyncRecord, @@ -35,7 +34,6 @@ import { getTaskStats, getWebsiteUrl, openInBrowser, - removeChatBox, resetKoodoSync, showTaskProgress, throttle, @@ -256,22 +254,18 @@ class Header extends React.Component { _nextContext: any ) { if (nextProps.isAuthed && nextProps.isAuthed !== this.props.isAuthed) { - if (isElectron) { - if (ConfigService.getReaderConfig("isAllowNotification") === "yes") { - getNotification().then((res) => { - if ( - res.data && - res.data.result === "ok" && - res.data.unread && - res.data.unread > 0 - ) { - this.setState({ notificationCount: res.data.unread }); - ConfigService.setReaderConfig("isAllowNotification", "no"); - } - }); - } - } else { - addChatBox(); + if (ConfigService.getReaderConfig("isAllowNotification") === "yes") { + getNotification().then((res) => { + if ( + res.data && + res.data.result === "ok" && + res.data.unread && + res.data.unread > 0 + ) { + this.setState({ notificationCount: res.data.unread }); + ConfigService.setReaderConfig("isAllowNotification", "no"); + } + }); } if (ConfigService.getReaderConfig("isProUpgraded") !== "yes") { try { @@ -291,12 +285,6 @@ class Header extends React.Component { await this.handleOpenLastReadBook(); } } - if (!nextProps.isAuthed && nextProps.isAuthed !== this.props.isAuthed) { - if (isElectron) { - } else { - removeChatBox(); - } - } } handleOpenLastReadBook = async () => { let filePath = ""; @@ -689,24 +677,37 @@ class Header extends React.Component { className="header" style={this.props.isCollapsed ? { marginLeft: "40px" } : {}} > - {isElectron && this.props.isAuthed && ( + {this.props.isAuthed && (
{ this.setState({ notificationCount: 0 }); let deviceUuid = await TokenService.getFingerprint(); - window.require("electron").ipcRenderer.invoke("new-chat", { - url: + if (isElectron) { + window.require("electron").ipcRenderer.invoke("new-chat", { + url: + getWebsiteUrl() + + (ConfigService.getReaderConfig("lang").startsWith("zh") + ? "/zh/faq" + : "/en/faq") + + "?referer=app&version=" + + packageJson.version + + "&client=desktop&device=" + + deviceUuid, + locale: getChatLocale(), + }); + } else { + openInBrowser( getWebsiteUrl() + - (ConfigService.getReaderConfig("lang").startsWith("zh") - ? "/zh/faq" - : "/en/faq") + - "?referer=app&version=" + - packageJson.version + - "&client=desktop&device=" + - deviceUuid, - locale: getChatLocale(), - }); + (ConfigService.getReaderConfig("lang").startsWith("zh") + ? "/zh/faq" + : "/en/faq") + + "?referer=app&version=" + + packageJson.version + + "&client=web&device=" + + deviceUuid + ); + } }} > { return "en"; } }; -export async function addChatBox() { - let deviceUuid = await TokenService.getFingerprint(); - const scriptContent = ` - (function (d, t) { - var BASE_URL = "https://app.chatwoot.com"; - var g = d.createElement(t), - s = d.getElementsByTagName(t)[0]; - g.src = BASE_URL + "/packs/js/sdk.js"; - g.defer = true; - g.async = true; - s.parentNode.insertBefore(g, s); - g.onload = function () { - window.chatwootSDK.run({ - websiteToken: "svaD5wxfU5UY1r5ZzpMtLqv2", - baseUrl: BASE_URL, - }); - window.addEventListener('chatwoot:ready', function() { - window.$chatwoot.setLocale('${getChatLocale()}'); - window.$chatwoot.setCustomAttributes({ - version: '${packageJson.version}', - client: 'web', - device: '${deviceUuid}', - }); - }); - }; - })(document, "script"); - `; - - const scriptElement = document.createElement("script"); - scriptElement.type = "text/javascript"; - scriptElement.text = scriptContent; - document.head.appendChild(scriptElement); -} -export function removeChatBox() { - const scriptElement = document.querySelector("script[src*='chatwoot']"); - if (scriptElement) { - scriptElement.remove(); - } -} export const preCacheAllBooks = async (bookList: Book[]) => { for (let index = 0; index < bookList.length; index++) { const selectedBook = bookList[index];