Launch Playlet from web app

This commit is contained in:
Brahim Hadriche committed 2023-11-14 18:49:17 -05:00
1 parent d65f930247
commit 2a57cc99c7
4 files changed
+35 -7

No files matched your search

+6
View File
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
- Playlet logo in web app is clickable, and launches app if not already on
## [0.16.0] - 2023-11-13 ## [0.16.0] - 2023-11-13
### Added ### Added
@@ -0,0 +1,10 @@
import { getIp } from "./Host";
export class ExternalControlProtocol {
static async launchApp(appId) {
return fetch(`http://${getIp()}:8060/launch/${appId}`, {
method: 'POST',
body: '',
})
}
}
+6 -1
View File
@@ -3,4 +3,9 @@ function getHost() {
return urlSearchParams.get('host') ?? window.location.host return urlSearchParams.get('host') ?? window.location.host
} }
export { getHost } function getIp() {
const host = getHost()
return host.split(':')[0]
}
export { getHost, getIp }
+13 -6
View File
@@ -3,6 +3,7 @@
import playletLogoLight from "assets/logo-light.svg"; import playletLogoLight from "assets/logo-light.svg";
import UserIcon from "assets/user.svg.svelte"; import UserIcon from "assets/user.svg.svelte";
import { PlayletApi } from "lib/Api/PlayletApi"; import { PlayletApi } from "lib/Api/PlayletApi";
import { ExternalControlProtocol } from "lib/Api/ExternalControlProtocol";
import { appThemeStore, playletStateStore } from "lib/Stores"; import { appThemeStore, playletStateStore } from "lib/Stores";
import ThemeSelect from "lib/ThemeToggle.svelte"; import ThemeSelect from "lib/ThemeToggle.svelte";
@@ -12,10 +13,14 @@
let currentInstance; let currentInstance;
let loggedInInstance; let loggedInInstance;
let username; let username;
let appId = "693751";
playletStateStore.subscribe((value) => { playletStateStore.subscribe((value) => {
version = value?.app?.lib_version ?? ""; version = value?.app?.lib_version ?? "";
if (value?.app?.id === "dev") { if (value?.app?.id) {
appId = value?.app?.id;
}
if (appId === "dev") {
version += "-dev"; version += "-dev";
} }
if ( if (
@@ -49,11 +54,13 @@
<div class="navbar bg-base-100 sticky top-0 z-40"> <div class="navbar bg-base-100 sticky top-0 z-40">
<div class="flex-1"> <div class="flex-1">
<img <button on:click={() => ExternalControlProtocol.launchApp(appId)}>
src={$appThemeStore === "dark" ? playletLogoDark : playletLogoLight} <img
class="h-8" src={$appThemeStore === "dark" ? playletLogoDark : playletLogoLight}
alt="Playlet Logo" class="h-8"
/> alt="Playlet Logo"
/>
</button>
<h4 class="label brightness-75">{version}</h4> <h4 class="label brightness-75">{version}</h4>
</div> </div>
<div class="flex-none"> <div class="flex-none">