mirror of
https://github.com/koodo-reader/koodo-reader.git
synced 2026-10-07 13:22:17 -04:00
feat: update service handling in PopupAssist and PopupTrans for authenticated users
This commit is contained in:
1 parent
1cedef5380
commit
9bb3ec647c
2 files changed
+23
-11
No files matched your search
@@ -155,6 +155,12 @@ class PopupAssist extends React.Component<PopupAssistProps, PopupAssistState> {
|
||||
aiService: pluginList[0].key,
|
||||
});
|
||||
ConfigService.setReaderConfig("aiService", pluginList[0].key);
|
||||
} else if (this.props.isAuthed) {
|
||||
this.setState({
|
||||
aiService: "official-ai-assistant-plugin",
|
||||
isAddNew: false,
|
||||
});
|
||||
ConfigService.setReaderConfig("aiService", "official-ai-assistant-plugin");
|
||||
} else {
|
||||
this.setState({
|
||||
isAddNew: true,
|
||||
@@ -235,9 +241,9 @@ class PopupAssist extends React.Component<PopupAssistProps, PopupAssistState> {
|
||||
.trim()
|
||||
: "";
|
||||
if (
|
||||
(!this.state.aiService ||
|
||||
(!ConfigService.getReaderConfig("aiService") ||
|
||||
this.props.plugins.findIndex(
|
||||
(item) => item.key === this.state.aiService
|
||||
(item) => item.key === ConfigService.getReaderConfig("aiService")
|
||||
) === -1) &&
|
||||
!this.props.isAuthed
|
||||
) {
|
||||
@@ -251,8 +257,8 @@ class PopupAssist extends React.Component<PopupAssistProps, PopupAssistState> {
|
||||
handleDoAnswer = async (text: string) => {
|
||||
try {
|
||||
if (
|
||||
this.state.aiService &&
|
||||
this.state.aiService === "custom-ai-assistant-plugin"
|
||||
ConfigService.getReaderConfig("aiService") &&
|
||||
ConfigService.getReaderConfig("aiService") === "custom-ai-assistant-plugin"
|
||||
) {
|
||||
let plugin = this.props.plugins.find(
|
||||
(item) => item.key === "custom-ai-assistant-plugin"
|
||||
@@ -329,8 +335,8 @@ class PopupAssist extends React.Component<PopupAssistProps, PopupAssistState> {
|
||||
this.scrollToBottom();
|
||||
}
|
||||
} else if (
|
||||
this.state.aiService &&
|
||||
this.state.aiService !== "official-ai-assistant-plugin"
|
||||
ConfigService.getReaderConfig("aiService") &&
|
||||
ConfigService.getReaderConfig("aiService") !== "official-ai-assistant-plugin"
|
||||
) {
|
||||
} else if (this.props.isAuthed) {
|
||||
let plugin = this.props.plugins.find(
|
||||
|
||||
@@ -69,6 +69,12 @@ class PopupTrans extends React.Component<PopupTransProps, PopupTransState> {
|
||||
});
|
||||
ConfigService.setReaderConfig("transService", pluginList[0].key);
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
} else if (this.props.isAuthed) {
|
||||
this.setState({
|
||||
transService: "official-ai-trans-plugin",
|
||||
isAddNew: false,
|
||||
});
|
||||
ConfigService.setReaderConfig("transService", "official-ai-trans-plugin");
|
||||
} else {
|
||||
this.setState({
|
||||
isAddNew: true,
|
||||
@@ -81,12 +87,12 @@ class PopupTrans extends React.Component<PopupTransProps, PopupTransState> {
|
||||
|
||||
handleTrans = async (text: string) => {
|
||||
if (
|
||||
this.state.transService &&
|
||||
this.state.transService !== "official-ai-trans-plugin" &&
|
||||
this.state.transService !== "custom-ai-trans-plugin"
|
||||
ConfigService.getReaderConfig("transService") &&
|
||||
ConfigService.getReaderConfig("transService") !== "official-ai-trans-plugin" &&
|
||||
ConfigService.getReaderConfig("transService") !== "custom-ai-trans-plugin"
|
||||
) {
|
||||
let plugin = this.props.plugins.find(
|
||||
(item) => item.key === this.state.transService
|
||||
(item) => item.key === ConfigService.getReaderConfig("transService")
|
||||
);
|
||||
if (!plugin) {
|
||||
return;
|
||||
@@ -129,7 +135,7 @@ class PopupTrans extends React.Component<PopupTransProps, PopupTransState> {
|
||||
);
|
||||
console.error(err);
|
||||
});
|
||||
} else if (this.state.transService === "custom-ai-trans-plugin") {
|
||||
} else if (ConfigService.getReaderConfig("transService") === "custom-ai-trans-plugin") {
|
||||
this.setState({
|
||||
transService: "custom-ai-trans-plugin",
|
||||
isAddNew: false,
|
||||
|
||||
Reference in new issue
Block a user