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
500d1190a4
commit
c3f042112a
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: |
|
run: |
|
||||||
gh release create ${{ steps.tag.outputs.tag }} \
|
gh release create ${{ steps.tag.outputs.tag }} \
|
||||||
--title "Gerbil ${{ steps.tag.outputs.tag }}" \
|
--title "Gerbil ${{ steps.tag.outputs.tag }}" \
|
||||||
--generate-notes
|
--generate-notes \
|
||||||
|
--prerelease
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
export const APP_NAME = 'gerbil';
|
|
||||||
export const PRODUCT_NAME = 'Gerbil';
|
export const PRODUCT_NAME = 'Gerbil';
|
||||||
|
|
||||||
export const CONFIG_FILE_NAME = 'config.json';
|
export const CONFIG_FILE_NAME = 'config.json';
|
||||||
|
|
|
||||||
|
|
@ -1,34 +1,14 @@
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
import { spawn } from 'child_process';
|
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 { terminateProcess } from '@/utils/process';
|
||||||
import { pathExists, readJsonFile } from '@/utils/fs';
|
import { pathExists, readJsonFile } from '@/utils/fs';
|
||||||
|
import { getConfigDir } from '@/utils/path';
|
||||||
|
|
||||||
export class LightweightCliHandler {
|
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> {
|
private async getCurrentKoboldBinary(): Promise<string | null> {
|
||||||
try {
|
try {
|
||||||
const configPath = this.getConfigPath();
|
const configPath = getConfigDir();
|
||||||
if (!(await pathExists(configPath))) {
|
if (!(await pathExists(configPath))) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,10 @@ import { SillyTavernManager } from '@/main/managers/SillyTavernManager';
|
||||||
import { HardwareManager } from '@/main/managers/HardwareManager';
|
import { HardwareManager } from '@/main/managers/HardwareManager';
|
||||||
import { BinaryManager } from '@/main/managers/BinaryManager';
|
import { BinaryManager } from '@/main/managers/BinaryManager';
|
||||||
import { IPCHandlers } from '@/main/ipc';
|
import { IPCHandlers } from '@/main/ipc';
|
||||||
import { PRODUCT_NAME, CONFIG_FILE_NAME } from '@/constants';
|
import { PRODUCT_NAME } from '@/constants';
|
||||||
import { homedir } from 'os';
|
import { homedir } from 'os';
|
||||||
import { ensureDir } from '@/utils/fs';
|
import { ensureDir } from '@/utils/fs';
|
||||||
|
import { getConfigDir } from '@/utils/path';
|
||||||
|
|
||||||
export class GerbilApp {
|
export class GerbilApp {
|
||||||
private windowManager: WindowManager;
|
private windowManager: WindowManager;
|
||||||
|
|
@ -27,10 +28,7 @@ export class GerbilApp {
|
||||||
this.logManager = new LogManager();
|
this.logManager = new LogManager();
|
||||||
this.logManager.setupGlobalErrorHandlers();
|
this.logManager.setupGlobalErrorHandlers();
|
||||||
|
|
||||||
this.configManager = new ConfigManager(
|
this.configManager = new ConfigManager(getConfigDir(), this.logManager);
|
||||||
this.getConfigPath(),
|
|
||||||
this.logManager
|
|
||||||
);
|
|
||||||
this.windowManager = new WindowManager();
|
this.windowManager = new WindowManager();
|
||||||
this.hardwareManager = new HardwareManager(this.logManager);
|
this.hardwareManager = new HardwareManager(this.logManager);
|
||||||
|
|
||||||
|
|
@ -61,28 +59,23 @@ export class GerbilApp {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getConfigPath() {
|
private getDefaultInstallDir(): string {
|
||||||
return join(app.getPath('userData'), CONFIG_FILE_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
private getDefaultInstallDir(appName: string): string {
|
|
||||||
const platform = process.platform;
|
const platform = process.platform;
|
||||||
const home = homedir();
|
const home = homedir();
|
||||||
|
|
||||||
switch (platform) {
|
switch (platform) {
|
||||||
case 'win32':
|
case 'win32':
|
||||||
return join(home, appName);
|
return join(home, PRODUCT_NAME);
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
return join(home, 'Applications', appName);
|
return join(home, 'Applications', PRODUCT_NAME);
|
||||||
default:
|
default:
|
||||||
return join(home, '.local', 'share', appName);
|
return join(home, '.local', 'share', PRODUCT_NAME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async ensureInstallDirectory(): Promise<void> {
|
private async ensureInstallDirectory(): Promise<void> {
|
||||||
const installDir =
|
const installDir =
|
||||||
this.configManager.getInstallDir() ||
|
this.configManager.getInstallDir() || this.getDefaultInstallDir();
|
||||||
this.getDefaultInstallDir(PRODUCT_NAME);
|
|
||||||
|
|
||||||
if (!this.configManager.getInstallDir()) {
|
if (!this.configManager.getInstallDir()) {
|
||||||
await this.configManager.setInstallDir(installDir);
|
await this.configManager.setInstallDir(installDir);
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,9 @@
|
||||||
import { join, dirname } from 'path';
|
import { join, dirname } from 'path';
|
||||||
|
import { pathExists } from '@/utils/fs';
|
||||||
import { LogManager } from '@/main/managers/LogManager';
|
import { LogManager } from '@/main/managers/LogManager';
|
||||||
import type { KoboldCppManager } from '@/main/managers/KoboldCppManager';
|
import type { KoboldCppManager } from '@/main/managers/KoboldCppManager';
|
||||||
import type { HardwareManager } from '@/main/managers/HardwareManager';
|
import type { HardwareManager } from '@/main/managers/HardwareManager';
|
||||||
import type { BackendOption } from '@/types';
|
import type { BackendOption, BackendSupport } from '@/types';
|
||||||
import { pathExists } from '@/utils/fs';
|
|
||||||
|
|
||||||
export interface BackendSupport {
|
|
||||||
rocm: boolean;
|
|
||||||
vulkan: boolean;
|
|
||||||
clblast: boolean;
|
|
||||||
noavx2: boolean;
|
|
||||||
failsafe: boolean;
|
|
||||||
cuda: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class BinaryManager {
|
export class BinaryManager {
|
||||||
private backendSupportCache = new Map<string, BackendSupport>();
|
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,
|
BasicGPUInfo,
|
||||||
GPUMemoryInfo,
|
GPUMemoryInfo,
|
||||||
} from '@/types/hardware';
|
} from '@/types/hardware';
|
||||||
import type { BackendOption } from '@/types';
|
import type { BackendOption, BackendSupport } from '@/types';
|
||||||
|
|
||||||
export interface GitHubAsset {
|
export interface GitHubAsset {
|
||||||
name: string;
|
name: string;
|
||||||
|
|
@ -43,7 +43,6 @@ export interface ReleaseWithStatus {
|
||||||
export interface InstalledVersion {
|
export interface InstalledVersion {
|
||||||
version: string;
|
version: string;
|
||||||
path: string;
|
path: string;
|
||||||
type: 'github' | 'rocm';
|
|
||||||
filename: string;
|
filename: string;
|
||||||
size?: number;
|
size?: number;
|
||||||
}
|
}
|
||||||
|
|
@ -103,14 +102,7 @@ export interface KoboldAPI {
|
||||||
detectGPUCapabilities: () => Promise<GPUCapabilities>;
|
detectGPUCapabilities: () => Promise<GPUCapabilities>;
|
||||||
detectGPUMemory: () => Promise<GPUMemoryInfo[]>;
|
detectGPUMemory: () => Promise<GPUMemoryInfo[]>;
|
||||||
detectROCm: () => Promise<{ supported: boolean; devices: string[] }>;
|
detectROCm: () => Promise<{ supported: boolean; devices: string[] }>;
|
||||||
detectBackendSupport: () => Promise<{
|
detectBackendSupport: () => Promise<BackendSupport | null>;
|
||||||
rocm: boolean;
|
|
||||||
vulkan: boolean;
|
|
||||||
clblast: boolean;
|
|
||||||
noavx2: boolean;
|
|
||||||
failsafe: boolean;
|
|
||||||
cuda: boolean;
|
|
||||||
} | null>;
|
|
||||||
getAvailableBackends: (includeDisabled?: boolean) => Promise<BackendOption[]>;
|
getAvailableBackends: (includeDisabled?: boolean) => Promise<BackendOption[]>;
|
||||||
getCurrentInstallDir: () => Promise<string>;
|
getCurrentInstallDir: () => Promise<string>;
|
||||||
selectInstallDirectory: () => Promise<string | null>;
|
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[];
|
devices?: string[];
|
||||||
disabled?: boolean;
|
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