@lobehub/chat 1.97.17 → 1.98.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/apps/desktop/package.json +8 -5
- package/apps/desktop/src/main/const/store.ts +12 -0
- package/apps/desktop/src/main/controllers/NetworkProxyCtr.ts +172 -0
- package/apps/desktop/src/main/controllers/__tests__/NetworkProxyCtr.test.ts +401 -0
- package/apps/desktop/src/main/core/Browser.ts +2 -0
- package/apps/desktop/src/main/modules/networkProxy/dispatcher.ts +116 -0
- package/apps/desktop/src/main/modules/networkProxy/index.ts +6 -0
- package/apps/desktop/src/main/modules/networkProxy/tester.ts +163 -0
- package/apps/desktop/src/main/modules/networkProxy/urlBuilder.ts +25 -0
- package/apps/desktop/src/main/modules/networkProxy/validator.ts +80 -0
- package/apps/desktop/src/main/types/store.ts +2 -1
- package/apps/desktop/src/main/utils/logger.ts +2 -1
- package/changelog/v1.json +9 -0
- package/locales/ar/electron.json +39 -0
- package/locales/ar/setting.json +1 -0
- package/locales/bg-BG/electron.json +39 -0
- package/locales/bg-BG/setting.json +1 -0
- package/locales/de-DE/electron.json +39 -0
- package/locales/de-DE/setting.json +1 -0
- package/locales/en-US/electron.json +39 -0
- package/locales/en-US/setting.json +1 -0
- package/locales/es-ES/electron.json +39 -0
- package/locales/es-ES/setting.json +1 -0
- package/locales/fa-IR/electron.json +39 -0
- package/locales/fa-IR/setting.json +1 -0
- package/locales/fr-FR/electron.json +39 -0
- package/locales/fr-FR/setting.json +1 -0
- package/locales/it-IT/electron.json +39 -0
- package/locales/it-IT/setting.json +1 -0
- package/locales/ja-JP/electron.json +39 -0
- package/locales/ja-JP/setting.json +1 -0
- package/locales/ko-KR/electron.json +39 -0
- package/locales/ko-KR/setting.json +1 -0
- package/locales/nl-NL/electron.json +39 -0
- package/locales/nl-NL/setting.json +1 -0
- package/locales/pl-PL/electron.json +39 -0
- package/locales/pl-PL/setting.json +1 -0
- package/locales/pt-BR/electron.json +39 -0
- package/locales/pt-BR/setting.json +1 -0
- package/locales/ru-RU/electron.json +39 -0
- package/locales/ru-RU/setting.json +1 -0
- package/locales/tr-TR/electron.json +39 -0
- package/locales/tr-TR/setting.json +1 -0
- package/locales/vi-VN/electron.json +39 -0
- package/locales/vi-VN/setting.json +1 -0
- package/locales/zh-CN/electron.json +39 -0
- package/locales/zh-CN/setting.json +1 -0
- package/locales/zh-TW/electron.json +39 -0
- package/locales/zh-TW/setting.json +1 -0
- package/package.json +3 -3
- package/packages/electron-client-ipc/src/events/index.ts +3 -1
- package/packages/electron-client-ipc/src/events/settings.ts +12 -0
- package/packages/electron-client-ipc/src/types/index.ts +1 -0
- package/packages/electron-client-ipc/src/types/proxy.ts +12 -0
- package/src/app/[variants]/(main)/settings/hooks/useCategory.tsx +11 -1
- package/src/app/[variants]/(main)/settings/proxy/features/ProxyForm.tsx +369 -0
- package/src/app/[variants]/(main)/settings/proxy/index.tsx +22 -0
- package/src/app/[variants]/(main)/settings/proxy/page.tsx +28 -0
- package/src/locales/default/electron.ts +39 -0
- package/src/locales/default/setting.ts +1 -0
- package/src/services/electron/settings.ts +33 -0
- package/src/store/electron/actions/settings.ts +55 -0
- package/src/store/electron/initialState.ts +12 -1
- package/src/store/electron/selectors/__tests__/desktopState.test.ts +3 -1
- package/src/store/electron/store.ts +4 -1
- package/src/store/global/initialState.ts +1 -0
- package/apps/desktop/scripts/pglite-server.ts +0 -14
@@ -0,0 +1,28 @@
|
|
1
|
+
import { notFound } from 'next/navigation';
|
2
|
+
|
3
|
+
import { isDesktop } from '@/const/version';
|
4
|
+
import { metadataModule } from '@/server/metadata';
|
5
|
+
import { translation } from '@/server/translation';
|
6
|
+
import { DynamicLayoutProps } from '@/types/next';
|
7
|
+
import { RouteVariants } from '@/utils/server/routeVariants';
|
8
|
+
|
9
|
+
import Client from './index';
|
10
|
+
|
11
|
+
export const generateMetadata = async (props: DynamicLayoutProps) => {
|
12
|
+
const locale = await RouteVariants.getLocale(props);
|
13
|
+
const { t } = await translation('setting', locale);
|
14
|
+
|
15
|
+
return metadataModule.generate({
|
16
|
+
description: t('header.desc'),
|
17
|
+
title: t('tab.proxy'),
|
18
|
+
url: '/settings/proxy',
|
19
|
+
});
|
20
|
+
};
|
21
|
+
|
22
|
+
const Page = () => {
|
23
|
+
if (!isDesktop) return notFound();
|
24
|
+
|
25
|
+
return <Client />;
|
26
|
+
};
|
27
|
+
|
28
|
+
export default Page;
|
@@ -1,4 +1,43 @@
|
|
1
1
|
const electron = {
|
2
|
+
proxy: {
|
3
|
+
auth: '需要认证',
|
4
|
+
authDesc: '如果代理服务器需要用户名和密码',
|
5
|
+
authSettings: '认证设置',
|
6
|
+
basicSettings: '代理设置',
|
7
|
+
basicSettingsDesc: '配置代理服务器的连接参数',
|
8
|
+
bypass: '不使用代理的地址',
|
9
|
+
connectionTest: '连接测试',
|
10
|
+
enable: '启用代理',
|
11
|
+
enableDesc: '开启后将通过代理服务器访问网络',
|
12
|
+
password: '密码',
|
13
|
+
password_placeholder: '请输入密码',
|
14
|
+
port: '端口',
|
15
|
+
resetButton: '重置',
|
16
|
+
saveButton: '保存',
|
17
|
+
saveFailed: '保存失败:{{error}}',
|
18
|
+
saveSuccess: '代理设置保存成功',
|
19
|
+
server: '服务器地址',
|
20
|
+
testButton: '测试连接',
|
21
|
+
testDescription: '使用当前代理配置测试连接,验证配置是否正常工作',
|
22
|
+
testFailed: '连接失败',
|
23
|
+
testSuccessWithTime: '测试连接成功,耗时 {{time}} ms',
|
24
|
+
testUrl: '测试地址',
|
25
|
+
testUrlPlaceholder: '请输入要测试的 URL',
|
26
|
+
testing: '正在测试连接...',
|
27
|
+
type: '代理类型',
|
28
|
+
unsavedChanges: '您有未保存的更改',
|
29
|
+
username: '用户名',
|
30
|
+
username_placeholder: '请输入用户名',
|
31
|
+
validation: {
|
32
|
+
passwordRequired: '启用认证时密码为必填项',
|
33
|
+
portInvalid: '端口必须是 1 到 65535 之间的数字',
|
34
|
+
portRequired: '启用代理时端口为必填项',
|
35
|
+
serverInvalid: '请输入有效的服务器地址(IP 或域名)',
|
36
|
+
serverRequired: '启用代理时服务器地址为必填项',
|
37
|
+
typeRequired: '启用代理时代理类型为必填项',
|
38
|
+
usernameRequired: '启用认证时用户名为必填项',
|
39
|
+
},
|
40
|
+
},
|
2
41
|
remoteServer: {
|
3
42
|
authError: '授权失败: {{error}}',
|
4
43
|
authPending: '请在浏览器中完成授权',
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import { NetworkProxySettings, dispatch } from '@lobechat/electron-client-ipc';
|
2
|
+
|
3
|
+
class DesktopSettingsService {
|
4
|
+
/**
|
5
|
+
* 获取远程服务器配置
|
6
|
+
*/
|
7
|
+
getProxySettings = async () => {
|
8
|
+
return dispatch('getProxySettings');
|
9
|
+
};
|
10
|
+
|
11
|
+
/**
|
12
|
+
* 设置远程服务器配置
|
13
|
+
*/
|
14
|
+
setSettings = async (data: Partial<NetworkProxySettings>) => {
|
15
|
+
return dispatch('setProxySettings', data);
|
16
|
+
};
|
17
|
+
|
18
|
+
/**
|
19
|
+
* 测试代理连接
|
20
|
+
*/
|
21
|
+
testProxyConnection = async (url: string) => {
|
22
|
+
return dispatch('testProxyConnection', url);
|
23
|
+
};
|
24
|
+
|
25
|
+
/**
|
26
|
+
* 测试指定的代理配置
|
27
|
+
*/
|
28
|
+
testProxyConfig = async (config: NetworkProxySettings, testUrl?: string) => {
|
29
|
+
return dispatch('testProxyConfig', { config, testUrl });
|
30
|
+
};
|
31
|
+
}
|
32
|
+
|
33
|
+
export const desktopSettingsService = new DesktopSettingsService();
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { NetworkProxySettings } from '@lobechat/electron-client-ipc';
|
2
|
+
import isEqual from 'fast-deep-equal';
|
3
|
+
import useSWR, { SWRResponse, mutate } from 'swr';
|
4
|
+
import type { StateCreator } from 'zustand/vanilla';
|
5
|
+
|
6
|
+
import { desktopSettingsService } from '@/services/electron/settings';
|
7
|
+
|
8
|
+
import type { ElectronStore } from '../store';
|
9
|
+
|
10
|
+
/**
|
11
|
+
* 设置操作
|
12
|
+
*/
|
13
|
+
export interface ElectronSettingsAction {
|
14
|
+
refreshProxySettings: () => Promise<void>;
|
15
|
+
setProxySettings: (params: Partial<NetworkProxySettings>) => Promise<void>;
|
16
|
+
useGetProxySettings: () => SWRResponse;
|
17
|
+
}
|
18
|
+
|
19
|
+
const ELECTRON_PROXY_SETTINGS_KEY = 'electron:getProxySettings';
|
20
|
+
|
21
|
+
export const settingsSlice: StateCreator<
|
22
|
+
ElectronStore,
|
23
|
+
[['zustand/devtools', never]],
|
24
|
+
[],
|
25
|
+
ElectronSettingsAction
|
26
|
+
> = (set, get) => ({
|
27
|
+
refreshProxySettings: async () => {
|
28
|
+
await mutate(ELECTRON_PROXY_SETTINGS_KEY);
|
29
|
+
},
|
30
|
+
|
31
|
+
setProxySettings: async (values) => {
|
32
|
+
try {
|
33
|
+
// 更新设置
|
34
|
+
await desktopSettingsService.setSettings(values);
|
35
|
+
|
36
|
+
// 刷新状态
|
37
|
+
await get().refreshProxySettings();
|
38
|
+
} catch (error) {
|
39
|
+
console.error('代理设置更新失败:', error);
|
40
|
+
}
|
41
|
+
},
|
42
|
+
|
43
|
+
useGetProxySettings: () =>
|
44
|
+
useSWR<NetworkProxySettings>(
|
45
|
+
ELECTRON_PROXY_SETTINGS_KEY,
|
46
|
+
async () => desktopSettingsService.getProxySettings(),
|
47
|
+
{
|
48
|
+
onSuccess: (data) => {
|
49
|
+
if (!isEqual(data, get().proxySettings)) {
|
50
|
+
set({ proxySettings: data });
|
51
|
+
}
|
52
|
+
},
|
53
|
+
},
|
54
|
+
),
|
55
|
+
});
|
@@ -1,7 +1,16 @@
|
|
1
|
-
import { DataSyncConfig, ElectronAppState } from '@lobechat/electron-client-ipc';
|
1
|
+
import { DataSyncConfig, ElectronAppState, NetworkProxySettings } from '@lobechat/electron-client-ipc';
|
2
2
|
|
3
3
|
export type RemoteServerError = 'CONFIG_ERROR' | 'AUTH_ERROR' | 'DISCONNECT_ERROR';
|
4
4
|
|
5
|
+
export const defaultProxySettings: NetworkProxySettings = {
|
6
|
+
enableProxy: false,
|
7
|
+
proxyBypass: 'localhost, 127.0.0.1, ::1',
|
8
|
+
proxyPort: '',
|
9
|
+
proxyRequireAuth: false,
|
10
|
+
proxyServer: '',
|
11
|
+
proxyType: 'http',
|
12
|
+
};
|
13
|
+
|
5
14
|
export interface ElectronState {
|
6
15
|
appState: ElectronAppState;
|
7
16
|
dataSyncConfig: DataSyncConfig;
|
@@ -9,6 +18,7 @@ export interface ElectronState {
|
|
9
18
|
isConnectingServer?: boolean;
|
10
19
|
isInitRemoteServerConfig: boolean;
|
11
20
|
isSyncActive?: boolean;
|
21
|
+
proxySettings: NetworkProxySettings;
|
12
22
|
remoteServerSyncError?: { message?: string; type: RemoteServerError };
|
13
23
|
}
|
14
24
|
|
@@ -19,4 +29,5 @@ export const initialState: ElectronState = {
|
|
19
29
|
isConnectingServer: false,
|
20
30
|
isInitRemoteServerConfig: false,
|
21
31
|
isSyncActive: false,
|
32
|
+
proxySettings: defaultProxySettings,
|
22
33
|
};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
2
2
|
|
3
|
-
import { ElectronState } from '@/store/electron/initialState';
|
3
|
+
import { ElectronState, defaultProxySettings } from '@/store/electron/initialState';
|
4
4
|
|
5
5
|
import { desktopStateSelectors } from '../desktopState';
|
6
6
|
|
@@ -25,6 +25,7 @@ describe('desktopStateSelectors', () => {
|
|
25
25
|
storageMode: 'local',
|
26
26
|
},
|
27
27
|
isInitRemoteServerConfig: false,
|
28
|
+
proxySettings: defaultProxySettings,
|
28
29
|
};
|
29
30
|
|
30
31
|
expect(desktopStateSelectors.usePath(state)).toEqual({
|
@@ -47,6 +48,7 @@ describe('desktopStateSelectors', () => {
|
|
47
48
|
storageMode: 'local',
|
48
49
|
},
|
49
50
|
isInitRemoteServerConfig: false,
|
51
|
+
proxySettings: defaultProxySettings,
|
50
52
|
};
|
51
53
|
|
52
54
|
expect(desktopStateSelectors.usePath(state)).toBeUndefined();
|
@@ -4,6 +4,7 @@ import { StateCreator } from 'zustand/vanilla';
|
|
4
4
|
|
5
5
|
import { createDevtools } from '../middleware/createDevtools';
|
6
6
|
import { type ElectronAppAction, createElectronAppSlice } from './actions/app';
|
7
|
+
import { type ElectronSettingsAction, settingsSlice } from './actions/settings';
|
7
8
|
import { type ElectronRemoteServerAction, remoteSyncSlice } from './actions/sync';
|
8
9
|
import { type ElectronState, initialState } from './initialState';
|
9
10
|
|
@@ -12,7 +13,8 @@ import { type ElectronState, initialState } from './initialState';
|
|
12
13
|
export interface ElectronStore
|
13
14
|
extends ElectronState,
|
14
15
|
ElectronRemoteServerAction,
|
15
|
-
ElectronAppAction
|
16
|
+
ElectronAppAction,
|
17
|
+
ElectronSettingsAction {
|
16
18
|
/* empty */
|
17
19
|
}
|
18
20
|
|
@@ -22,6 +24,7 @@ const createStore: StateCreator<ElectronStore, [['zustand/devtools', never]]> =
|
|
22
24
|
...initialState,
|
23
25
|
...remoteSyncSlice(...parameters),
|
24
26
|
...createElectronAppSlice(...parameters),
|
27
|
+
...settingsSlice(...parameters),
|
25
28
|
});
|
26
29
|
|
27
30
|
// =============== 实装 useStore ============ //
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import { PGlite } from "@electric-sql/pglite";
|
2
|
-
import { createServer } from "pglite-server";
|
3
|
-
|
4
|
-
// 创建或连接到您现有的 PGlite 数据库
|
5
|
-
const db = new PGlite("/Users/arvinxx/Library/Application Support/lobehub-desktop/lobehub-local-db");
|
6
|
-
await db.waitReady;
|
7
|
-
|
8
|
-
// 创建服务器并监听端口
|
9
|
-
const PORT = 6543;
|
10
|
-
const pgServer = createServer(db);
|
11
|
-
|
12
|
-
pgServer.listen(PORT, () => {
|
13
|
-
console.log(`PGlite 服务器已启动,监听端口 ${PORT}`);
|
14
|
-
});
|