mirror of
https://github.com/lone-cloud/gerbil
synced 2026-06-03 19:54:44 -07:00
minor code refactoring
This commit is contained in:
parent
914e974426
commit
b913dc5c60
9 changed files with 46 additions and 72 deletions
3
.github/workflows/release.yml
vendored
3
.github/workflows/release.yml
vendored
|
|
@ -119,7 +119,8 @@ jobs:
|
|||
run: |
|
||||
gh release create ${{ steps.tag.outputs.tag }} \
|
||||
--title "Gerbil ${{ steps.tag.outputs.tag }}" \
|
||||
--generate-notes
|
||||
--generate-notes \
|
||||
--prerelease
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
export const APP_NAME = 'gerbil';
|
||||
export const PRODUCT_NAME = 'Gerbil';
|
||||
|
||||
export const CONFIG_FILE_NAME = 'config.json';
|
||||
|
|
|
|||
|
|
@ -1,34 +1,14 @@
|
|||
/* eslint-disable no-console */
|
||||
import { spawn } from 'child_process';
|
||||
import { join } from 'path';
|
||||
import { homedir } from 'os';
|
||||
|
||||
import { PRODUCT_NAME, CONFIG_FILE_NAME } from '@/constants';
|
||||
import { terminateProcess } from '@/utils/process';
|
||||
import { pathExists, readJsonFile } from '@/utils/fs';
|
||||
import { getConfigDir } from '@/utils/path';
|
||||
|
||||
export class LightweightCliHandler {
|
||||
private getConfigDir(appName: string): string {
|
||||
const platform = process.platform;
|
||||
const home = homedir();
|
||||
|
||||
switch (platform) {
|
||||
case 'win32':
|
||||
return join(home, 'AppData', 'Roaming', appName);
|
||||
case 'darwin':
|
||||
return join(home, 'Library', 'Application Support', appName);
|
||||
default:
|
||||
return join(home, '.config', appName);
|
||||
}
|
||||
}
|
||||
|
||||
private getConfigPath(): string {
|
||||
return join(this.getConfigDir(PRODUCT_NAME), CONFIG_FILE_NAME);
|
||||
}
|
||||
|
||||
private async getCurrentKoboldBinary(): Promise<string | null> {
|
||||
try {
|
||||
const configPath = this.getConfigPath();
|
||||
const configPath = getConfigDir();
|
||||
if (!(await pathExists(configPath))) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,9 +9,10 @@ import { SillyTavernManager } from '@/main/managers/SillyTavernManager';
|
|||
import { HardwareManager } from '@/main/managers/HardwareManager';
|
||||
import { BinaryManager } from '@/main/managers/BinaryManager';
|
||||
import { IPCHandlers } from '@/main/ipc';
|
||||
import { PRODUCT_NAME, CONFIG_FILE_NAME } from '@/constants';
|
||||
import { PRODUCT_NAME } from '@/constants';
|
||||
import { homedir } from 'os';
|
||||
import { ensureDir } from '@/utils/fs';
|
||||
import { getConfigDir } from '@/utils/path';
|
||||
|
||||
export class GerbilApp {
|
||||
private windowManager: WindowManager;
|
||||
|
|
@ -27,10 +28,7 @@ export class GerbilApp {
|
|||
this.logManager = new LogManager();
|
||||
this.logManager.setupGlobalErrorHandlers();
|
||||
|
||||
this.configManager = new ConfigManager(
|
||||
this.getConfigPath(),
|
||||
this.logManager
|
||||
);
|
||||
this.configManager = new ConfigManager(getConfigDir(), this.logManager);
|
||||
this.windowManager = new WindowManager();
|
||||
this.hardwareManager = new HardwareManager(this.logManager);
|
||||
|
||||
|
|
@ -61,28 +59,23 @@ export class GerbilApp {
|
|||
);
|
||||
}
|
||||
|
||||
private getConfigPath() {
|
||||
return join(app.getPath('userData'), CONFIG_FILE_NAME);
|
||||
}
|
||||
|
||||
private getDefaultInstallDir(appName: string): string {
|
||||
private getDefaultInstallDir(): string {
|
||||
const platform = process.platform;
|
||||
const home = homedir();
|
||||
|
||||
switch (platform) {
|
||||
case 'win32':
|
||||
return join(home, appName);
|
||||
return join(home, PRODUCT_NAME);
|
||||
case 'darwin':
|
||||
return join(home, 'Applications', appName);
|
||||
return join(home, 'Applications', PRODUCT_NAME);
|
||||
default:
|
||||
return join(home, '.local', 'share', appName);
|
||||
return join(home, '.local', 'share', PRODUCT_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
private async ensureInstallDirectory(): Promise<void> {
|
||||
const installDir =
|
||||
this.configManager.getInstallDir() ||
|
||||
this.getDefaultInstallDir(PRODUCT_NAME);
|
||||
this.configManager.getInstallDir() || this.getDefaultInstallDir();
|
||||
|
||||
if (!this.configManager.getInstallDir()) {
|
||||
await this.configManager.setInstallDir(installDir);
|
||||
|
|
|
|||
|
|
@ -1,18 +1,9 @@
|
|||
import { join, dirname } from 'path';
|
||||
import { pathExists } from '@/utils/fs';
|
||||
import { LogManager } from '@/main/managers/LogManager';
|
||||
import type { KoboldCppManager } from '@/main/managers/KoboldCppManager';
|
||||
import type { HardwareManager } from '@/main/managers/HardwareManager';
|
||||
import type { BackendOption } from '@/types';
|
||||
import { pathExists } from '@/utils/fs';
|
||||
|
||||
export interface BackendSupport {
|
||||
rocm: boolean;
|
||||
vulkan: boolean;
|
||||
clblast: boolean;
|
||||
noavx2: boolean;
|
||||
failsafe: boolean;
|
||||
cuda: boolean;
|
||||
}
|
||||
import type { BackendOption, BackendSupport } from '@/types';
|
||||
|
||||
export class BinaryManager {
|
||||
private backendSupportCache = new Map<string, BackendSupport>();
|
||||
|
|
|
|||
12
src/types/electron.d.ts
vendored
12
src/types/electron.d.ts
vendored
|
|
@ -4,7 +4,7 @@ import type {
|
|||
BasicGPUInfo,
|
||||
GPUMemoryInfo,
|
||||
} from '@/types/hardware';
|
||||
import type { BackendOption } from '@/types';
|
||||
import type { BackendOption, BackendSupport } from '@/types';
|
||||
|
||||
export interface GitHubAsset {
|
||||
name: string;
|
||||
|
|
@ -43,7 +43,6 @@ export interface ReleaseWithStatus {
|
|||
export interface InstalledVersion {
|
||||
version: string;
|
||||
path: string;
|
||||
type: 'github' | 'rocm';
|
||||
filename: string;
|
||||
size?: number;
|
||||
}
|
||||
|
|
@ -103,14 +102,7 @@ export interface KoboldAPI {
|
|||
detectGPUCapabilities: () => Promise<GPUCapabilities>;
|
||||
detectGPUMemory: () => Promise<GPUMemoryInfo[]>;
|
||||
detectROCm: () => Promise<{ supported: boolean; devices: string[] }>;
|
||||
detectBackendSupport: () => Promise<{
|
||||
rocm: boolean;
|
||||
vulkan: boolean;
|
||||
clblast: boolean;
|
||||
noavx2: boolean;
|
||||
failsafe: boolean;
|
||||
cuda: boolean;
|
||||
} | null>;
|
||||
detectBackendSupport: () => Promise<BackendSupport | null>;
|
||||
getAvailableBackends: (includeDisabled?: boolean) => Promise<BackendOption[]>;
|
||||
getCurrentInstallDir: () => Promise<string>;
|
||||
selectInstallDirectory: () => Promise<string | null>;
|
||||
|
|
|
|||
9
src/types/index.d.ts
vendored
9
src/types/index.d.ts
vendored
|
|
@ -52,3 +52,12 @@ export interface BackendOption extends SelectOption {
|
|||
devices?: string[];
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export interface BackendSupport {
|
||||
rocm: boolean;
|
||||
vulkan: boolean;
|
||||
clblast: boolean;
|
||||
noavx2: boolean;
|
||||
failsafe: boolean;
|
||||
cuda: boolean;
|
||||
}
|
||||
|
|
|
|||
21
src/utils/path.ts
Normal file
21
src/utils/path.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { join } from 'path';
|
||||
import { homedir } from 'os';
|
||||
import { PRODUCT_NAME, CONFIG_FILE_NAME } from '@/constants';
|
||||
|
||||
export function getConfigDir(): string {
|
||||
return join(getConfigDirPath(), CONFIG_FILE_NAME);
|
||||
}
|
||||
|
||||
function getConfigDirPath(): string {
|
||||
const platform = process.platform;
|
||||
const home = homedir();
|
||||
|
||||
switch (platform) {
|
||||
case 'win32':
|
||||
return join(home, 'AppData', 'Roaming', PRODUCT_NAME);
|
||||
case 'darwin':
|
||||
return join(home, 'Library', 'Application Support', PRODUCT_NAME);
|
||||
default:
|
||||
return join(home, '.config', PRODUCT_NAME);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
import { join } from 'path';
|
||||
|
||||
export function getPlatformPathFromWindowsPath(
|
||||
basePath: string,
|
||||
windowsBinaryPath: string
|
||||
): string {
|
||||
const binaryName =
|
||||
process.platform === 'win32'
|
||||
? windowsBinaryPath
|
||||
: windowsBinaryPath.replace(/\.[^.]*$/, '');
|
||||
return join(basePath, 'node_modules', '.bin', binaryName);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue