feat: add a startup switch for quick assistant
This commit is contained in:
@@ -387,7 +387,9 @@
|
||||
},
|
||||
"quickAssistant": {
|
||||
"title": "Quick Assistant",
|
||||
"click_tray_to_show": "Click the system tray icon to open"
|
||||
"click_tray_to_show": "Click the tray icon to start",
|
||||
"enable_quick_assistant": "Enable Quick Assistant",
|
||||
"use_shortcut_to_show": "Right-click the tray icon or use shortcuts to start"
|
||||
},
|
||||
"display.title": "Display Settings",
|
||||
"font_size.title": "Message font size",
|
||||
|
||||
@@ -385,7 +385,9 @@
|
||||
},
|
||||
"quickAssistant": {
|
||||
"title": "クイックアシスタント",
|
||||
"click_tray_to_show": "システムトレイアイコンをクリックして開く"
|
||||
"click_tray_to_show": "トレイアイコンをクリックして起動",
|
||||
"enable_quick_assistant": "クイックアシスタントを有効にする",
|
||||
"use_shortcut_to_show": "トレイアイコンを右クリックするか、ショートカットキーで起動できます"
|
||||
},
|
||||
"display.title": "表示設定",
|
||||
"font_size.title": "メッセージのフォントサイズ",
|
||||
|
||||
@@ -387,7 +387,9 @@
|
||||
},
|
||||
"quickAssistant": {
|
||||
"title": "Быстрый помощник",
|
||||
"click_tray_to_show": "Нажмите на иконку системного трея для открытия"
|
||||
"click_tray_to_show": "Нажмите на иконку трея для запуска",
|
||||
"enable_quick_assistant": "Включить быстрый помощник",
|
||||
"use_shortcut_to_show": "Нажмите на иконку трея или используйте горячие клавиши для запуска"
|
||||
},
|
||||
"display.title": "Настройки отображения",
|
||||
"font_size.title": "Размер шрифта сообщений",
|
||||
|
||||
@@ -388,7 +388,9 @@
|
||||
},
|
||||
"quickAssistant": {
|
||||
"title": "快捷助手",
|
||||
"click_tray_to_show": "点击系统托盘图标打开"
|
||||
"click_tray_to_show": "点击托盘图标启动",
|
||||
"enable_quick_assistant": "启用快捷助手",
|
||||
"use_shortcut_to_show": "右键点击托盘图标或使用快捷键启动"
|
||||
},
|
||||
"display.title": "显示设置",
|
||||
"font_size.title": "消息字体大小",
|
||||
|
||||
@@ -387,7 +387,9 @@
|
||||
},
|
||||
"quickAssistant": {
|
||||
"title": "快捷助手",
|
||||
"click_tray_to_show": "點擊系統托盤圖標打開"
|
||||
"click_tray_to_show": "點擊托盤圖標啟動",
|
||||
"enable_quick_assistant": "啟用快捷助手",
|
||||
"use_shortcut_to_show": "右鍵點擊托盤圖標或使用快捷鍵啟動"
|
||||
},
|
||||
"display.title": "顯示設定",
|
||||
"font_size.title": "訊息字體大小",
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { InfoCircleOutlined } from '@ant-design/icons'
|
||||
import { useTheme } from '@renderer/context/ThemeProvider'
|
||||
import { useSettings } from '@renderer/hooks/useSettings'
|
||||
import { useAppDispatch } from '@renderer/store'
|
||||
import { setClickTrayToShowQuickAssistant } from '@renderer/store/settings'
|
||||
import { setClickTrayToShowQuickAssistant, setEnableQuickAssistant } from '@renderer/store/settings'
|
||||
import HomeWindow from '@renderer/windows/mini/home/HomeWindow'
|
||||
import { Switch } from 'antd'
|
||||
import { Switch, Tooltip } from 'antd'
|
||||
import { FC } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import styled from 'styled-components'
|
||||
@@ -13,9 +14,26 @@ import { SettingContainer, SettingDivider, SettingGroup, SettingRow, SettingRowT
|
||||
const QuickAssistantSettings: FC = () => {
|
||||
const { t } = useTranslation()
|
||||
const { theme } = useTheme()
|
||||
const { clickTrayToShowQuickAssistant, setTray } = useSettings()
|
||||
const { enableQuickAssistant, clickTrayToShowQuickAssistant, setTray } = useSettings()
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
const handleEnableQuickAssistant = async (enable: boolean) => {
|
||||
dispatch(setEnableQuickAssistant(enable))
|
||||
await window.api.config.set('enableQuickAssistant', enable)
|
||||
window.api.restartTray()
|
||||
const disable = !enable
|
||||
disable && window.api.miniWindow.close()
|
||||
|
||||
if (enable && !clickTrayToShowQuickAssistant) {
|
||||
window.message.info({
|
||||
content: t('settings.quickAssistant.use_shortcut_to_show'),
|
||||
duration: 4,
|
||||
icon: <InfoCircleOutlined />,
|
||||
key: 'quick-assistant-info'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const handleClickTrayToShowQuickAssistant = async (checked: boolean) => {
|
||||
dispatch(setClickTrayToShowQuickAssistant(checked))
|
||||
await window.api.config.set('clickTrayToShowQuickAssistant', checked)
|
||||
@@ -31,13 +49,29 @@ const QuickAssistantSettings: FC = () => {
|
||||
<SettingTitle>{t('settings.quickAssistant.title')}</SettingTitle>
|
||||
<SettingDivider />
|
||||
<SettingRow>
|
||||
<SettingRowTitle>{t('settings.quickAssistant.click_tray_to_show')}</SettingRowTitle>
|
||||
<Switch checked={clickTrayToShowQuickAssistant} onChange={handleClickTrayToShowQuickAssistant} />
|
||||
<SettingRowTitle style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
|
||||
<span>{t('settings.quickAssistant.enable_quick_assistant')}</span>
|
||||
<Tooltip title={t('settings.quickAssistant.use_shortcut_to_show')} placement="right">
|
||||
<InfoCircleOutlined style={{ cursor: 'pointer' }} />
|
||||
</Tooltip>
|
||||
</SettingRowTitle>
|
||||
<Switch checked={enableQuickAssistant} onChange={handleEnableQuickAssistant} />
|
||||
</SettingRow>
|
||||
{enableQuickAssistant && (
|
||||
<>
|
||||
<SettingDivider />
|
||||
<SettingRow>
|
||||
<SettingRowTitle>{t('settings.quickAssistant.click_tray_to_show')}</SettingRowTitle>
|
||||
<Switch checked={clickTrayToShowQuickAssistant} onChange={handleClickTrayToShowQuickAssistant} />
|
||||
</SettingRow>
|
||||
</>
|
||||
)}
|
||||
</SettingGroup>
|
||||
<AssistantContainer onClick={() => {}}>
|
||||
<HomeWindow />
|
||||
</AssistantContainer>
|
||||
{enableQuickAssistant && (
|
||||
<AssistantContainer>
|
||||
<HomeWindow />
|
||||
</AssistantContainer>
|
||||
)}
|
||||
</SettingContainer>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -846,6 +846,8 @@ const migrateConfig = {
|
||||
}
|
||||
})
|
||||
|
||||
state.settings.enableQuickAssistant = false
|
||||
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ export interface SettingsState {
|
||||
disabled: SidebarIcon[]
|
||||
}
|
||||
narrowMode: boolean
|
||||
enableQuickAssistant: boolean
|
||||
clickTrayToShowQuickAssistant: boolean
|
||||
}
|
||||
|
||||
@@ -107,6 +108,7 @@ const initialState: SettingsState = {
|
||||
disabled: []
|
||||
},
|
||||
narrowMode: false,
|
||||
enableQuickAssistant: false,
|
||||
clickTrayToShowQuickAssistant: false
|
||||
}
|
||||
|
||||
@@ -245,6 +247,9 @@ const settingsSlice = createSlice({
|
||||
},
|
||||
setClickTrayToShowQuickAssistant: (state, action: PayloadAction<boolean>) => {
|
||||
state.clickTrayToShowQuickAssistant = action.payload
|
||||
},
|
||||
setEnableQuickAssistant: (state, action: PayloadAction<boolean>) => {
|
||||
state.enableQuickAssistant = action.payload
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -291,7 +296,8 @@ export const {
|
||||
setTopicNamingPrompt,
|
||||
setSidebarIcons,
|
||||
setNarrowMode,
|
||||
setClickTrayToShowQuickAssistant
|
||||
setClickTrayToShowQuickAssistant,
|
||||
setEnableQuickAssistant
|
||||
} = settingsSlice.actions
|
||||
|
||||
export default settingsSlice.reducer
|
||||
|
||||
@@ -34,8 +34,6 @@ const HomeWindow: FC = () => {
|
||||
|
||||
textRef.current = `${referenceText}\n\n${text}`
|
||||
|
||||
const isMiniWindow = window.location.hash === '#/mini'
|
||||
|
||||
const onReadClipboard = useCallback(async () => {
|
||||
const text = await navigator.clipboard.readText()
|
||||
setClipboardText(text.trim())
|
||||
@@ -49,7 +47,7 @@ const HomeWindow: FC = () => {
|
||||
i18n.changeLanguage(language || navigator.language || 'en-US')
|
||||
}, [language])
|
||||
|
||||
const onCloseWindow = () => isMiniWindow && window.close()
|
||||
const onCloseWindow = () => window.api.miniWindow.hide()
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
if (e.key === 'Escape') {
|
||||
|
||||
Reference in New Issue
Block a user