mirror of
https://github.com/mileswolfallen2/OmniEmu2.0.git
synced 2026-12-06 08:33:53 +00:00
still workign to make it this is just a back up
This commit is contained in:
1 parent
e1ee2173d2
commit
59cd586e3b
18 files changed
+798
-567
No files matched your search
@@ -288,6 +288,13 @@ function alternativePaths(emulatorId: string): string[] {
|
||||
const userData = app.getPath('userData');
|
||||
const omniEmuDir = join(userData, 'emulators', emulatorId);
|
||||
|
||||
// Check marker file first (written after a successful install)
|
||||
const markerFile = join(omniEmuDir, '.installed');
|
||||
try {
|
||||
const markerPath = require('fs').readFileSync(markerFile, 'utf-8').trim();
|
||||
if (markerPath && existsSync(markerPath)) return [markerPath];
|
||||
} catch { /* no marker */ }
|
||||
|
||||
const common: Record<string, string[]> = {
|
||||
dolphin: [
|
||||
join(omniEmuDir, 'Dolphin.exe'),
|
||||
|
||||
+50
-8
@@ -1,15 +1,40 @@
|
||||
import { app, BrowserWindow, Tray, Menu, nativeImage } from 'electron';
|
||||
import { join } from 'path';
|
||||
import { existsSync } from 'fs';
|
||||
import { registerIpcHandlers } from './ipc';
|
||||
import { settings } from './settings';
|
||||
import { isMacOS, isWindows } from './platform';
|
||||
import { isMacOS } from './platform';
|
||||
|
||||
let mainWindow: BrowserWindow | null = null;
|
||||
let tray: Tray | null = null;
|
||||
|
||||
const isDev = !app.isPackaged;
|
||||
const VITE_DEV_SERVER_URL = process.env.VITE_DEV_SERVER_URL;
|
||||
|
||||
function createAppIcon() {
|
||||
const iconPaths = [
|
||||
join(__dirname, '../../assets/icon.png'),
|
||||
join(__dirname, '../renderer/assets/icon.png'),
|
||||
join(__dirname, '../../build/icon.png'),
|
||||
];
|
||||
for (const p of iconPaths) {
|
||||
try {
|
||||
if (existsSync(p)) return nativeImage.createFromPath(p);
|
||||
} catch { /* skip */ }
|
||||
}
|
||||
// Fallback: 16x16 purple pixel
|
||||
const size = 16;
|
||||
const buf = Buffer.alloc(size * size * 4 + 8);
|
||||
buf.writeUInt32LE(size, 0);
|
||||
buf.writeUInt32LE(size, 4);
|
||||
for (let i = 8; i < buf.length; i += 4) {
|
||||
buf[i] = 108; buf[i + 1] = 99; buf[i + 2] = 255; buf[i + 3] = 255;
|
||||
}
|
||||
return nativeImage.createFromBuffer(buf, { width: size, height: size });
|
||||
}
|
||||
|
||||
function createWindow(): void {
|
||||
const icon = createAppIcon();
|
||||
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 1200,
|
||||
height: 800,
|
||||
@@ -18,6 +43,7 @@ function createWindow(): void {
|
||||
title: 'OmniEmu',
|
||||
backgroundColor: '#1a1a2e',
|
||||
show: false,
|
||||
icon,
|
||||
webPreferences: {
|
||||
preload: join(__dirname, 'preload.js'),
|
||||
contextIsolation: true,
|
||||
@@ -26,9 +52,11 @@ function createWindow(): void {
|
||||
},
|
||||
});
|
||||
|
||||
if (isDev) {
|
||||
mainWindow.loadURL('http://localhost:5173');
|
||||
mainWindow.webContents.openDevTools();
|
||||
if (VITE_DEV_SERVER_URL) {
|
||||
mainWindow.loadURL(VITE_DEV_SERVER_URL);
|
||||
if (process.env.OMNIEMU_DEVTOOLS) {
|
||||
mainWindow.webContents.openDevTools();
|
||||
}
|
||||
} else {
|
||||
mainWindow.loadFile(join(__dirname, '../renderer/index.html'));
|
||||
}
|
||||
@@ -51,10 +79,10 @@ function createWindow(): void {
|
||||
}
|
||||
|
||||
function createTray(): void {
|
||||
const iconSize = isMacOS() ? 16 : 24;
|
||||
const icon = nativeImage.createEmpty();
|
||||
const icon = createAppIcon();
|
||||
const trayIcon = icon.resize({ width: 22, height: 22 });
|
||||
|
||||
tray = new Tray(icon);
|
||||
tray = new Tray(trayIcon);
|
||||
tray.setToolTip('OmniEmu');
|
||||
|
||||
const contextMenu = Menu.buildFromTemplate([
|
||||
@@ -67,6 +95,20 @@ function createTray(): void {
|
||||
tray.on('click', () => mainWindow?.show());
|
||||
}
|
||||
|
||||
// Prevent multiple instances
|
||||
const gotLock = app.requestSingleInstanceLock();
|
||||
if (!gotLock) {
|
||||
app.quit();
|
||||
} else {
|
||||
app.on('second-instance', () => {
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||
mainWindow.show();
|
||||
mainWindow.focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
app.whenReady().then(() => {
|
||||
registerIpcHandlers();
|
||||
createWindow();
|
||||
|
||||
+117
-69
@@ -1,10 +1,9 @@
|
||||
import { createWriteStream, existsSync, mkdirSync, createReadStream } from 'fs';
|
||||
import { join, dirname, basename, extname } from 'path';
|
||||
import { get } from 'https';
|
||||
import { get as getHttp } from 'http';
|
||||
import { execSync, spawn } from 'child_process';
|
||||
import { createWriteStream, existsSync, mkdirSync, readdirSync, statSync } from 'fs';
|
||||
import { join, basename, extname, dirname } from 'path';
|
||||
import { get as httpsGet, RequestOptions } from 'https';
|
||||
import { get as httpGet } from 'http';
|
||||
import { execSync } from 'child_process';
|
||||
import { pipeline } from 'stream/promises';
|
||||
import { createGunzip, createBrotliDecompress, createInflate } from 'zlib';
|
||||
import { randomBytes } from 'crypto';
|
||||
import { app } from 'electron';
|
||||
import { EmulatorDownload, InstallProgress, Platform, Arch } from '../shared/types';
|
||||
@@ -24,113 +23,158 @@ function tempName(suffix: string): string {
|
||||
|
||||
function downloadFile(url: string, dest: string, onProgress: (pct: number) => void): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const protocol = url.startsWith('https') ? get : getHttp;
|
||||
protocol(url, (response) => {
|
||||
const code = response.statusCode ?? 500;
|
||||
if (code >= 300 && code < 400 && response.headers.location) {
|
||||
downloadFile(response.headers.location, dest, onProgress).then(resolve).catch(reject);
|
||||
return;
|
||||
}
|
||||
if (code !== 200) {
|
||||
reject(new Error(`HTTP ${code} downloading ${url}`));
|
||||
return;
|
||||
}
|
||||
|
||||
const total = parseInt(response.headers['content-length'] ?? '0', 10);
|
||||
let downloaded = 0;
|
||||
const file = createWriteStream(dest);
|
||||
|
||||
response.on('data', (chunk: Buffer) => {
|
||||
downloaded += chunk.length;
|
||||
if (total > 0) onProgress(Math.round((downloaded / total) * 100));
|
||||
});
|
||||
|
||||
pipeline(response, file)
|
||||
.then(() => {
|
||||
onProgress(100);
|
||||
resolve();
|
||||
})
|
||||
.catch(reject);
|
||||
}).on('error', reject);
|
||||
const doRequest = (currentUrl: string) => {
|
||||
const protocol = currentUrl.startsWith('https') ? httpsGet : httpGet;
|
||||
const opts: RequestOptions = {
|
||||
headers: { 'User-Agent': 'OmniEmu/0.1.0' },
|
||||
timeout: 30000,
|
||||
};
|
||||
protocol(currentUrl, opts, (response) => {
|
||||
const code = response.statusCode ?? 500;
|
||||
if (code >= 300 && code < 400 && response.headers.location) {
|
||||
doRequest(response.headers.location);
|
||||
return;
|
||||
}
|
||||
if (code !== 200) {
|
||||
reject(new Error(`HTTP ${code} — ${currentUrl}`));
|
||||
return;
|
||||
}
|
||||
const total = parseInt(response.headers['content-length'] ?? '0', 10);
|
||||
let downloaded = 0;
|
||||
const fileStream = createWriteStream(dest);
|
||||
response.on('data', (chunk: Buffer) => {
|
||||
downloaded += chunk.length;
|
||||
if (total > 0) onProgress(Math.round((downloaded / total) * 100));
|
||||
});
|
||||
pipeline(response, fileStream).then(resolve).catch(reject);
|
||||
}).on('error', reject).on('timeout', function (this: any) { this.destroy(); reject(new Error('Download timed out')); });
|
||||
};
|
||||
doRequest(url);
|
||||
});
|
||||
}
|
||||
|
||||
function execOrThrow(cmd: string): string {
|
||||
try {
|
||||
return execSync(cmd, { stdio: 'pipe', timeout: 120000 }).toString();
|
||||
} catch (e: any) {
|
||||
throw new Error(`Command failed: ${cmd}\n${e.stderr?.toString() || e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
function findAppInDir(dir: string): string | undefined {
|
||||
const entries = readdirSync(dir, { withFileTypes: true });
|
||||
for (const e of entries) {
|
||||
const full = join(dir, e.name);
|
||||
if (e.isDirectory()) {
|
||||
if (e.name.endsWith('.app')) {
|
||||
const macosBin = join(full, 'Contents', 'MacOS', basename(e.name, '.app'));
|
||||
if (existsSync(macosBin)) return macosBin;
|
||||
}
|
||||
const found = findAppInDir(full);
|
||||
if (found) return found;
|
||||
} else if (e.isFile()) {
|
||||
const isExec = e.name.endsWith('.exe') || e.name.endsWith('.AppImage')
|
||||
|| e.name === 'retroarch' || e.name === 'dolphin-emu'
|
||||
|| e.name === 'rpcs3' || e.name === 'Ryujinx'
|
||||
|| e.name === 'mame' || e.name === 'mame64' || e.name === 'PCSX2';
|
||||
if (isExec) return full;
|
||||
// Check if it's executable
|
||||
try {
|
||||
if (statSync(full).mode & 0o111) return full;
|
||||
} catch { /* skip */ }
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function extractArchive(archivePath: string, destDir: string, format: string, emulatorId: string, onProgress: (msg: string) => void): void {
|
||||
if (!existsSync(destDir)) mkdirSync(destDir, { recursive: true });
|
||||
|
||||
onProgress(`Extracting ${basename(archivePath)}...`);
|
||||
|
||||
switch (format) {
|
||||
case 'zip': {
|
||||
execSync(`unzip -o "${archivePath}" -d "${destDir}"`, { stdio: 'pipe' });
|
||||
case 'zip':
|
||||
execOrThrow(`unzip -o "${archivePath}" -d "${destDir}"`);
|
||||
break;
|
||||
}
|
||||
case 'tar.gz':
|
||||
case 'tar.bz2': {
|
||||
const decompress = format === 'tar.bz2' ? '-j' : '-z';
|
||||
execSync(`tar -x${decompress}f "${archivePath}" -C "${destDir}"`, { stdio: 'pipe' });
|
||||
execOrThrow(`tar -xzf "${archivePath}" -C "${destDir}"`);
|
||||
break;
|
||||
case 'tar.bz2':
|
||||
execOrThrow(`tar -xjf "${archivePath}" -C "${destDir}"`);
|
||||
break;
|
||||
}
|
||||
case '7z': {
|
||||
execSync(`7z x "${archivePath}" -o"${destDir}" -y`, { stdio: 'pipe' });
|
||||
try {
|
||||
execOrThrow(`7z x "${archivePath}" -o"${destDir}" -y`);
|
||||
} catch {
|
||||
// Try unzip as fallback (some 7z files are actually zip)
|
||||
execOrThrow(`unzip -o "${archivePath}" -d "${destDir}"`);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'dmg': {
|
||||
// Attach DMG and copy .app out
|
||||
const mountPoint = `/tmp/omniemu_${emulatorId}`;
|
||||
execSync(`hdiutil attach "${archivePath}" -mountpoint "${mountPoint}" -nobrowse -quiet`, { stdio: 'pipe' });
|
||||
execSync(`cp -R "${mountPoint}"/*.app "${destDir}/" 2>/dev/null; cp -R "${mountPoint}"/*/*.app "${destDir}/" 2>/dev/null; true`, { stdio: 'pipe' });
|
||||
execSync(`hdiutil detach "${mountPoint}" -quiet 2>/dev/null; true`, { stdio: 'pipe' });
|
||||
if (!isMacOS()) throw new Error('DMG files can only be extracted on macOS');
|
||||
const mountPoint = `/tmp/omniemu_${emulatorId}_${randomBytes(4).toString('hex')}`;
|
||||
try {
|
||||
execOrThrow(`hdiutil attach "${archivePath}" -mountpoint "${mountPoint}" -nobrowse -quiet`);
|
||||
// Copy any .app bundles found in the mounted volume
|
||||
const result = execSync(`ls "${mountPoint}" 2>/dev/null || true`).toString();
|
||||
for (const item of result.split('\n').filter(Boolean)) {
|
||||
const src = join(mountPoint, item);
|
||||
if (item.endsWith('.app') || (statSync(src).isDirectory() && !item.startsWith('.'))) {
|
||||
execOrThrow(`cp -R "${src}" "${destDir}/"`);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
execOrThrow(`hdiutil detach "${mountPoint}" -quiet 2>/dev/null; true`);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'exe':
|
||||
case 'msi':
|
||||
case 'appimage':
|
||||
case 'pkg': {
|
||||
// These are direct installers, not archives
|
||||
case 'pkg':
|
||||
// These are installers, not archives
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new Error(`Unknown archive format: ${format}`);
|
||||
}
|
||||
|
||||
onProgress('Extraction complete');
|
||||
}
|
||||
|
||||
function runInstaller(installerPath: string, format: string, emulatorId: string, installDir: string, onProgress: (msg: string) => void): void {
|
||||
onProgress(`Running installer for ${emulatorId}...`);
|
||||
onProgress(`Running installer...`);
|
||||
|
||||
switch (format) {
|
||||
case 'exe': {
|
||||
if (isWindows()) {
|
||||
execSync(`"${installerPath}" /S /D="${installDir}"`, { stdio: 'pipe', timeout: 300000 });
|
||||
execOrThrow(`"${installerPath}" /S /D="${installDir}"`);
|
||||
} else {
|
||||
execSync(`chmod +x "${installerPath}" && "${installerPath}" -- "${installDir}"`, { stdio: 'pipe', timeout: 300000 });
|
||||
execOrThrow(`chmod +x "${installerPath}" && "${installerPath}"`);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'msi': {
|
||||
execSync(`msiexec /i "${installerPath}" /quiet /norestart INSTALLDIR="${installDir}"`, { stdio: 'pipe', timeout: 300000 });
|
||||
execOrThrow(`msiexec /i "${installerPath}" /quiet /norestart INSTALLDIR="${installDir}"`);
|
||||
break;
|
||||
}
|
||||
case 'appimage': {
|
||||
execSync(`chmod +x "${installerPath}"`, { stdio: 'pipe' });
|
||||
// Copy AppImage to install dir
|
||||
execSync(`cp "${installerPath}" "${installDir}/${emulatorId}.AppImage"`, { stdio: 'pipe' });
|
||||
execOrThrow(`chmod +x "${installerPath}"`);
|
||||
execOrThrow(`cp "${installerPath}" "${installDir}/${emulatorId}.AppImage"`);
|
||||
break;
|
||||
}
|
||||
case 'pkg': {
|
||||
execSync(`installer -pkg "${installerPath}" -target /`, { stdio: 'pipe', timeout: 300000 });
|
||||
execOrThrow(`installer -pkg "${installerPath}" -target /`);
|
||||
break;
|
||||
}
|
||||
case 'dmg': {
|
||||
case 'dmg':
|
||||
case 'zip':
|
||||
case 'tar.gz':
|
||||
case 'tar.bz2':
|
||||
case '7z':
|
||||
// Already handled in extractArchive
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new Error(`Cannot install format: ${format}`);
|
||||
}
|
||||
|
||||
onProgress('Installer finished');
|
||||
}
|
||||
|
||||
@@ -143,26 +187,24 @@ export async function installEmulator(
|
||||
arch: Arch,
|
||||
onProgress: ProgressCallback
|
||||
): Promise<string> {
|
||||
// Pick the right download for this platform + arch
|
||||
const candidates = downloads.filter((d) => !d.arch || d.arch === arch);
|
||||
const download = candidates[0];
|
||||
if (!download) throw new Error(`No download available for ${platform}/${arch}`);
|
||||
if (!download) throw new Error(`No download available for ${emulatorId} on ${platform} (${arch})`);
|
||||
|
||||
const report = (stage: InstallProgress['stage'], percent: number, message: string) => {
|
||||
onProgress({ emulatorId, stage, percent, message });
|
||||
};
|
||||
|
||||
report('downloading', 0, `Downloading ${download.url}...`);
|
||||
|
||||
report('downloading', 0, `Downloading ${emulatorId}...`);
|
||||
const downloadPath = tempName(`.${download.format}`);
|
||||
await downloadFile(download.url, downloadPath, (pct) => {
|
||||
report('downloading', pct, `Downloading ${emulatorId}... ${pct}%`);
|
||||
});
|
||||
report('downloading', 100, 'Download complete');
|
||||
|
||||
const installDir = join(app.getPath('userData'), 'emulators', emulatorId);
|
||||
if (!existsSync(installDir)) mkdirSync(installDir, { recursive: true });
|
||||
|
||||
// Determine if this is an archive or an installer
|
||||
const archiveFormats = ['zip', 'tar.gz', 'tar.bz2', '7z', 'dmg'];
|
||||
const installerFormats = ['exe', 'msi', 'pkg', 'appimage'];
|
||||
|
||||
@@ -185,7 +227,13 @@ export async function installEmulator(
|
||||
// Cleanup
|
||||
try { execSync(`rm -f "${downloadPath}"`); } catch { /* ignore */ }
|
||||
|
||||
report('done', 100, `${emulatorId} installed successfully`);
|
||||
report('done', 100, `${emulatorId} installed`);
|
||||
|
||||
return installDir;
|
||||
}
|
||||
|
||||
/** After install, find the executable in the install dir */
|
||||
export function findInstalledBinary(emulatorId: string, installDir: string): string | undefined {
|
||||
if (!existsSync(installDir)) return undefined;
|
||||
return findAppInDir(installDir);
|
||||
}
|
||||
+11
-2
@@ -1,4 +1,6 @@
|
||||
import { ipcMain, shell, dialog, BrowserWindow } from 'electron';
|
||||
import { join } from 'path';
|
||||
import { writeFileSync } from 'fs';
|
||||
import {
|
||||
getAllEmulatorStates,
|
||||
checkEmulator,
|
||||
@@ -9,7 +11,7 @@ import {
|
||||
getRomsDirectory,
|
||||
getEmulatorsDirectory,
|
||||
} from './emulators';
|
||||
import { installEmulator } from './installer';
|
||||
import { installEmulator, findInstalledBinary } from './installer';
|
||||
import { applyRecommendedConfig, getPresets, checkConfigured } from './configurator';
|
||||
import { settings } from './settings';
|
||||
import { getSystemInfo, platformName, getPlatform, getArch } from './platform';
|
||||
@@ -44,7 +46,14 @@ export function registerIpcHandlers(): void {
|
||||
win?.webContents.send('emulators:install-progress', p);
|
||||
};
|
||||
|
||||
await installEmulator(emulatorId, downloads, platform, arch, sendProgress);
|
||||
const installDir = await installEmulator(emulatorId, downloads, platform, arch, sendProgress);
|
||||
|
||||
// Try to find the binary and create a symlink or record it
|
||||
const binary = findInstalledBinary(emulatorId, installDir);
|
||||
if (binary) {
|
||||
const marker = join(installDir, '.installed');
|
||||
writeFileSync(marker, binary);
|
||||
}
|
||||
|
||||
// Re-check state after install
|
||||
return checkEmulator(emulatorId);
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
import React, { useEffect, useState, useCallback } from 'react';
|
||||
import type { EmulatorState } from '../../shared/types';
|
||||
import React, { useEffect, useState, useCallback, useRef } from 'react';
|
||||
import type { EmulatorState, InstallProgress } from '../../shared/types';
|
||||
|
||||
interface ProgressMap {
|
||||
[emulatorId: string]: InstallProgress;
|
||||
}
|
||||
|
||||
export function EmulatorsPage() {
|
||||
const [states, setStates] = useState<EmulatorState[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [progress, setProgress] = useState<ProgressMap>({});
|
||||
const [actioning, setActioning] = useState<string | null>(null);
|
||||
const cleanups = useRef<(() => void)[]>([]);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
@@ -12,16 +19,74 @@ export function EmulatorsPage() {
|
||||
setLoading(false);
|
||||
}, []);
|
||||
|
||||
useEffect(() => { load(); }, [load]);
|
||||
useEffect(() => {
|
||||
load();
|
||||
|
||||
const unsub = window.omni.emulators.onInstallProgress((p: InstallProgress) => {
|
||||
setProgress((prev) => ({ ...prev, [p.emulatorId]: p }));
|
||||
if (p.stage === 'done' || p.stage === 'error') {
|
||||
setActioning(null);
|
||||
}
|
||||
});
|
||||
cleanups.current.push(unsub);
|
||||
|
||||
return () => {
|
||||
cleanups.current.forEach((fn) => fn());
|
||||
};
|
||||
}, [load]);
|
||||
|
||||
const handleInstall = async (id: string) => {
|
||||
await window.omni.emulators.openInstallUrl(id);
|
||||
setActioning(id);
|
||||
setProgress((prev) => ({
|
||||
...prev,
|
||||
[id]: { emulatorId: id, stage: 'downloading', percent: 0, message: 'Starting...' },
|
||||
}));
|
||||
await window.omni.emulators.install(id);
|
||||
await load();
|
||||
};
|
||||
|
||||
const handleRefresh = () => {
|
||||
load();
|
||||
const handleInstallAndConfigure = async (id: string) => {
|
||||
setActioning(id);
|
||||
setProgress((prev) => ({
|
||||
...prev,
|
||||
[id]: { emulatorId: id, stage: 'downloading', percent: 0, message: 'Starting...' },
|
||||
}));
|
||||
const result = await window.omni.emulators.install(id);
|
||||
if (result.installed && result.path) {
|
||||
await window.omni.emulators.configure(id, result.path);
|
||||
}
|
||||
await load();
|
||||
};
|
||||
|
||||
const handleConfigure = async (state: EmulatorState) => {
|
||||
if (!state.path) return;
|
||||
setActioning(state.config.id);
|
||||
setProgress((prev) => ({
|
||||
...prev,
|
||||
[state.config.id]: {
|
||||
emulatorId: state.config.id,
|
||||
stage: 'configuring', percent: 0, message: 'Applying recommended settings...',
|
||||
},
|
||||
}));
|
||||
await window.omni.emulators.configure(state.config.id, state.path);
|
||||
setProgress((prev) => ({
|
||||
...prev,
|
||||
[state.config.id]: {
|
||||
emulatorId: state.config.id,
|
||||
stage: 'done', percent: 100,
|
||||
message: 'Configuration applied',
|
||||
},
|
||||
}));
|
||||
setActioning(null);
|
||||
await load();
|
||||
};
|
||||
|
||||
const handleOpenWebsite = async (id: string) => {
|
||||
await window.omni.emulators.openWebsite(id);
|
||||
};
|
||||
|
||||
const handleRefresh = () => load();
|
||||
|
||||
if (loading) {
|
||||
return <div className="loading">Checking emulators...</div>;
|
||||
}
|
||||
@@ -31,74 +96,164 @@ export function EmulatorsPage() {
|
||||
<div className="empty-state">
|
||||
<div className="empty-state-icon">🕹️</div>
|
||||
<h3>No emulators configured</h3>
|
||||
<p>Add emulator definitions to get started.</p>
|
||||
<p>Ready to install and configure emulators automatically.</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const currentProgress = (id: string) => progress[id];
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div style={{ display: 'flex', justifyContent: 'flex-end', marginBottom: 16 }}>
|
||||
<div className="info-bar">
|
||||
<span>
|
||||
{states.filter((s) => s.installed).length} installed
|
||||
{' · '}
|
||||
{states.filter((s) => s.configured).length} configured
|
||||
{' · '}
|
||||
{Object.keys(progress).length > 0 && ' Installing...'}
|
||||
</span>
|
||||
<button className="btn btn-secondary btn-sm" onClick={handleRefresh}>
|
||||
Refresh
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="card-grid">
|
||||
{states.map((state) => (
|
||||
<div className="card" key={state.config.id}>
|
||||
<div className="card-header">
|
||||
<h3>{state.config.name}</h3>
|
||||
<span
|
||||
className={`badge ${
|
||||
!state.config.supported
|
||||
? 'badge-unsupported'
|
||||
: state.installed
|
||||
? 'badge-installed'
|
||||
: 'badge-missing'
|
||||
}`}
|
||||
>
|
||||
{!state.config.supported
|
||||
? 'Unsupported'
|
||||
: state.installed
|
||||
? 'Installed'
|
||||
: 'Not installed'}
|
||||
</span>
|
||||
</div>
|
||||
{states.map((state) => {
|
||||
const prog = currentProgress(state.config.id);
|
||||
const isActioning = actioning === state.config.id;
|
||||
|
||||
<p>{state.config.description}</p>
|
||||
|
||||
<div style={{ marginTop: 8 }}>
|
||||
{state.config.platforms.map((p) => (
|
||||
<span className="platform-tag" key={p}>
|
||||
{p}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{state.version && (
|
||||
<p className="text-sm text-muted mt-2">
|
||||
Version: {state.version}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div style={{ marginTop: 12, display: 'flex', gap: 8 }}>
|
||||
{!state.installed && state.config.installUrl && (
|
||||
<button
|
||||
className="btn btn-primary btn-sm"
|
||||
onClick={() => handleInstall(state.config.id)}
|
||||
return (
|
||||
<div className="card" key={state.config.id}>
|
||||
<div className="card-header">
|
||||
<h3>{state.config.name}</h3>
|
||||
<span
|
||||
className={`badge ${
|
||||
!state.config.supported
|
||||
? 'badge-unsupported'
|
||||
: state.installed
|
||||
? state.configured
|
||||
? 'badge-installed'
|
||||
: 'badge-installed'
|
||||
: 'badge-missing'
|
||||
}`}
|
||||
>
|
||||
Install
|
||||
</button>
|
||||
)}
|
||||
{state.installed && state.path && (
|
||||
<span className="text-sm text-muted" style={{ padding: '4px 0' }}>
|
||||
{state.path}
|
||||
{!state.config.supported
|
||||
? 'Unsupported'
|
||||
: state.installed
|
||||
? state.configured
|
||||
? 'Configured'
|
||||
: 'Installed'
|
||||
: 'Not installed'}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<p>{state.config.description}</p>
|
||||
|
||||
<div style={{ marginTop: 8 }}>
|
||||
{state.config.platforms.map((p) => (
|
||||
<span className="platform-tag" key={p}>
|
||||
{p}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{state.version && (
|
||||
<p className="text-sm text-muted mt-2">Version: {state.version}</p>
|
||||
)}
|
||||
|
||||
{prog && (
|
||||
<div className="mt-2">
|
||||
<div className="progress-bar">
|
||||
<div
|
||||
className="progress-fill"
|
||||
style={{
|
||||
width: `${prog.percent}%`,
|
||||
background:
|
||||
prog.stage === 'error'
|
||||
? 'var(--error)'
|
||||
: 'var(--accent)',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<p className="text-sm text-muted mt-2">
|
||||
{prog.stage === 'error'
|
||||
? `Error: ${prog.error || prog.message}`
|
||||
: prog.message}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div
|
||||
style={{
|
||||
marginTop: 12,
|
||||
display: 'flex',
|
||||
flexWrap: 'wrap',
|
||||
gap: 6,
|
||||
alignItems: 'center',
|
||||
}}
|
||||
>
|
||||
{!state.installed && state.config.supported && (
|
||||
<>
|
||||
<button
|
||||
className="btn btn-primary btn-sm"
|
||||
disabled={isActioning}
|
||||
onClick={() => handleInstallAndConfigure(state.config.id)}
|
||||
>
|
||||
{isActioning ? 'Working...' : 'Install & Configure'}
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-secondary btn-sm"
|
||||
disabled={isActioning}
|
||||
onClick={() => handleInstall(state.config.id)}
|
||||
>
|
||||
Install Only
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
|
||||
{!state.installed && !state.config.supported && (
|
||||
<span className="text-sm text-muted">Not supported on this platform</span>
|
||||
)}
|
||||
|
||||
{state.installed && !state.configured && (
|
||||
<button
|
||||
className="btn btn-primary btn-sm"
|
||||
disabled={isActioning}
|
||||
onClick={() => handleConfigure(state)}
|
||||
>
|
||||
Apply Recommended Settings
|
||||
</button>
|
||||
)}
|
||||
|
||||
{state.installed && state.configured && (
|
||||
<>
|
||||
<button
|
||||
className="btn btn-secondary btn-sm"
|
||||
disabled={isActioning}
|
||||
onClick={() => handleConfigure(state)}
|
||||
>
|
||||
Re-apply Settings
|
||||
</button>
|
||||
<span className="badge badge-installed" style={{ fontSize: 11 }}>
|
||||
Configured
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
|
||||
{state.config.websiteUrl && (
|
||||
<button
|
||||
className="btn-icon"
|
||||
title="Open website"
|
||||
onClick={() => handleOpenWebsite(state.config.id)}
|
||||
>
|
||||
↗
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -2,79 +2,97 @@ import React, { useEffect, useState, useCallback } from 'react';
|
||||
import type { GameEntry } from '../../shared/types';
|
||||
|
||||
const platformIcons: Record<string, string> = {
|
||||
nes: '🕹️',
|
||||
snes: '🕹️',
|
||||
n64: '🎮',
|
||||
gba: '🎮',
|
||||
gbc: '🎮',
|
||||
ps1: '💿',
|
||||
ps2: '💿',
|
||||
ps3: '💿',
|
||||
wii: '📀',
|
||||
gc: '📀',
|
||||
switch: '🕹️',
|
||||
arcade: '🕹️',
|
||||
nes: '🕹️', snes: '🕹️', n64: '🎮',
|
||||
gba: '🎮', gbc: '🎮',
|
||||
ps1: '💿', ps2: '💿', ps3: '💿',
|
||||
wii: '📀', gc: '📀',
|
||||
switch: '🕹️', arcade: '🕹️',
|
||||
};
|
||||
|
||||
export function LibraryPage() {
|
||||
const [games, setGames] = useState<GameEntry[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [selectedDir, setSelectedDir] = useState<string | null>(null);
|
||||
const [romsDir, setRomsDir] = useState<string>('');
|
||||
|
||||
const handleScan = useCallback(async () => {
|
||||
const dir = await window.omni.roms.selectDirectory();
|
||||
if (!dir) return;
|
||||
setSelectedDir(dir);
|
||||
// Load saved ROM directory on mount
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const settings = await window.omni.settings.get();
|
||||
if (settings.romsDirectory) {
|
||||
setRomsDir(settings.romsDirectory);
|
||||
setLoading(true);
|
||||
const results = await window.omni.roms.scan(settings.romsDirectory);
|
||||
setGames(results);
|
||||
setLoading(false);
|
||||
}
|
||||
})();
|
||||
}, []);
|
||||
|
||||
const scanDirectory = useCallback(async (dir: string) => {
|
||||
setRomsDir(dir);
|
||||
setLoading(true);
|
||||
// Save to persistent settings
|
||||
await window.omni.settings.save({ romsDirectory: dir });
|
||||
const results = await window.omni.roms.scan(dir);
|
||||
setGames(results);
|
||||
setLoading(false);
|
||||
}, []);
|
||||
|
||||
const handleScan = useCallback(async () => {
|
||||
const dir = await window.omni.roms.selectDirectory();
|
||||
if (!dir) return;
|
||||
await scanDirectory(dir);
|
||||
}, [scanDirectory]);
|
||||
|
||||
const handleLaunch = async (game: GameEntry) => {
|
||||
await window.omni.game.launch(game.emulatorId, game.romPath);
|
||||
};
|
||||
|
||||
const handleOpenDirectory = async () => {
|
||||
const dir = await window.omni.roms.selectDirectory();
|
||||
if (!dir) return;
|
||||
setSelectedDir(dir);
|
||||
setLoading(true);
|
||||
const results = await window.omni.roms.scan(dir);
|
||||
setGames(results);
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div style={{ display: 'flex', gap: 8, marginBottom: 16 }}>
|
||||
<div style={{ display: 'flex', gap: 8, marginBottom: 16, alignItems: 'center' }}>
|
||||
<button className="btn btn-primary" onClick={handleScan}>
|
||||
Scan for ROMs
|
||||
Select ROM Folder
|
||||
</button>
|
||||
{selectedDir && (
|
||||
<span className="text-sm text-muted" style={{ padding: '8px 0' }}>
|
||||
{selectedDir}
|
||||
{romsDir && (
|
||||
<span className="text-sm text-muted" style={{ padding: '8px 0', maxWidth: 400, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
||||
{romsDir}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{loading && <div className="loading">Scanning for games...</div>}
|
||||
|
||||
{!loading && games.length === 0 && (
|
||||
<div className="scan-area" onClick={handleOpenDirectory}>
|
||||
{!loading && games.length === 0 && !romsDir && (
|
||||
<div className="scan-area" onClick={handleScan}>
|
||||
<div style={{ fontSize: 48 }}>📂</div>
|
||||
<p>Click to select a ROM directory</p>
|
||||
<p>Select a folder to scan for ROMs</p>
|
||||
<p className="text-sm text-muted mt-2">
|
||||
Supported formats: .nes, .sfc, .n64, .gba, .iso, .wbfs, .nsp, .ps2, and more
|
||||
Your ROM directory will be saved for next time
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!loading && games.length === 0 && romsDir && (
|
||||
<div className="empty-state">
|
||||
<div className="empty-state-icon">🔍</div>
|
||||
<p>No ROMs found in that folder</p>
|
||||
<p className="text-sm text-muted mt-2">
|
||||
Supported: .nes, .sfc, .n64, .gba, .iso, .wbfs, .nsp, .ps2, .chd, and more
|
||||
</p>
|
||||
<button className="btn btn-secondary mt-4" onClick={handleScan}>
|
||||
Choose another folder
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{games.length > 0 && (
|
||||
<div>
|
||||
<div className="info-bar">
|
||||
<span>{games.length} games found</span>
|
||||
<span>{(games.length / 10).toFixed(1)} GB estimated</span>
|
||||
<button className="btn btn-secondary btn-sm" onClick={handleScan}>
|
||||
Rescan
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="library-grid">
|
||||
@@ -91,9 +109,7 @@ export function LibraryPage() {
|
||||
<div className="game-card-info">
|
||||
<div className="game-card-title">{game.title}</div>
|
||||
<div className="game-card-platform">
|
||||
{game.platform.toUpperCase()}
|
||||
{' · '}
|
||||
{game.emulatorId}
|
||||
{game.platform.toUpperCase()} · {game.emulatorId}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -84,6 +84,25 @@ export function SettingsPage() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="settings-section">
|
||||
<h3>Presets</h3>
|
||||
|
||||
<div className="setting-row">
|
||||
<div>
|
||||
<div className="setting-label">Preset Source URL</div>
|
||||
<div className="setting-desc">
|
||||
URL to fetch recommended emulator config presets from
|
||||
</div>
|
||||
</div>
|
||||
<input
|
||||
type="text"
|
||||
value={settings.presetSourceUrl}
|
||||
onChange={(e) => update({ presetSourceUrl: e.target.value })}
|
||||
style={{ width: 300 }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="settings-section">
|
||||
<h3>Behavior</h3>
|
||||
|
||||
|
||||
@@ -447,6 +447,21 @@ select:focus, input[type="text"]:focus {
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
/* Progress bar */
|
||||
.progress-bar {
|
||||
width: 100%;
|
||||
height: 6px;
|
||||
background: var(--bg-tertiary);
|
||||
border-radius: 3px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.progress-fill {
|
||||
height: 100%;
|
||||
border-radius: 3px;
|
||||
transition: width 300ms ease, background 300ms ease;
|
||||
}
|
||||
|
||||
/* Utility */
|
||||
.mt-2 { margin-top: 8px; }
|
||||
.mt-4 { margin-top: 16px; }
|
||||
|
||||
+42
-2
@@ -1,8 +1,48 @@
|
||||
import type { OmniApi } from '../main/preload';
|
||||
import type {
|
||||
EmulatorConfig,
|
||||
EmulatorState,
|
||||
GameEntry,
|
||||
SystemInfo,
|
||||
AppSettings,
|
||||
InstallProgress,
|
||||
ConfigPreset,
|
||||
} from '../shared/types';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
omni: OmniApi;
|
||||
omni: {
|
||||
system: {
|
||||
info: () => Promise<SystemInfo>;
|
||||
platformName: () => Promise<string>;
|
||||
};
|
||||
emulators: {
|
||||
list: () => Promise<EmulatorConfig[]>;
|
||||
states: () => Promise<EmulatorState[]>;
|
||||
check: (id: string) => Promise<EmulatorState>;
|
||||
install: (id: string) => Promise<EmulatorState>;
|
||||
configure: (id: string, installPath: string) => Promise<{ success: boolean; state: EmulatorState }>;
|
||||
presets: (id: string) => Promise<ConfigPreset[]>;
|
||||
configured: (id: string, installPath?: string) => Promise<boolean>;
|
||||
openWebsite: (id: string) => Promise<boolean>;
|
||||
onInstallProgress: (cb: (p: InstallProgress) => void) => () => void;
|
||||
};
|
||||
roms: {
|
||||
scan: (directory?: string) => Promise<GameEntry[]>;
|
||||
selectDirectory: () => Promise<string | null>;
|
||||
};
|
||||
game: {
|
||||
launch: (emulatorId: string, romPath: string) => Promise<boolean>;
|
||||
};
|
||||
settings: {
|
||||
get: () => Promise<AppSettings>;
|
||||
save: (s: Partial<AppSettings>) => Promise<AppSettings>;
|
||||
reset: () => Promise<AppSettings>;
|
||||
};
|
||||
paths: {
|
||||
romsDirectory: () => Promise<string>;
|
||||
emulatorsDirectory: () => Promise<string>;
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user