Add Windows GUI
- mediahive/winmain.py: pywebview launcher with threaded uvicorn backend, - scripts/winbuild.py: build script — downloads ffmpeg, runs PyInstaller, makes zip - mediahive/config.py: TOML config persistence in %APPDATA%/mediahive/ - server.py: POST /api/change-folder switches media root - showreel.py: suppress console windows for ffmpeg subprocesses on Windows - protocol.py: add ChangeFolderRequest struct
This commit is contained in:
@@ -87,3 +87,28 @@ export function getCoverUrl(coverPath: string | null): string {
|
||||
|
||||
return `/api/media${encodedPath}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke the native OS folder picker via pywebview, then switch the server's
|
||||
* media folder in-place and reload the page. Only works inside the packaged
|
||||
* desktop app.
|
||||
*/
|
||||
export async function pickFolderAndRestart(): Promise<void> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const api = (window as any).pywebview?.api;
|
||||
if (!api) return;
|
||||
const folder: string | null = await api.pick_folder();
|
||||
if (!folder) return;
|
||||
const res = await fetch('/api/change-folder', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ folder }),
|
||||
});
|
||||
if (res.ok) {
|
||||
// Give the server a moment to complete the background folder switch before reloading
|
||||
setTimeout(() => window.location.reload(), 500);
|
||||
} else {
|
||||
const err = await res.json().catch(() => ({ detail: res.statusText }));
|
||||
alert(`Failed to change folder: ${err.detail || res.statusText}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,18 @@
|
||||
@keydown.escape="handleEscape"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="isDesktopApp" class="header-settings">
|
||||
<button
|
||||
class="header-settings-btn"
|
||||
title="Change media folder"
|
||||
@click="changeFolder"
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
</template>
|
||||
|
||||
@@ -64,6 +76,7 @@ import { ref, watch, computed, onMounted, onUnmounted } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { navAttrs } from '../composables/useKeyboardNavigation';
|
||||
import logoUrl from '../assets/mediahive.webp';
|
||||
import { pickFolderAndRestart } from '../api';
|
||||
|
||||
const props = defineProps<{
|
||||
currentView: 'movies' | 'series';
|
||||
@@ -82,6 +95,18 @@ const router = useRouter();
|
||||
const searchInputRef = ref<HTMLInputElement | null>(null);
|
||||
const localSearch = ref(props.searchQuery);
|
||||
|
||||
// True only when running inside the packaged pywebview desktop app.
|
||||
// pywebview injects window.pywebview asynchronously, so we listen for the
|
||||
// 'pywebviewready' event rather than checking at component creation time.
|
||||
const isDesktopApp = ref(typeof (window as any).pywebview !== 'undefined');
|
||||
function _onPywebviewReady() { isDesktopApp.value = true; }
|
||||
window.addEventListener('pywebviewready', _onPywebviewReady, { once: true });
|
||||
onUnmounted(() => window.removeEventListener('pywebviewready', _onPywebviewReady));
|
||||
|
||||
async function changeFolder() {
|
||||
await pickFolderAndRestart();
|
||||
}
|
||||
|
||||
// Check if we're on a detail page
|
||||
const isDetailPage = computed(() => {
|
||||
return props.position === 'after-movie-header' || props.position === 'after-series-hero';
|
||||
|
||||
@@ -152,6 +152,28 @@ html, body {
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.header-settings {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.header-settings-btn {
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: var(--text-secondary);
|
||||
cursor: pointer;
|
||||
padding: 6px;
|
||||
border-radius: 4px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
transition: color var(--transition-fast);
|
||||
}
|
||||
|
||||
.header-settings-btn:hover {
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.search-input {
|
||||
background: rgba(20, 20, 20, 0.9);
|
||||
border: 2px solid var(--border-color);
|
||||
|
||||
Reference in New Issue
Block a user