From 9bb3ec647c8390329dbc8a3134875f82a701c168 Mon Sep 17 00:00:00 2001 From: troyeguo <13820674+troyeguo@users.noreply.github.com> Date: Sun, 23 Aug 2026 11:22:03 +0800 Subject: [PATCH] feat: update service handling in PopupAssist and PopupTrans for authenticated users --- .../popups/popupAssist/component.tsx | 18 ++++++++++++------ src/components/popups/popupTrans/component.tsx | 16 +++++++++++----- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/components/popups/popupAssist/component.tsx b/src/components/popups/popupAssist/component.tsx index 20140078..b434660a 100644 --- a/src/components/popups/popupAssist/component.tsx +++ b/src/components/popups/popupAssist/component.tsx @@ -155,6 +155,12 @@ class PopupAssist extends React.Component { 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 { .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 { 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 { 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( diff --git a/src/components/popups/popupTrans/component.tsx b/src/components/popups/popupTrans/component.tsx index 23f94450..ab4b0840 100644 --- a/src/components/popups/popupTrans/component.tsx +++ b/src/components/popups/popupTrans/component.tsx @@ -69,6 +69,12 @@ class PopupTrans extends React.Component { }); 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 { 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 { ); 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,