mirror of
https://github.com/koodo-reader/koodo-reader.git
synced 2026-10-08 13:53:02 -04:00
Remove chat box functionality and related methods from Header and common utilities
This commit is contained in:
1 parent
877c08a6f6
commit
0ba0a9769f
2 files changed
+37
-75
No files matched your search
@@ -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<HeaderProps, HeaderState> {
|
||||
_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<HeaderProps, HeaderState> {
|
||||
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<HeaderProps, HeaderState> {
|
||||
className="header"
|
||||
style={this.props.isCollapsed ? { marginLeft: "40px" } : {}}
|
||||
>
|
||||
{isElectron && this.props.isAuthed && (
|
||||
{this.props.isAuthed && (
|
||||
<div
|
||||
className="header-chat-widget"
|
||||
onClick={async () => {
|
||||
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
|
||||
);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<img
|
||||
|
||||
@@ -714,45 +714,6 @@ export const getChatLocale = () => {
|
||||
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];
|
||||
|
||||
Reference in new issue
Block a user