1
0
mirror of https://github.com/lencx/ChatGPT.git synced 2024-10-01 01:06:13 -04:00
This commit is contained in:
lencx 2023-01-05 17:18:47 +08:00
commit a6e746d27e
10 changed files with 83 additions and 70 deletions

View File

@ -57,8 +57,8 @@ jobs:
- name: Install app dependencies and build it
run: yarn && yarn build:fe
- name: Rewrite tauri.conf.json
run: yarn fix:conf
# - name: Rewrite tauri.conf.json
# run: yarn fix:conf
- name: fix tray icon
if: matrix.platform != 'macos-latest'

View File

@ -16,7 +16,8 @@
## 📦 安装
[📝 更新日志](./UPDATE_LOG.md)
- [📝 更新日志](./UPDATE_LOG.md)
- [🕒 历史版本...](https://github.com/lencx/ChatGPT/releases)
<!-- download start -->
@ -24,8 +25,8 @@
- [ChatGPT_0.7.4_x64_en-US.msi](https://github.com/lencx/ChatGPT/releases/download/v0.7.4/ChatGPT_0.7.4_x64_en-US.msi)
- 或者使用 [winget](https://learn.microsoft.com/en-us/windows/package-manager/winget/):
- `winget install --id=lencx.ChatGPT -e`
- `winget install --id=lencx.ChatGPT -e --version 0.7.4`
- `winget install --id=lencx.ChatGPT -e`
- `winget install --id=lencx.ChatGPT -e --version 0.7.4`
**注意:如果安装路径和应用名称相同,会导致冲突 ([#142](https://github.com/lencx/ChatGPT/issues/142#issuecomment-1371166972))**
@ -50,6 +51,7 @@
- [chat-gpt_0.7.4_amd64.deb](https://github.com/lencx/ChatGPT/releases/download/v0.7.4/chat-gpt_0.7.4_amd64.deb)
- [chat-gpt_0.7.4_amd64.AppImage](https://github.com/lencx/ChatGPT/releases/download/v0.7.4/chat-gpt_0.7.4_amd64.AppImage): **工作可靠,`.deb` 运行失败时可以尝试它**
- [chatgpt-desktop-bin](https://aur.archlinux.org/packages/chatgpt-desktop-bin): 使用 AUR 来安装
<!-- download end -->
@ -134,7 +136,7 @@
目前同步自定文件仅支持 json 和 csv且需要满足以下格式否则会导致应用异常
> JSON 格式
`JSON 格式`
```json
[
@ -151,7 +153,7 @@
]
```
> CSV 格式
`CSV 格式`
```csv
"cmd","act","prompt"

View File

@ -19,7 +19,8 @@
## 📦 Install
[📝 Update Log](./UPDATE_LOG.md)
- [📝 Update Log](./UPDATE_LOG.md)
- [🕒 History versions...](https://github.com/lencx/ChatGPT/releases)
<!-- download start -->
@ -27,8 +28,8 @@
- From our github releases: [ChatGPT_0.7.4_x64_en-US.msi](https://github.com/lencx/ChatGPT/releases/download/v0.7.4/ChatGPT_0.7.4_x64_en-US.msi)
- Or install with [winget](https://learn.microsoft.com/en-us/windows/package-manager/winget/):
- `winget install --id=lencx.ChatGPT -e`
- `winget install --id=lencx.ChatGPT -e --version 0.7.4`
- `winget install --id=lencx.ChatGPT -e`
- `winget install --id=lencx.ChatGPT -e --version 0.7.4`
**Note: If the installation path and application name are the same, it will lead to conflict ([#142](https://github.com/lencx/ChatGPT/issues/142#issuecomment-1371166972))**
@ -53,8 +54,7 @@
- [chat-gpt_0.7.4_amd64.deb](https://github.com/lencx/ChatGPT/releases/download/v0.7.4/chat-gpt_0.7.4_amd64.deb)
- [chat-gpt_0.7.4_amd64.AppImage](https://github.com/lencx/ChatGPT/releases/download/v0.7.4/chat-gpt_0.7.4_amd64.AppImage): **works reliably, you can try it if `.deb` fails to run**
[History versions...](https://github.com/lencx/ChatGPT/releases)
- Available on [AUR](https://aur.archlinux.org/packages/chatgpt-desktop-bin) with the package name `chatgpt-desktop-bin`, and you can use your favourite AUR package manager to install it.
<!-- download end -->

View File

@ -5,7 +5,7 @@ use crate::{
};
use log::info;
use std::{collections::HashMap, fs, path::PathBuf};
use tauri::{api, command, AppHandle, Manager};
use tauri::{api, command, AppHandle, Manager, Theme};
use walkdir::WalkDir;
#[command]
@ -45,6 +45,11 @@ pub fn get_chat_conf() -> ChatConfJson {
ChatConfJson::get_chat_conf()
}
#[command]
pub fn get_theme() -> String {
ChatConfJson::theme().unwrap_or(Theme::Light).to_string()
}
#[command]
pub fn reset_chat_conf() -> ChatConfJson {
ChatConfJson::reset_chat_conf()

View File

@ -103,14 +103,13 @@ pub fn init() -> Menu {
update_silent.selected()
} else {
update_silent
})
// .add_item(if chat_conf.auto_update == "Disable" {
// update_disable.selected()
// } else {
// update_disable
// })
,
).into(),
}), // .add_item(if chat_conf.auto_update == "Disable" {
// update_disable.selected()
// } else {
// update_disable
// })
)
.into(),
stay_on_top_menu.into(),
#[cfg(target_os = "macos")]
titlebar_menu.into(),
@ -273,22 +272,31 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
ChatConfJson::amend(&serde_json::json!({ "theme": theme }), Some(app)).unwrap();
}
"update_prompt" | "update_silent" | "update_disable" => {
for id in ["update_prompt" , "update_silent" , "update_disable"] {
for id in ["update_prompt", "update_silent", "update_disable"] {
menu_handle.get_item(id).set_selected(false).unwrap();
}
let auto_update = match menu_id {
"update_silent" => {
menu_handle.get_item("update_silent").set_selected(true).unwrap();
menu_handle
.get_item("update_silent")
.set_selected(true)
.unwrap();
"Silent"
},
}
"update_disable" => {
menu_handle.get_item("update_disable").set_selected(true).unwrap();
menu_handle
.get_item("update_disable")
.set_selected(true)
.unwrap();
"Disable"
},
}
_ => {
menu_handle.get_item("update_prompt").set_selected(true).unwrap();
menu_handle
.get_item("update_prompt")
.set_selected(true)
.unwrap();
"Prompt"
},
}
};
ChatConfJson::amend(&serde_json::json!({ "auto_update": auto_update }), None).unwrap();
}

View File

@ -52,6 +52,7 @@ async fn main() {
cmd::download,
cmd::open_link,
cmd::get_chat_conf,
cmd::get_theme,
cmd::reset_chat_conf,
cmd::run_check_update,
cmd::form_cancel,

16
src/layout/index.scss vendored
View File

@ -1,16 +1,23 @@
.chat-logo {
text-align: center;
padding: 5px 0;
height: 48px;
img {
width: 48px;
height: 48px;
width: 44px;
height: 44px;
margin-top: 4px;
}
}
.chat-info {
text-align: center;
font-weight: bold;
.ant-tag {
margin: 2px;
}
}
.ant-layout-sider-trigger {
user-select: none;
-webkit-user-select: none;
@ -24,9 +31,6 @@
.ant-menu {
user-select: none;
-webkit-user-select: none;
.ant-menu-item {
background-color: #f8f8f8;
}
}
.ant-layout-footer {

39
src/layout/index.tsx vendored
View File

@ -1,5 +1,5 @@
import { FC, useState } from 'react';
import {Layout, Menu, Button, Tooltip, message} from 'antd';
import { useState } from 'react';
import {Layout, Menu, Tooltip, ConfigProvider, theme, Tag } from 'antd';
import { SyncOutlined } from '@ant-design/icons';
import { useNavigate, useLocation } from 'react-router-dom';
import { getName, getVersion } from '@tauri-apps/api/app';
@ -12,24 +12,22 @@ const { Content, Footer, Sider } = Layout;
const appName = await getName();
const appVersion = await getVersion();
const appTheme = await invoke("get_theme");
interface ChatLayoutProps {
children?: React.ReactNode;
}
const ChatLayout: FC<ChatLayoutProps> = ({ children }) => {
export default function ChatLayout() {
const [collapsed, setCollapsed] = useState(false);
const location = useLocation();
const go = useNavigate();
const checkAppUpdate = async () => {
await invoke('run_check_update', {silent: false});
await invoke('run_check_update', { silent: false });
}
return (
<ConfigProvider theme={{algorithm: appTheme === "dark" ? theme.darkAlgorithm : theme.defaultAlgorithm}}>
<Layout style={{ minHeight: '100vh' }} hasSider>
<Sider
theme="light"
theme={appTheme === "dark" ? "dark" : "light"}
collapsible
collapsed={collapsed}
onCollapse={(value) => setCollapsed(value)}
@ -45,21 +43,19 @@ const ChatLayout: FC<ChatLayoutProps> = ({ children }) => {
>
<div className="chat-logo"><img src="/logo.png" /></div>
<div className="chat-info">
<span>{appName}</span>
</div>
<div className="chat-info">
<span>{appVersion}</span>
<span> </span>
{
<Tooltip title="click to check update">
<a onClick={checkAppUpdate}><SyncOutlined /></a>
</Tooltip>
}
<Tag>{appName}</Tag>
<Tag>
<span style={{ marginRight: 5 }}>{appVersion}</span>
<Tooltip title="click to check update">
<a onClick={checkAppUpdate}><SyncOutlined /></a>
</Tooltip>
</Tag>
</div>
<Menu
defaultSelectedKeys={[location.pathname]}
mode="inline"
theme={ appTheme === "dark" ? "dark" : "light" }
inlineIndent={12}
items={menuItems}
defaultOpenKeys={['/model']}
@ -79,7 +75,6 @@ const ChatLayout: FC<ChatLayoutProps> = ({ children }) => {
<a href="https://github.com/lencx/chatgpt" target="_blank">ChatGPT Desktop Application</a> ©2022 Created by lencx</Footer>
</Layout>
</Layout>
</ConfigProvider>
);
};
export default ChatLayout;
};

2
src/main.scss vendored
View File

@ -63,7 +63,7 @@ html, body {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: #2a2a2a;
// color: #2a2a2a;
}
span {

24
src/view/General.tsx vendored
View File

@ -114,20 +114,23 @@ export default function General() {
labelCol={{ span: 8 }}
wrapperCol={{ span: 15, offset: 1 }}
>
<Form.Item label="Stay On Top" name="stay_on_top" valuePropName="checked">
<Switch />
</Form.Item>
{platformInfo === 'darwin' && (
<Form.Item label="Titlebar" name="titlebar" valuePropName="checked">
<Switch />
</Form.Item>
)}
<Form.Item label="Theme" name="theme">
<Radio.Group>
<Radio value="Light">Light</Radio>
<Radio value="Dark">Dark</Radio>
{
(["darwin", "windows"].includes(platformInfo) ) && (
<Radio value="System">System</Radio>
)
}
{["darwin", "windows"].includes(platformInfo) && (
<Radio value="System">System</Radio>
)}
</Radio.Group>
</Form.Item>
<Form.Item label="Stay On Top" name="stay_on_top" valuePropName="checked">
<Switch />
</Form.Item>
<Form.Item label={<AutoUpdateLabel />} name="auto_update">
<Radio.Group>
<Radio value="Prompt">Prompt</Radio>
@ -138,11 +141,6 @@ export default function General() {
<Form.Item label={<GlobalShortcut />} name="global_shortcut">
<Input placeholder="CmdOrCtrl+Shift+O" {...DISABLE_AUTO_COMPLETE} />
</Form.Item>
{platformInfo === 'darwin' && (
<Form.Item label="Titlebar" name="titlebar" valuePropName="checked">
<Switch />
</Form.Item>
)}
<Form.Item label={<OriginLabel url={chatConf?.default_origin} />} name="origin">
<Input placeholder="https://chat.openai.com" {...DISABLE_AUTO_COMPLETE} />
</Form.Item>