TidGi-Desktop/src/services/context/index.ts
lin onetwo b76fc17794
Chore/upgrade (#646)
* docs: deps

* Update dependencies and type usage for AI features

Upgraded multiple dependencies in package.json and pnpm-lock.yaml, including @ai-sdk, @mui, react, and others for improved compatibility and performance. Changed type usage from CoreMessage to ModelMessage in mockOpenAI.test.ts to align with updated ai package. No functional changes to application logic.

* feat: i18n

* feat: test oauth login and use PKCE

* fix: use ollama-ai-provider-v2

* test: github and mock oauth2 login

* test: gitea login

* Refactor context menu cleanup and error message

Moved context menu cleanup for OAuth window to a single closed event handler in Authentication service. Simplified error message formatting in ContextService for missing keys.

* lint: AI fix

* Add tsx as a dev dependency and update scripts

Replaced usage of 'pnpm dlx tsx' with direct 'tsx' command in development and test scripts for improved reliability. Added 'tsx' to devDependencies in package.json.
2025-10-23 23:42:06 +08:00

48 lines
1.7 KiB
TypeScript

import { isElectronDevelopment } from '@/constants/isElectronDevelopment';
import { app, net } from 'electron';
import { injectable } from 'inversify';
import os from 'os';
import process from 'process';
import * as appPaths from '@/constants/appPaths';
import { supportedLanguagesMap, tiddlywikiLanguagesMap } from '@/constants/languages';
import * as paths from '@/constants/paths';
import { getMainWindowEntry } from '@services/windows/viteEntry';
import type { IConstants, IContext, IContextService, IPaths } from './interface';
@injectable()
export class ContextService implements IContextService {
// @ts-expect-error Property 'MAIN_WINDOW_WEBPACK_ENTRY' is missing, esbuild will make it `pathConstants = { ..._constants_paths__WEBPACK_IMPORTED_MODULE_4__, ..._constants_appPaths__WEBPACK_IMPORTED_MODULE_5__, 'http://localhost:3012/main_window' };`
private readonly pathConstants: IPaths = { ...paths, ...appPaths };
private readonly constants: IConstants = {
isDevelopment: isElectronDevelopment,
platform: process.platform,
appVersion: app.getVersion(),
appName: app.name,
oSVersion: os.release(),
environmentVersions: process.versions,
tiddlywikiLanguagesMap,
supportedLanguagesMap,
};
private readonly context: IContext;
constructor() {
this.pathConstants.MAIN_WINDOW_WEBPACK_ENTRY = getMainWindowEntry();
this.context = {
...this.pathConstants,
...this.constants,
};
}
public async get<K extends keyof IContext>(key: K): Promise<IContext[K]> {
if (key in this.context) {
return this.context[key];
}
throw new Error(`${key} not existed in ContextService`);
}
public async isOnline(): Promise<boolean> {
return net.isOnline();
}
}