633 lines
24 KiB
HTML
633 lines
24 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en" data-bs-theme="auto">
|
|
|
|
<head>
|
|
<%- header %>
|
|
</head>
|
|
|
|
<body id="app" v-cloak>
|
|
<Navbar></Navbar>
|
|
<div class="container">
|
|
<div class="my-4">
|
|
<h1>{{ $t('apps.applications_title') }}</h1>
|
|
<p>{{ $t('apps.applications_desc') }}</p>
|
|
</div>
|
|
|
|
<!-- Apps Grid -->
|
|
<div class="row g-3" v-if="apps && apps.length > 0">
|
|
<div class="col-12 col-sm-6 col-md-4 col-lg-3" v-for="(app,i) in apps" :key="i">
|
|
<div class="card app-card h-100">
|
|
<div class="app-poster-container">
|
|
<img
|
|
v-if="app['image-path']"
|
|
:src="'/api/covers/' + i"
|
|
class="app-poster"
|
|
:alt="app.name"
|
|
@error="handleImageError"
|
|
/>
|
|
<div v-else class="app-poster-placeholder">
|
|
<span class="app-initial">{{ app.name.charAt(0).toUpperCase() }}</span>
|
|
</div>
|
|
</div>
|
|
<div class="card-body d-flex flex-column">
|
|
<h5 class="card-title mb-2">{{ app.name }}</h5>
|
|
<div class="app-details text-muted small mb-3">
|
|
<div v-if="app.output" class="text-truncate">
|
|
<file-text :size="14" class="icon me-1"></file-text>
|
|
{{ app.output }}
|
|
</div>
|
|
<div v-if="app.cmd" class="text-truncate">
|
|
<terminal :size="14" class="icon me-1"></terminal>
|
|
{{ app.cmd }}
|
|
</div>
|
|
</div>
|
|
<div class="mt-auto d-flex gap-2">
|
|
<button class="btn btn-sm btn-primary flex-fill" @click="editApp(i)">
|
|
<edit :size="16" class="icon"></edit>
|
|
{{ $t('apps.edit') }}
|
|
</button>
|
|
<button class="btn btn-sm btn-danger" @click="showDeleteForm(i)">
|
|
<trash-2 :size="16" class="icon"></trash-2>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Empty State -->
|
|
<div v-else class="card">
|
|
<div class="card-body text-center py-5">
|
|
<p class="text-muted">{{ $t('apps.no_applications') }}</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="edit-form card mt-4" v-if="showEditForm">
|
|
<div class="card-body">
|
|
<!-- Application Name -->
|
|
<div class="mb-3">
|
|
<label for="appName" class="form-label">{{ $t('apps.app_name') }}</label>
|
|
<input type="text" class="form-control" id="appName" aria-describedby="appNameHelp" v-model="editForm.name" />
|
|
<div id="appNameHelp" class="form-text">{{ $t('apps.app_name_desc') }}</div>
|
|
</div>
|
|
<!-- output -->
|
|
<div class="mb-3">
|
|
<label for="appOutput" class="form-label">{{ $t('apps.output_name') }}</label>
|
|
<input type="text" class="form-control monospace" id="appOutput" aria-describedby="appOutputHelp"
|
|
v-model="editForm.output" />
|
|
<div id="appOutputHelp" class="form-text">{{ $t('apps.output_desc') }}</div>
|
|
</div>
|
|
<!-- prep-cmd -->
|
|
<Checkbox class="mb-3"
|
|
id="excludeGlobalPrep"
|
|
label="apps.global_prep_name"
|
|
desc="apps.global_prep_desc"
|
|
v-model="editForm['exclude-global-prep-cmd']"
|
|
default="true"
|
|
inverse-values
|
|
></Checkbox>
|
|
<div class="mb-3">
|
|
<label for="appName" class="form-label">{{ $t('apps.cmd_prep_name') }}</label>
|
|
<div class="form-text">{{ $t('apps.cmd_prep_desc') }}</div>
|
|
<div class="d-flex justify-content-start mb-3 mt-3" v-if="editForm['prep-cmd'].length === 0">
|
|
<button class="btn btn-success" @click="addPrepCmd">
|
|
<plus :size="18" class="icon"></plus>
|
|
{{ $t('apps.add_cmds') }}
|
|
</button>
|
|
</div>
|
|
<table class="table" v-if="editForm['prep-cmd'].length > 0">
|
|
<thead>
|
|
<tr>
|
|
<th scope="col">
|
|
<play :size="18" class="icon"></play>
|
|
{{ $t('_common.do_cmd') }}
|
|
</th>
|
|
<th scope="col">
|
|
<rotate-ccw :size="18" class="icon"></rotate-ccw>
|
|
{{ $t('_common.undo_cmd') }}
|
|
</th>
|
|
<th scope="col" v-if="platform === 'windows'">
|
|
<shield :size="18" class="icon"></shield>
|
|
{{ $t('_common.run_as') }}
|
|
</th>
|
|
<th scope="col"></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr v-for="(c, i) in editForm['prep-cmd']">
|
|
<td>
|
|
<input type="text" class="form-control monospace" v-model="c.do" />
|
|
</td>
|
|
<td>
|
|
<input type="text" class="form-control monospace" v-model="c.undo" />
|
|
</td>
|
|
<td v-if="platform === 'windows'" class="align-middle">
|
|
<Checkbox :id="'prep-cmd-admin-' + i"
|
|
label="_common.elevated"
|
|
desc=""
|
|
v-model="c.elevated"
|
|
></Checkbox>
|
|
</td>
|
|
<td class="align-middle">
|
|
<button class="btn btn-danger btn-sm ms-2" @click="deletePrepCmd(i)">
|
|
<trash-2 :size="16" class="icon"></trash-2>
|
|
</button>
|
|
<button class="btn btn-success btn-sm ms-2" @click="addPrepCmd">
|
|
<plus :size="16" class="icon"></plus>
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- detached -->
|
|
<div class="mb-3">
|
|
<label for="appName" class="form-label">{{ $t('apps.detached_cmds') }}</label>
|
|
<div v-for="(c,i) in editForm.detached" class="d-flex justify-content-between align-items-center my-2">
|
|
<input type="text" v-model="editForm.detached[i]" class="form-control monospace">
|
|
<button class="btn btn-danger btn-sm ms-2" @click="editForm.detached.splice(i,1)">
|
|
<trash-2 :size="16" class="icon"></trash-2>
|
|
</button>
|
|
<button class="btn btn-success btn-sm ms-2" @click="addDetached">
|
|
<plus :size="16" class="icon"></plus>
|
|
</button>
|
|
</div>
|
|
<div class="d-flex justify-content-start mb-3 mt-3" v-if="editForm.detached.length === 0">
|
|
<button class="btn btn-success" @click="addDetached">
|
|
<plus :size="18" class="icon"></plus>
|
|
{{ $t('apps.detached_cmds_add') }}
|
|
</button>
|
|
</div>
|
|
<div class="form-text">
|
|
{{ $t('apps.detached_cmds_desc') }}<br>
|
|
<b>{{ $t('_common.note') }}</b> {{ $t('apps.detached_cmds_note') }}
|
|
</div>
|
|
</div>
|
|
<!-- command -->
|
|
<div class="mb-3">
|
|
<label for="appCmd" class="form-label">{{ $t('apps.cmd') }}</label>
|
|
<input type="text" class="form-control monospace" id="appCmd" aria-describedby="appCmdHelp"
|
|
v-model="editForm.cmd" />
|
|
<div id="appCmdHelp" class="form-text">
|
|
{{ $t('apps.cmd_desc') }}<br>
|
|
<b>{{ $t('_common.note') }}</b> {{ $t('apps.cmd_note') }}
|
|
</div>
|
|
</div>
|
|
<!-- working dir -->
|
|
<div class="mb-3">
|
|
<label for="appWorkingDir" class="form-label">{{ $t('apps.working_dir') }}</label>
|
|
<input type="text" class="form-control monospace" id="appWorkingDir" aria-describedby="appWorkingDirHelp"
|
|
v-model="editForm['working-dir']" />
|
|
<div id="appWorkingDirHelp" class="form-text">{{ $t('apps.working_dir_desc') }}</div>
|
|
</div>
|
|
<!-- elevation -->
|
|
<Checkbox v-if="platform === 'windows'"
|
|
class="mb-3"
|
|
id="appElevation"
|
|
label="_common.run_as"
|
|
desc="apps.run_as_desc"
|
|
v-model="editForm.elevated"
|
|
default="false"
|
|
></Checkbox>
|
|
<!-- auto-detach -->
|
|
<Checkbox class="mb-3"
|
|
id="autoDetach"
|
|
label="apps.auto_detach"
|
|
desc="apps.auto_detach_desc"
|
|
v-model="editForm['auto-detach']"
|
|
default="true"
|
|
></Checkbox>
|
|
<!-- wait for all processes -->
|
|
<Checkbox class="mb-3"
|
|
id="waitAll"
|
|
label="apps.wait_all"
|
|
desc="apps.wait_all_desc"
|
|
v-model="editForm['wait-all']"
|
|
default="true"
|
|
></Checkbox>
|
|
<!-- exit timeout -->
|
|
<div class="mb-3">
|
|
<label for="exitTimeout" class="form-label">{{ $t('apps.exit_timeout') }}</label>
|
|
<input type="number" class="form-control monospace" id="exitTimeout" aria-describedby="exitTimeoutHelp"
|
|
v-model="editForm['exit-timeout']" min="0" placeholder="5" />
|
|
<div id="exitTimeoutHelp" class="form-text">{{ $t('apps.exit_timeout_desc') }}</div>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="appImagePath" class="form-label">{{ $t('apps.image') }}</label>
|
|
<div class="input-group">
|
|
<input type="text" class="form-control monospace" id="appImagePath" aria-describedby="appImagePathHelp"
|
|
v-model="editForm['image-path']" />
|
|
<button class="btn btn-secondary" type="button" data-bs-toggle="modal" data-bs-target="#coverFinderModal"
|
|
@click="showCoverFinder">
|
|
<search :size="18" class="icon"></search>
|
|
{{ $t('apps.find_cover') }}
|
|
</button>
|
|
</div>
|
|
<div id="appImagePathHelp" class="form-text">{{ $t('apps.image_desc') }}</div>
|
|
</div>
|
|
|
|
<!-- Cover Finder Modal -->
|
|
<div class="modal fade" id="coverFinderModal" tabindex="-1" aria-labelledby="coverFinderModalLabel" aria-hidden="true" ref="coverFinderModal">
|
|
<div class="modal-dialog modal-xl modal-dialog-scrollable modal-fullscreen-md-down">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="coverFinderModalLabel">
|
|
<span v-if="coverSearching">{{ $t('apps.searching_covers') }}</span>
|
|
<span v-else-if="coverCandidates.length > 0">{{ $t('apps.covers_found') }} ({{ coverCandidates.length }})</span>
|
|
<span v-else>{{ $t('apps.no_covers_found') }}</span>
|
|
</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<div class="mb-3">
|
|
<div class="input-group">
|
|
<input
|
|
type="text"
|
|
class="form-control"
|
|
v-model="coverSearchQuery"
|
|
:placeholder="editForm.name"
|
|
@keyup.enter="performCoverSearch"
|
|
/>
|
|
<button class="btn btn-primary" type="button" @click="performCoverSearch">
|
|
<search :size="18" class="icon"></search>
|
|
{{ $t('_common.search') }}
|
|
</button>
|
|
</div>
|
|
<div class="form-text mt-2">
|
|
<b>{{ $t('_common.note') }}</b> {{ $t('apps.cover_search_hint') }}
|
|
<a href="https://www.igdb.com/" target="_blank" rel="noopener noreferrer">IGDB</a>
|
|
</div>
|
|
</div>
|
|
<div class="cover-results" :class="{ busy: coverFinderBusy }">
|
|
<div class="row">
|
|
<div v-if="coverSearching" class="col-12 col-sm-6 col-lg-4 mb-3">
|
|
<div class="cover-container">
|
|
<div class="spinner-border" role="status">
|
|
<span class="visually-hidden">{{ $t('apps.loading') }}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div v-for="(cover,i) in coverCandidates" :key="'i'" class="col-12 col-sm-6 col-lg-3 mb-3"
|
|
@click="useCover(cover)">
|
|
<div class="cover-container result">
|
|
<img class="rounded" :src="cover.url" />
|
|
</div>
|
|
<label class="d-block text-nowrap text-center text-truncate">
|
|
{{cover.name}}
|
|
</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
|
|
<x :size="18" class="icon"></x>
|
|
{{ $t('_common.cancel') }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="env-hint alert alert-info">
|
|
<div class="form-text">
|
|
<h4>{{ $t('apps.env_vars_about') }}</h4>
|
|
{{ $t('apps.env_vars_desc') }}
|
|
</div>
|
|
<table class="env-table">
|
|
<tr>
|
|
<td><b>{{ $t('apps.env_var_name') }}</b></td>
|
|
<td><b></b></td>
|
|
</tr>
|
|
<tr>
|
|
<td style="font-family: monospace">SUNSHINE_APP_ID</td>
|
|
<td>{{ $t('apps.env_app_id') }}</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="font-family: monospace">SUNSHINE_APP_NAME</td>
|
|
<td>{{ $t('apps.env_app_name') }}</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="font-family: monospace">SUNSHINE_CLIENT_WIDTH</td>
|
|
<td>{{ $t('apps.env_client_width') }}</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="font-family: monospace">SUNSHINE_CLIENT_HEIGHT</td>
|
|
<td>{{ $t('apps.env_client_height') }}</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="font-family: monospace">SUNSHINE_CLIENT_FPS</td>
|
|
<td>{{ $t('apps.env_client_fps') }}</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="font-family: monospace">SUNSHINE_CLIENT_HDR</td>
|
|
<td>{{ $t('apps.env_client_hdr') }}</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="font-family: monospace">SUNSHINE_CLIENT_GCMAP</td>
|
|
<td>{{ $t('apps.env_client_gcmap') }}</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="font-family: monospace">SUNSHINE_CLIENT_HOST_AUDIO</td>
|
|
<td>{{ $t('apps.env_client_host_audio') }}</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="font-family: monospace">SUNSHINE_CLIENT_ENABLE_SOPS</td>
|
|
<td>{{ $t('apps.env_client_enable_sops') }}</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="font-family: monospace">SUNSHINE_CLIENT_AUDIO_CONFIGURATION</td>
|
|
<td>{{ $t('apps.env_client_audio_config') }}</td>
|
|
</tr>
|
|
</table>
|
|
<div class="form-text" v-if="platform === 'windows'"><b>{{ $t('apps.env_qres_example') }}</b>
|
|
<pre>cmd /C <{{ $t('apps.env_qres_path') }}>\QRes.exe /X:%SUNSHINE_CLIENT_WIDTH% /Y:%SUNSHINE_CLIENT_HEIGHT% /R:%SUNSHINE_CLIENT_FPS%</pre>
|
|
</div>
|
|
<div class="form-text" v-else-if="platform === 'freebsd' || platform === 'linux'"><b>{{ $t('apps.env_xrandr_example') }}</b>
|
|
<pre>sh -c "xrandr --output HDMI-1 --mode \"${SUNSHINE_CLIENT_WIDTH}x${SUNSHINE_CLIENT_HEIGHT}\" --rate ${SUNSHINE_CLIENT_FPS}"</pre>
|
|
</div>
|
|
<div class="form-text" v-else-if="platform === 'macos'"><b>{{ $t('apps.env_displayplacer_example') }}</b>
|
|
<pre>sh -c "displayplacer "id:<screenId> res:${SUNSHINE_CLIENT_WIDTH}x${SUNSHINE_CLIENT_HEIGHT} hz:${SUNSHINE_CLIENT_FPS} scaling:on origin:(0,0) degree:0""</pre>
|
|
</div>
|
|
<div class="form-text"><a
|
|
href="https://docs.lizardbyte.dev/projects/sunshine/latest/md_docs_2app__examples.html"
|
|
target="_blank">{{ $t('_common.see_more') }}</a></div>
|
|
</div>
|
|
<!-- Save buttons -->
|
|
<div class="d-flex">
|
|
<button @click="showEditForm = false" class="btn btn-secondary m-2">
|
|
<x :size="18" class="icon"></x>
|
|
{{ $t('_common.cancel') }}
|
|
</button>
|
|
<button class="btn btn-primary m-2" @click="save">
|
|
<save :size="18" class="icon"></save>
|
|
{{ $t('_common.save') }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="mt-4" v-else>
|
|
<button class="btn btn-primary" @click="newApp">
|
|
<layers-plus :size="18" class="icon"></layers-plus>
|
|
{{ $t('apps.add_new') }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
<script type="module">
|
|
import { createApp } from 'vue'
|
|
import { initApp } from './init'
|
|
import Navbar from './Navbar.vue'
|
|
import Checkbox from './Checkbox.vue'
|
|
import { Modal } from 'bootstrap/dist/js/bootstrap'
|
|
import {
|
|
Edit,
|
|
FileText,
|
|
LayersPlus,
|
|
Play,
|
|
Plus,
|
|
RotateCcw,
|
|
Save,
|
|
Search,
|
|
Shield,
|
|
Terminal,
|
|
Trash2,
|
|
X,
|
|
} from 'lucide-vue-next'
|
|
|
|
const app = createApp({
|
|
components: {
|
|
Navbar,
|
|
Checkbox,
|
|
Edit,
|
|
FileText,
|
|
LayersPlus,
|
|
Play,
|
|
Plus,
|
|
RotateCcw,
|
|
Save,
|
|
Search,
|
|
Shield,
|
|
Terminal,
|
|
Trash2,
|
|
X,
|
|
},
|
|
data() {
|
|
return {
|
|
apps: [],
|
|
showEditForm: false,
|
|
editForm: null,
|
|
detachedCmd: "",
|
|
coverSearching: false,
|
|
coverFinderBusy: false,
|
|
coverCandidates: [],
|
|
coverSearchQuery: "",
|
|
platform: "",
|
|
};
|
|
},
|
|
created() {
|
|
fetch("./api/apps")
|
|
.then((r) => r.json())
|
|
.then((r) => {
|
|
console.log(r);
|
|
this.apps = r.apps;
|
|
});
|
|
|
|
fetch("./api/config")
|
|
.then(r => r.json())
|
|
.then(r => this.platform = r.platform);
|
|
},
|
|
methods: {
|
|
newApp() {
|
|
this.editForm = {
|
|
name: "",
|
|
output: "",
|
|
cmd: "",
|
|
index: -1,
|
|
"exclude-global-prep-cmd": false,
|
|
elevated: false,
|
|
"auto-detach": true,
|
|
"wait-all": true,
|
|
"exit-timeout": 5,
|
|
"prep-cmd": [],
|
|
detached: [],
|
|
"image-path": ""
|
|
};
|
|
this.editForm.index = -1;
|
|
this.showEditForm = true;
|
|
},
|
|
editApp(id) {
|
|
this.editForm = JSON.parse(JSON.stringify(this.apps[id]));
|
|
this.editForm.index = id;
|
|
if (this.editForm["prep-cmd"] === undefined)
|
|
this.editForm["prep-cmd"] = [];
|
|
if (this.editForm["detached"] === undefined)
|
|
this.editForm["detached"] = [];
|
|
if (this.editForm["exclude-global-prep-cmd"] === undefined)
|
|
this.editForm["exclude-global-prep-cmd"] = false;
|
|
if (this.editForm["elevated"] === undefined && this.platform === 'windows') {
|
|
this.editForm["elevated"] = false;
|
|
}
|
|
if (this.editForm["auto-detach"] === undefined) {
|
|
this.editForm["auto-detach"] = true;
|
|
}
|
|
if (this.editForm["wait-all"] === undefined) {
|
|
this.editForm["wait-all"] = true;
|
|
}
|
|
if (this.editForm["exit-timeout"] === undefined) {
|
|
this.editForm["exit-timeout"] = 5;
|
|
}
|
|
this.showEditForm = true;
|
|
},
|
|
showDeleteForm(id) {
|
|
let resp = confirm(
|
|
"Are you sure to delete " + this.apps[id].name + "?"
|
|
);
|
|
if (resp) {
|
|
fetch("./api/apps/" + id, {
|
|
method: "DELETE",
|
|
headers: {
|
|
"Content-Type": "application/json"
|
|
},
|
|
}).then((r) => {
|
|
if (r.status === 200) document.location.reload();
|
|
});
|
|
}
|
|
},
|
|
addPrepCmd() {
|
|
let template = {
|
|
do: "",
|
|
undo: ""
|
|
};
|
|
|
|
if (this.platform === 'windows') {
|
|
template = { ...template, elevated: false };
|
|
}
|
|
|
|
this.editForm["prep-cmd"].push(template);
|
|
},
|
|
deletePrepCmd(index) {
|
|
this.editForm["prep-cmd"].splice(index, 1);
|
|
},
|
|
addDetached() {
|
|
this.editForm.detached.push("");
|
|
},
|
|
showCoverFinder() {
|
|
// Reset search state
|
|
this.coverCandidates = [];
|
|
this.coverSearchQuery = "";
|
|
|
|
// Perform initial search with app name
|
|
this.performCoverSearch();
|
|
},
|
|
performCoverSearch() {
|
|
this.coverSearching = true;
|
|
this.coverCandidates = [];
|
|
|
|
// Use search query if provided, otherwise fall back to app name
|
|
const searchTerm = this.coverSearchQuery.trim() || this.editForm["name"].toString();
|
|
|
|
function getSearchBucket(name) {
|
|
let bucket = name.substring(0, Math.min(name.length, 2)).toLowerCase().replaceAll(/[^a-z\d]/g, '');
|
|
if (!bucket) {
|
|
return '@';
|
|
}
|
|
return bucket;
|
|
}
|
|
|
|
function searchCovers(name) {
|
|
if (!name) {
|
|
return Promise.resolve([]);
|
|
}
|
|
let searchName = name.replaceAll(/\s+/g, '.').toLowerCase();
|
|
|
|
// Use raw.githubusercontent.com to avoid CORS issues as we migrate the CNAME
|
|
let dbUrl = "https://raw.githubusercontent.com/LizardByte/GameDB/gh-pages";
|
|
let bucket = getSearchBucket(name);
|
|
return fetch(`${dbUrl}/buckets/${bucket}.json`).then(function (r) {
|
|
if (!r.ok) throw new Error("Failed to search covers");
|
|
return r.json();
|
|
}).then(maps => Promise.all(Object.keys(maps).map(id => {
|
|
let item = maps[id];
|
|
if (item.name.replaceAll(/\s+/g, '.').toLowerCase().startsWith(searchName)) {
|
|
return fetch(`${dbUrl}/games/${id}.json`).then(function (r) {
|
|
return r.json();
|
|
}).catch(() => null);
|
|
}
|
|
return null;
|
|
}).filter(item => item)))
|
|
.then(results => results
|
|
.filter(item => item && item.cover && item.cover.url)
|
|
.map(game => {
|
|
const thumb = game.cover.url;
|
|
const dotIndex = thumb.lastIndexOf('.');
|
|
const slashIndex = thumb.lastIndexOf('/');
|
|
if (dotIndex < 0 || slashIndex < 0) {
|
|
return null;
|
|
}
|
|
const slug = thumb.substring(slashIndex + 1, dotIndex);
|
|
return {
|
|
name: game.name,
|
|
key: `igdb_${game.id}`,
|
|
url: `https://images.igdb.com/igdb/image/upload/t_cover_big/${slug}.jpg`,
|
|
saveUrl: `https://images.igdb.com/igdb/image/upload/t_cover_big_2x/${slug}.png`,
|
|
}
|
|
}).filter(item => item));
|
|
}
|
|
|
|
searchCovers(searchTerm)
|
|
.then(list => this.coverCandidates = list)
|
|
.finally(() => this.coverSearching = false);
|
|
},
|
|
useCover(cover) {
|
|
this.coverFinderBusy = true;
|
|
fetch("./api/covers/upload", {
|
|
method: "POST",
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
key: cover.key,
|
|
url: cover.saveUrl,
|
|
})
|
|
}).then(r => {
|
|
if (!r.ok) throw new Error("Failed to download covers");
|
|
return r.json();
|
|
}).then(body => {
|
|
this.editForm["image-path"] = body.path;
|
|
// Close the modal
|
|
const modalEl = this.$refs.coverFinderModal;
|
|
if (modalEl) {
|
|
const modal = Modal.getInstance(modalEl);
|
|
if (modal) {
|
|
modal.hide();
|
|
}
|
|
}
|
|
})
|
|
.finally(() => this.coverFinderBusy = false);
|
|
},
|
|
save() {
|
|
this.editForm["image-path"] = this.editForm["image-path"].toString().replace(/"/g, '');
|
|
fetch("./api/apps", {
|
|
method: "POST",
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(this.editForm),
|
|
}).then((r) => {
|
|
if (r.status === 200) document.location.reload();
|
|
});
|
|
},
|
|
handleImageError(event) {
|
|
// Hide the broken image and show placeholder instead
|
|
event.target.style.display = 'none';
|
|
const placeholder = event.target.nextElementSibling;
|
|
if (placeholder && placeholder.classList.contains('app-poster-placeholder')) {
|
|
placeholder.style.display = 'flex';
|
|
}
|
|
}
|
|
},
|
|
});
|
|
|
|
|
|
initApp(app);
|
|
</script>
|