@@ -5,58 +5,158 @@ import { listen } from "@tauri-apps/api/event";
55import { process } from " @tauri-apps/api" ;
66import { invoke } from " @tauri-apps/api/tauri" ;
77
8- let iframeSrc = ref (" loading.html" );
9- let debug = ref (true );
8+ let iframeSrc = ref (" /loading.html" );
9+ let debugMode = ref (false );
10+ let configMode = ref (false );
1011let squeezeliteCommand: Command | null = null ;
1112let squeezeliteProcess: Child | null = null ;
12- let clientName = " Lyrion Minim" ;
13+ let clientName = ref (" Lyrion Minim" );
14+ let serverUrl = ref (" " );
1315let pid = ref (0 );
1416
1517// Quite menu item clicked
1618listen (" quit" , async () => {
1719 await stopSqueezelite ();
18- process .exit (0 ).then (console .log ).catch (console .error ).finally (console .log );
20+ process .exit (0 )
21+ .then (console .log )
22+ .catch (console .error )
23+ .finally (console .log );
1924});
2025
2126// Debug menu item clicked
2227listen (" debug" , async () => {
23- debug .value = ! debug .value ;
28+ debugMode .value = ! debugMode .value ;
29+ });
30+
31+ // Debug menu item clicked
32+ listen (" config" , async () => {
33+ configMode .value = ! configMode .value ;
2434});
2535
2636async function startSqueezelite() {
37+ console .log (' Starting squeezelite' );
2738 // Don't start it twice!
28- if (squeezeliteCommand !== null ) {
39+ if (squeezeliteProcess !== null ) {
2940 return ;
3041 }
3142
32- squeezeliteCommand = Command .sidecar (" binaries/squeezelite" , [" -n" , clientName ]);
43+ squeezeliteCommand = Command .sidecar (" binaries/squeezelite" , [" -n" , clientName . value , " -M " , " SqueezeLite " + getOS () ]);
3344 squeezeliteProcess = await squeezeliteCommand .spawn ();
3445 pid .value = squeezeliteProcess .pid ;
3546 console .log (' Squeezelite process started ' + squeezeliteProcess .pid );
3647}
3748
3849async function stopSqueezelite() {
3950 if (squeezeliteProcess !== null ) {
51+ console .log (' Stopping squeezelite' );
4052 await squeezeliteProcess .kill ();
4153 console .log (' Squeezelite process stopped ' + squeezeliteProcess .pid );
4254 squeezeliteProcess = null ;
4355 }
4456}
4557
58+ function getOS() {
59+ const platform = window .navigator ?.userAgentData ?.platform || window .navigator .platform ,
60+ macosPlatforms = [' macOS' , ' Macintosh' , ' MacIntel' , ' MacPPC' , ' Mac68K' ],
61+ windowsPlatforms = [' Win32' , ' Win64' , ' Windows' , ' WinCE' ];
62+ let os = null ;
63+
64+ if (macosPlatforms .indexOf (platform ) !== - 1 ) {
65+ os = ' Mac' ;
66+ } else if (windowsPlatforms .indexOf (platform ) !== - 1 ) {
67+ os = ' Windows' ;
68+ } else if (/ Linux/ .test (platform )) {
69+ os = ' Linux' ;
70+ } else {
71+ os = ' ' ;
72+ }
73+
74+ return os ;
75+ }
76+
4677async function init() {
78+ console .log (' Init' );
4779 await startSqueezelite ();
48- let lmsServer = await invoke (" detect_lms_server" );
49- iframeSrc .value = " http://" + lmsServer + " /Material/now-playing?player=" + clientName ;
80+ serverUrl .value = await invoke (" detect_lms_server" );
81+ showPlayer ();
82+ }
83+
84+ function showPlayer() {
85+ iframeSrc .value = " http://" + serverUrl .value + " /Material/now-playing?player=" + clientName .value + " &layout=mobile" ;
5086}
5187
88+ async function saveConfig() {
89+ // await invoke("save_config", {
90+ // clientName: clientName.value,
91+ // serverUrl: serverUrl.value
92+ // });
93+ console .log (clientName .value );
94+ console .log (serverUrl .value );
95+ await stopSqueezelite ();
96+ await startSqueezelite ();
97+ showPlayer ();
98+ configMode .value = false ;
99+ }
52100
53101init ();
102+ /**
103+ Config planning:
54104
105+ LMS Server:
106+ - Auto detect
107+ - Manually set
108+
109+ Squeezelite:
110+ - Client Name (on change, restart squeezelite)
111+ - Auto start / stop
112+ - Stop button
113+ - Start button
114+ - Show current status (including PID)
115+
116+ */
55117 </script >
56118
57119<template >
58- <iframe :src =" iframeSrc" scrolling =" no" ></iframe >
59- <div id =" debug" v-show =" debug" >Pid: {{pid}}<br > URL: {{iframeSrc}}</div >
120+ <iframe :src =" iframeSrc" scrolling =" no" v-show =" !configMode" ></iframe >
121+
122+ <div id =" config" v-show =" configMode" class =" container" style =" margin-top : 2em " >
123+
124+ <div class =" row container" style =" gap : 2em ;" >
125+
126+ <div class =" s12 m6 center" >
127+ <img style =" max-width : 20% ; height :auto " src =" /images/lyrion-logo.png" >
128+ <h4 >Lyrion Minim</h4 >
129+
130+ <h5 >Configuration</h5 >
131+ </div >
132+
133+ <div class =" s12 m6 input-field outlined" >
134+ <input id =" clientName" v-model =" clientName" type =" text" placeholder =" Lyrion Minim" maxlength =" 20" >
135+ <label for =" clientName" >Client Name</label >
136+ <span class =" supporting-text" >The name you want to give this client in Lyrion Music Server</span >
137+ </div >
138+
139+ <div class =" s12 m6 input-field outlined" >
140+ <input id =" serverUrl" type =" text" v-model =" serverUrl" placeholder =" http://" maxlength =" 20" >
141+ <label for =" serverUrl" >Server Base URL</label >
142+ <span class =" supporting-text" >Override the auto-detected servere URL. Format: host:port</span >
143+ </div >
144+
145+ <div class =" s12 m6 center" >
146+ <button class =" btn waves-effect waves-light blue-grey" name =" action" @click =" saveConfig" >Save and Continue
147+ <i class =" material-icons right" >music_note</i >
148+ </button >
149+ </div >
150+
151+ </div >
152+
153+ </div >
154+
155+ <div id =" debug" v-show =" debugMode" >
156+ Pid: {{pid}}<br >
157+ URL: {{iframeSrc}}
158+ </div >
159+
60160</template >
61161
62162<style >
@@ -69,20 +169,14 @@ html, body, #app {
69169 overflow : hidden ;
70170 border-radius : 0.8em ;
71171}
72- iframe , #config , #splash {
172+ iframe , #config {
73173 width : 100% ;
74174 height : 100% ;
75175 border : none ;
76176 padding : 0 ;
77177 margin : 0 ;
78178 overflow : hidden ;
79179}
80- #config , #splash {
81- padding : 2em ;
82- background-color : black ;
83- opacity : 0.85 ;
84- color : white ;
85- }
86180input {
87181 color :white ;
88182}
@@ -94,5 +188,6 @@ input {
94188 color : white ;
95189 font-size : 0.7em ;
96190 z-index : 9 ;
191+ overflow : hidden ;
97192}
98193 </style >
0 commit comments