@lobehub/lobehub 2.0.0-next.242 → 2.0.0-next.244
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/.cursor/rules/desktop-feature-implementation.mdc +2 -2
- package/.cursor/rules/desktop-local-tools-implement.mdc +2 -2
- package/.github/workflows/test.yml +29 -14
- package/CHANGELOG.md +52 -0
- package/apps/desktop/Development.md +1 -6
- package/apps/desktop/README.md +2 -17
- package/apps/desktop/README.zh-CN.md +1 -15
- package/apps/desktop/src/main/controllers/index.ts +1 -1
- package/apps/desktop/src/main/controllers/registry.ts +0 -9
- package/apps/desktop/src/main/core/App.ts +1 -11
- package/apps/desktop/src/main/core/browser/Browser.ts +278 -457
- package/apps/desktop/src/main/core/browser/WindowStateManager.ts +180 -0
- package/apps/desktop/src/main/core/browser/WindowThemeManager.ts +167 -0
- package/apps/desktop/src/main/core/browser/__tests__/WindowStateManager.test.ts +237 -0
- package/apps/desktop/src/main/core/browser/__tests__/WindowThemeManager.test.ts +240 -0
- package/apps/desktop/src/main/exports.d.ts +1 -1
- package/apps/desktop/src/main/exports.ts +1 -1
- package/apps/desktop/src/main/utils/__tests__/http-headers.test.ts +131 -0
- package/apps/desktop/src/main/utils/http-headers.ts +61 -0
- package/apps/desktop/src/main/utils/ipc/__tests__/base.test.ts +1 -22
- package/apps/desktop/src/main/utils/ipc/base.ts +0 -20
- package/apps/desktop/src/main/utils/ipc/index.ts +1 -9
- package/changelog/v1.json +10 -0
- package/locales/en-US/subscription.json +1 -1
- package/locales/zh-CN/subscription.json +1 -1
- package/package.json +1 -1
- package/src/features/ChatInput/InputEditor/Placeholder.tsx +4 -1
- package/src/locales/default/subscription.ts +1 -1
- package/src/services/__tests__/models.test.ts +2 -1
- package/src/services/chat/index.ts +1 -1
- package/src/services/models.ts +2 -2
- package/vitest.config.mts +0 -1
- package/apps/desktop/src/main/controllers/UploadFileServerCtr.ts +0 -33
- package/apps/desktop/src/main/controllers/__tests__/UploadFileServerCtr.test.ts +0 -55
- package/src/server/modules/ElectronIPCClient/index.ts +0 -92
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { CreateFileParams } from '@lobechat/electron-server-ipc';
|
|
2
|
-
|
|
3
|
-
import FileService from '@/services/fileSrv';
|
|
4
|
-
|
|
5
|
-
import { ControllerModule, IpcServerMethod } from './index';
|
|
6
|
-
|
|
7
|
-
export default class UploadFileServerCtr extends ControllerModule {
|
|
8
|
-
static override readonly groupName = 'upload';
|
|
9
|
-
|
|
10
|
-
private get fileService() {
|
|
11
|
-
return this.app.getService(FileService);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
@IpcServerMethod()
|
|
15
|
-
async getFileUrlById(id: string) {
|
|
16
|
-
return this.fileService.getFilePath(id);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
@IpcServerMethod()
|
|
20
|
-
async getFileHTTPURL(path: string) {
|
|
21
|
-
return this.fileService.getFileHTTPURL(path);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
@IpcServerMethod()
|
|
25
|
-
async deleteFiles(paths: string[]) {
|
|
26
|
-
return this.fileService.deleteFiles(paths);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
@IpcServerMethod()
|
|
30
|
-
async createFile(params: CreateFileParams) {
|
|
31
|
-
return this.fileService.uploadFile(params);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import type { App } from '@/core/App';
|
|
4
|
-
|
|
5
|
-
import UploadFileServerCtr from '../UploadFileServerCtr';
|
|
6
|
-
|
|
7
|
-
vi.mock('@/services/fileSrv', () => ({
|
|
8
|
-
default: class MockFileService {},
|
|
9
|
-
}));
|
|
10
|
-
|
|
11
|
-
const mockFileService = {
|
|
12
|
-
getFileHTTPURL: vi.fn(),
|
|
13
|
-
getFilePath: vi.fn(),
|
|
14
|
-
deleteFiles: vi.fn(),
|
|
15
|
-
uploadFile: vi.fn(),
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const mockApp = {
|
|
19
|
-
getService: vi.fn(() => mockFileService),
|
|
20
|
-
} as unknown as App;
|
|
21
|
-
|
|
22
|
-
describe('UploadFileServerCtr', () => {
|
|
23
|
-
let controller: UploadFileServerCtr;
|
|
24
|
-
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
vi.clearAllMocks();
|
|
27
|
-
controller = new UploadFileServerCtr(mockApp);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('gets file path by id', async () => {
|
|
31
|
-
mockFileService.getFilePath.mockResolvedValue('path');
|
|
32
|
-
await expect(controller.getFileUrlById('id')).resolves.toBe('path');
|
|
33
|
-
expect(mockFileService.getFilePath).toHaveBeenCalledWith('id');
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('gets HTTP URL', async () => {
|
|
37
|
-
mockFileService.getFileHTTPURL.mockResolvedValue('url');
|
|
38
|
-
await expect(controller.getFileHTTPURL('/path')).resolves.toBe('url');
|
|
39
|
-
expect(mockFileService.getFileHTTPURL).toHaveBeenCalledWith('/path');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('deletes files', async () => {
|
|
43
|
-
mockFileService.deleteFiles.mockResolvedValue(undefined);
|
|
44
|
-
await controller.deleteFiles(['a']);
|
|
45
|
-
expect(mockFileService.deleteFiles).toHaveBeenCalledWith(['a']);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('creates files via upload service', async () => {
|
|
49
|
-
const params = { filename: 'file' } as any;
|
|
50
|
-
mockFileService.uploadFile.mockResolvedValue({ success: true });
|
|
51
|
-
|
|
52
|
-
await expect(controller.createFile(params)).resolves.toEqual({ success: true });
|
|
53
|
-
expect(mockFileService.uploadFile).toHaveBeenCalledWith(params);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { type CreateFileParams, ElectronIpcClient, type FileMetadata } from '@lobechat/electron-server-ipc';
|
|
2
|
-
import type { DesktopServerIpcServices } from '@lobehub/desktop-ipc-typings';
|
|
3
|
-
|
|
4
|
-
import packageJSON from '@/../apps/desktop/package.json';
|
|
5
|
-
|
|
6
|
-
const createServerInvokeProxy = <IpcServices>(
|
|
7
|
-
invoke: (channel: string, payload?: unknown) => Promise<unknown>,
|
|
8
|
-
): IpcServices =>
|
|
9
|
-
new Proxy(
|
|
10
|
-
{},
|
|
11
|
-
{
|
|
12
|
-
get(_target, groupKey) {
|
|
13
|
-
if (typeof groupKey !== 'string') return undefined;
|
|
14
|
-
|
|
15
|
-
return new Proxy(
|
|
16
|
-
{},
|
|
17
|
-
{
|
|
18
|
-
get(_methodTarget, methodKey) {
|
|
19
|
-
if (typeof methodKey !== 'string') return undefined;
|
|
20
|
-
|
|
21
|
-
const channel = `${groupKey}.${methodKey}`;
|
|
22
|
-
return (payload?: unknown) =>
|
|
23
|
-
payload === undefined ? invoke(channel) : invoke(channel, payload);
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
);
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
) as IpcServices;
|
|
30
|
-
|
|
31
|
-
class LobeHubElectronIpcClient extends ElectronIpcClient {
|
|
32
|
-
private _services: DesktopServerIpcServices | null = null;
|
|
33
|
-
|
|
34
|
-
private ensureServices(): DesktopServerIpcServices {
|
|
35
|
-
if (this._services) return this._services;
|
|
36
|
-
|
|
37
|
-
this._services = createServerInvokeProxy<DesktopServerIpcServices>((channel, payload) =>
|
|
38
|
-
payload === undefined ? this.sendRequest(channel) : this.sendRequest(channel, payload),
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
return this.services;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
private get ipc() {
|
|
45
|
-
return this.ensureServices();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public get services(): DesktopServerIpcServices {
|
|
49
|
-
return this.ipc;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
getDatabasePath = async (): Promise<string> => {
|
|
53
|
-
return this.ipc.system.getDatabasePath();
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
getUserDataPath = async (): Promise<string> => {
|
|
57
|
-
return this.ipc.system.getUserDataPath();
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
getDatabaseSchemaHash = async () => {
|
|
61
|
-
return this.ipc.system.getDatabaseSchemaHash();
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
setDatabaseSchemaHash = async (hash: string | undefined) => {
|
|
65
|
-
if (!hash) return;
|
|
66
|
-
|
|
67
|
-
return this.ipc.system.setDatabaseSchemaHash(hash);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
getFilePathById = async (id: string) => {
|
|
71
|
-
return this.ipc.upload.getFileUrlById(id);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
getFileHTTPURL = async (path: string) => {
|
|
75
|
-
return this.ipc.upload.getFileHTTPURL(path);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
deleteFiles = async (paths: string[]) => {
|
|
79
|
-
return this.ipc.upload.deleteFiles(paths);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
createFile = async (params: CreateFileParams) => {
|
|
83
|
-
return this.ipc.upload.createFile(params) as Promise<{
|
|
84
|
-
metadata: FileMetadata;
|
|
85
|
-
success: boolean;
|
|
86
|
-
}>;
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export const electronIpcClient = new LobeHubElectronIpcClient(packageJSON.name);
|
|
91
|
-
|
|
92
|
-
export const ensureElectronServerIpc = (): DesktopServerIpcServices => electronIpcClient.services;
|