mirror of
https://github.com/mileswolfallen2/OmniEmu2.0.git
synced 2026-12-06 16:43:54 +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
@@ -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