Skip to content

Commit 4d9479b

Browse files
committed
feat: activate existing conversation window by default (#222)
1 parent 539b9a0 commit 4d9479b

File tree

6 files changed

+56
-25
lines changed

6 files changed

+56
-25
lines changed

src/_locales/en/main.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,6 @@
103103
"Max Response Token Length": "Max Response Token Length",
104104
"Max Conversation Length": "Max Conversation Length",
105105
"Always pin the floating window": "Always pin the floating window",
106-
"Export": "Export"
106+
"Export": "Export",
107+
"Always Create New Conversation Window": "Always Create New Conversation Window"
107108
}

src/_locales/zh-hans/main.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,6 @@
103103
"Max Response Token Length": "响应的最大token长度",
104104
"Max Conversation Length": "对话处理的最大长度",
105105
"Always pin the floating window": "总是固定浮动窗口",
106-
"Export": "导出"
106+
"Export": "导出",
107+
"Always Create New Conversation Window": "总是创建新的对话窗口"
107108
}

src/_locales/zh-hant/main.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@
9999
"Open Conversation Page": "開啟獨立對話頁",
100100
"Open Conversation Window": "開啟獨立對話視窗",
101101
"Store to Independent Conversation Page": "收納到獨立對話頁",
102-
"Keep Conversation Window in Background": "保持對話窗口在後臺, 以便在任何程序中使用快捷鍵呼出",
102+
"Keep Conversation Window in Background": "保持對話視窗在後臺, 以便在任何程序中使用快捷鍵呼出",
103103
"Max Response Token Length": "響應的最大token長度",
104104
"Max Conversation Length": "對話處理的最大長度",
105105
"Always pin the floating window": "總是固定浮動視窗",
106-
"Export": "導出"
106+
"Export": "導出",
107+
"Always Create New Conversation Window": "總是創建新的對話視窗"
107108
}

src/config/index.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export const defaultConfig = {
116116

117117
// others
118118

119+
alwaysCreateNewConversationWindow: false,
119120
activeSelectionTools: ['translate', 'summary', 'polish', 'code', 'ask'],
120121
activeSiteAdapters: [
121122
'bilibili',

src/content-script/menu-tools/index.mjs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getCoreContentText } from '../../utils/get-core-content-text'
22
import { openUrl } from '../../utils/open-url'
33
import Browser from 'webextension-polyfill'
4+
import { getUserConfig } from '../../config/index.mjs'
45

56
export const config = {
67
newChat: {
@@ -24,12 +25,18 @@ export const config = {
2425
openConversationWindow: {
2526
label: 'Open Conversation Window',
2627
action: async () => {
27-
Browser.windows.create({
28-
url: Browser.runtime.getURL('IndependentPanel.html'),
29-
type: 'popup',
30-
width: 500,
31-
height: 650,
32-
})
28+
const config = await getUserConfig()
29+
const url = Browser.runtime.getURL('IndependentPanel.html')
30+
const tabs = await Browser.tabs.query({ url: url, windowType: 'popup' })
31+
if (!config.alwaysCreateNewConversationWindow && tabs.length > 0)
32+
await Browser.windows.update(tabs[0].windowId, { focused: true })
33+
else
34+
await Browser.windows.create({
35+
url: url,
36+
type: 'popup',
37+
width: 500,
38+
height: 650,
39+
})
3340
},
3441
},
3542
}

src/popup/Popup.jsx

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ GeneralPart.propTypes = {
339339
updateConfig: PropTypes.func.isRequired,
340340
}
341341

342-
function FeaturePages() {
342+
function FeaturePages({ config, updateConfig }) {
343343
const { t } = useTranslation()
344344
const [backgroundPermission, setBackgroundPermission] = useState(false)
345345

@@ -369,19 +369,21 @@ function FeaturePages() {
369369
>
370370
{t('Open Conversation Page')}
371371
</button>
372-
<button
373-
type="button"
374-
onClick={() => {
375-
Browser.windows.create({
376-
url: Browser.runtime.getURL('IndependentPanel.html'),
377-
type: 'popup',
378-
width: 500,
379-
height: 650,
380-
})
381-
}}
382-
>
383-
{t('Open Conversation Window')}
384-
</button>
372+
{!isMobile() && (
373+
<button
374+
type="button"
375+
onClick={() => {
376+
Browser.windows.create({
377+
url: Browser.runtime.getURL('IndependentPanel.html'),
378+
type: 'popup',
379+
width: 500,
380+
height: 650,
381+
})
382+
}}
383+
>
384+
{t('Open Conversation Window')}
385+
</button>
386+
)}
385387
{!isMobile() && !isFirefox() && !isSafari() && (
386388
<label>
387389
<input
@@ -402,10 +404,28 @@ function FeaturePages() {
402404
{t('Keep Conversation Window in Background')}
403405
</label>
404406
)}
407+
{!isMobile() && (
408+
<label>
409+
<input
410+
type="checkbox"
411+
checked={config.alwaysCreateNewConversationWindow}
412+
onChange={(e) => {
413+
const checked = e.target.checked
414+
updateConfig({ alwaysCreateNewConversationWindow: checked })
415+
}}
416+
/>
417+
{t('Always Create New Conversation Window')}
418+
</label>
419+
)}
405420
</div>
406421
)
407422
}
408423

424+
FeaturePages.propTypes = {
425+
config: PropTypes.object.isRequired,
426+
updateConfig: PropTypes.func.isRequired,
427+
}
428+
409429
function AdvancedPart({ config, updateConfig }) {
410430
const { t } = useTranslation()
411431

@@ -703,7 +723,7 @@ function Popup() {
703723
<GeneralPart config={config} updateConfig={updateConfig} />
704724
</TabPanel>
705725
<TabPanel>
706-
<FeaturePages />
726+
<FeaturePages config={config} updateConfig={updateConfig} />
707727
</TabPanel>
708728
<TabPanel>
709729
<SelectionTools config={config} updateConfig={updateConfig} />

0 commit comments

Comments
 (0)