fix: Navigation blocking now working with focuesed input fields

fix: Added warning to loging with lookup provider for better UX
feat: Added ROMM Client API Token in plugin settings
This commit is contained in:
Simeon Radivoev 2026-05-05 22:24:15 +03:00
parent 7029477392
commit 4da717c26d
Signed by: simeonradivoev
GPG key ID: C16C2132A7660C8E
20 changed files with 160 additions and 96 deletions

View file

@ -499,17 +499,17 @@ export default new Elysia()
}, { body: z.object({ source: z.string(), id: z.string() }) })
.get('/lookup', async ({ query: { search } }) =>
{
const matches: GameLookup[] = [];
await plugins.hooks.games.gameLookup.promise({ search, matches });
return matches;
const matches = new Map<string, GameLookup[]>();
await plugins.hooks.games.gameLookup.promise(matches, { search });
return { hadMatchers: matches.size > 0, matches: Array.from(matches.values()).flatMap(m => m) };
}, {
query: z.object({ search: z.string() })
})
.get('/lookup/:source/:id', async ({ params: { source, id } }) =>
{
const matches: GameLookup[] = [];
await plugins.hooks.games.gameLookup.promise({ source, id, matches });
return matches;
const matches = new Map<string, GameLookup[]>();
await plugins.hooks.games.gameLookup.promise(matches, { source, id });
return Array.from(matches.values()).flatMap(m => m);
})
.post('/game/:source/:id/play', async ({ params: { id, source }, body, set }) =>
{

View file

@ -48,9 +48,10 @@ export async function customUpdate (source: string, id: string, destination: str
const localGame = await getLocalGame(source, id);
if (!localGame) throw new Error("Could not find Local Game");
const matches: GameLookup[] = [];
await plugins.hooks.games.gameLookup.promise({ source: destination, id: destinationId, matches });
if (matches.length <= 0) throw new Error("Could not find destination");
const matchesMap = new Map<string, GameLookup[]>();
await plugins.hooks.games.gameLookup.promise(matchesMap, { source: destination, id: destinationId });
const matches = matchesMap.values().next().value;
if (!matches || matches?.length <= 0) throw new Error("Could not find destination");
const match = matches[0];
await db.transaction(async (tx) =>

View file

@ -441,9 +441,9 @@ export async function createLocalGame (info: {
if (info.screenshotUrls.length <= 0 && info.igdb_id)
{
const matches: GameLookup[] = [];
await plugins.hooks.games.gameLookup.promise({ source: 'igdb', id: String(info.igdb_id), matches });
info.screenshotUrls.push(...matches[0].screenshotUrls);
const matches = new Map<string, GameLookup[]>();
await plugins.hooks.games.gameLookup.promise(matches, { source: 'igdb', id: String(info.igdb_id) });
info.screenshotUrls.push(...(matches.values().next().value?.[0].screenshotUrls ?? []));
}
// pre-fetch screenshots

View file

@ -1,6 +1,6 @@
import { EmulatorPackageType, GameListFilterType } from '@/shared/constants';
import { CommandEntry, DownloadInfo, EmulatorSourceEntryType, EmulatorSupport, EmulatorSystem, FrontEndCollection, FrontEndFilterSets, FrontEndGameType, FrontEndGameTypeDetailed, FrontEndGameTypeWithIds, FrontEndId, FrontEndPlatformType, GameLookup, SaveFileChange, SaveSlots } from '@/shared/types';
import { SyncBailHook, AsyncSeriesHook, AsyncSeriesBailHook, Hook } from 'tapable';
import { SyncBailHook, AsyncSeriesHook, AsyncSeriesBailHook, Hook, AsyncSeriesWaterfallHook } from 'tapable';
export default class GameHooks
{
@ -96,12 +96,11 @@ export default class GameHooks
name?: string;
family_name?: string;
} | undefined>(['ctx']);
gameLookup = new AsyncSeriesHook<[ctx: {
gameLookup = new AsyncSeriesWaterfallHook<[matches: Map<string, GameLookup[]>, ctx: {
source?: string,
id?: string;
search?: string;
matches: GameLookup[];
}]>(['ctx']);
}]>(['matches', 'ctx']);
fetchPlatforms = new AsyncSeriesHook<[ctx: {
platforms: FrontEndPlatformType[];
}]>(['ctx']);

View file

@ -32,9 +32,10 @@ export class ImportJob implements IJob<z.infer<typeof ImportJob.dataSchema>, str
async start (context: JobContext<IJob<z.infer<typeof ImportJob.dataSchema>, string>, z.infer<typeof ImportJob.dataSchema>, string>): Promise<any>
{
const matches: GameLookup[] = [];
await plugins.hooks.games.gameLookup.promise({ source: this.source, id: this.id, matches });
if (matches.length <= 0) throw Error("Could not Find Game");
const matchesMap = new Map<string, GameLookup[]>();
await plugins.hooks.games.gameLookup.promise(matchesMap, { source: this.source, id: this.id });
const matches = matchesMap.values().next().value;
if (!matches || matches.length <= 0) throw Error("Could not Find Game");
const match = matches[0];
let cover: Buffer<ArrayBufferLike> | undefined = undefined;

View file

@ -43,13 +43,13 @@ export default class IgdbIntegration implements PluginType
{
await checkLoginAndRefreshTwitch();
ctx.hooks.games.gameLookup.tapPromise(desc.name, async ({ source, id, search, matches }) =>
ctx.hooks.games.gameLookup.tapPromise(desc.name, async (matches, { source, id, search }) =>
{
if (!process.env.TWITCH_CLIENT_ID) return;
if (!process.env.TWITCH_CLIENT_ID) return matches;
const access_token = await secrets.get({ service: 'gamflow_twitch', name: 'access_token' });
if (!access_token)
{
return;
return matches;
}
if ((source === 'igdb' && id) || search)
@ -62,7 +62,7 @@ export default class IgdbIntegration implements PluginType
...(source === 'igdb' && id ? [igdb.where('id', '=', Number(id))] : []),
igdb.limit(10)).execute());
matches.push(...games.filter(g => !!g.name)
matches.set(desc.name, games.filter(g => !!g.name)
.map(g =>
{
const lookup: GameLookup = {
@ -89,8 +89,10 @@ export default class IgdbIntegration implements PluginType
return lookup;
}));
return;
return matches;
}
return matches.set(desc.name, []);
});
ctx.hooks.games.platformLookup.tapPromise(desc.name, async ({ source, id, slug }) =>

View file

@ -15,9 +15,11 @@ import { validateGameSource } from "@/bun/api/games/services/statusService";
import z from "zod";
import { checkLoginAndRefreshRomm } from "@/bun/api/auth";
import { DownloadFileEntry, DownloadInfo, FrontEndCollection, FrontEndGameType, FrontEndGameTypeDetailed, FrontEndGameTypeDetailedAchievement, FrontEndGameTypeWithIds, FrontEndPlatformType } from "@/shared/types";
import Conf from "conf";
const SettingsSchema = z.object({
savesSync: z.boolean().default(false).describe("Experimental save sync support")
savesSync: z.boolean().default(false).describe("Experimental save sync support"),
clientApiToken: z.string().optional().describe("Generate a long lived token from the ROMM server")
});
type SettingsType = z.infer<typeof SettingsSchema>;
@ -39,26 +41,34 @@ export default class RommIntegration implements PluginType<SettingsType>
return true;
}
async updateClient ()
async getAccessToken (config: Conf<SettingsType>)
{
if (process.env.ROMM_CLIENT_TOKEN) return process.env.ROMM_CLIENT_TOKEN;
const client_token = await config.get('clientApiToken');
if (client_token) return client_token;
return (await secrets.get({ service: 'gameflow', name: 'romm_access_token' })) ?? undefined;
}
async updateClient (pluginConfig: Conf<SettingsType>)
{
client.setConfig({
baseUrl: config.get('rommAddress'),
async auth (auth)
auth: (auth) =>
{
if (auth.scheme === 'bearer')
{
return (await secrets.get({ service: 'gameflow', name: 'romm_access_token' })) ?? undefined;
return this.getAccessToken(pluginConfig);
}
}
});
}
async getAuthToken ()
async getAuthToken (config: Conf<SettingsType>)
{
return getAuthToken({
scheme: 'bearer',
type: "http"
}, async (a) => (await secrets.get({ service: "gameflow", name: 'romm_access_token' })) ?? undefined);
}, async (a) => this.getAccessToken(config));
}
async getAllRommPlatforms ()
@ -146,9 +156,9 @@ export default class RommIntegration implements PluginType<SettingsType>
{
this.isSteamDeck = isSteamDeckGameMode();
ctx.setProgress(0, "Logging Into Romm");
await this.updateClient();
await this.updateClient(ctx.config);
await checkLoginAndRefreshRomm();
await this.updateClient();
await this.updateClient(ctx.config);
ctx.hooks.games.fetchGames.tapPromise(desc.name, async ({ query, games }) =>
{
@ -199,7 +209,7 @@ export default class RommIntegration implements PluginType<SettingsType>
{
if (!await this.checkRemote()) return;
if (service !== 'romm') return;
await this.updateClient();
await this.updateClient(ctx.config);
});
ctx.hooks.games.fetchGame.tapPromise(desc.name, async ({ source, id }) =>
@ -273,7 +283,7 @@ export default class RommIntegration implements PluginType<SettingsType>
system_slug: rommPlatform.slug,
metadata: rom.metadatum,
files,
auth: await this.getAuthToken(),
auth: await this.getAuthToken(ctx.config),
extract_path,
id: "romm"
};
@ -310,7 +320,7 @@ export default class RommIntegration implements PluginType<SettingsType>
}
}
if (files.length > 0) return { files, auth: await this.getAuthToken() };
if (files.length > 0) return { files, auth: await this.getAuthToken(ctx.config) };
});
ctx.hooks.games.fetchRecommendedGamesForGame.tapPromise(desc.name, async ({ game, games }) =>
@ -445,7 +455,7 @@ export default class RommIntegration implements PluginType<SettingsType>
const rommSlot = saveFiles.data.slots.find(s => s.slot === 'gameflow' && s.latest.file_name_no_tags === slot);
if (rommSlot)
{
const auth = await this.getAuthToken();
const auth = await this.getAuthToken(ctx.config);
const headers: Record<string, string> = {};
if (auth)
headers['Authorization'] = auth;
@ -535,7 +545,7 @@ export default class RommIntegration implements PluginType<SettingsType>
url.searchParams.set('emulator', command.emulator);
url.searchParams.set('overwrite', "true");
const auth = await this.getAuthToken();
const auth = await this.getAuthToken(ctx.config);
const headers: Record<string, string> = {};
if (auth)
headers['Authorization'] = auth;