1
0
Fork 0
mirror of https://gitlab.com/futo-org/fcast.git synced 2025-08-06 01:02:49 +00:00

Added toasts and UI update on device connection

This commit is contained in:
Michael Hollister 2025-01-06 20:35:57 -06:00
parent 5328087d64
commit 3142709d7f
17 changed files with 640 additions and 121 deletions

View file

@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { preloadData } from 'common/main/Preload';
import { toast, ToastIcon } from 'common/components/Toast';
enum RemoteKeyCode {
Stop = 413,
@ -10,75 +11,175 @@ enum RemoteKeyCode {
Back = 461,
}
const serviceId = 'com.futo.fcast.receiver.service';
try {
const serviceId = 'com.futo.fcast.receiver.service';
const playService = window.webOS.service.request(`luna://${serviceId}/`, {
method:"play",
parameters: {},
onSuccess: (message: any) => {
if (message.value.subscribed === true) {
console.log('Main: Registered play handler with service');
}
else {
if (message.value !== undefined && message.value.playData !== undefined) {
console.log(`Main: Playing ${JSON.stringify(message)}`);
preloadData.getDeviceInfoService.cancel();
playService.cancel();
// WebOS 22 and earlier does not work well using the history API,
// so manually handling page navigation...
// history.pushState({}, '', '../main_window/index.html');
window.open('../player/index.html');
const startupStorageClearService = window.webOS.service.request(`luna://${serviceId}/`, {
method:"startup-storage-clear",
parameters: {},
onSuccess: (message: any) => {
if (message.value.subscribed === true) {
console.log('Main: Registered startup-storage-clear handler with service');
}
else {
preloadData.onStartupStorageClearCb();
}
},
onFailure: (message: any) => {
console.error(`Main: startup-storage-clear ${JSON.stringify(message)}`);
toast(`Main: startup-storage-clear ${JSON.stringify(message)}`, ToastIcon.ERROR);
},
subscribe: true,
resubscribe: true
});
const toastService = window.webOS.service.request(`luna://${serviceId}/`, {
method:"toast",
parameters: {},
onSuccess: (message: any) => {
if (message.value.subscribed === true) {
console.log('Main: Registered toast handler with service');
}
else {
toast(message.value.message, message.value.icon, message.value.duration);
}
},
onFailure: (message: any) => {
console.error(`Main: toast ${JSON.stringify(message)}`);
toast(`Main: toast ${JSON.stringify(message)}`, ToastIcon.ERROR);
},
subscribe: true,
resubscribe: true
});
const onConnectService = window.webOS.service.request(`luna://${serviceId}/`, {
method:"connect",
parameters: {},
onSuccess: (message: any) => {
if (message.value.subscribed === true) {
console.log('Main: Registered connect handler with service');
}
else {
preloadData.onConnectCb(null, message.value);
}
},
onFailure: (message: any) => {
console.error(`Main: connect ${JSON.stringify(message)}`);
toast(`Main: connect ${JSON.stringify(message)}`, ToastIcon.ERROR);
},
subscribe: true,
resubscribe: true
});
const onDisconnectService = window.webOS.service.request(`luna://${serviceId}/`, {
method:"disconnect",
parameters: {},
onSuccess: (message: any) => {
if (message.value.subscribed === true) {
console.log('Main: Registered disconnect handler with service');
}
else {
preloadData.onDisconnectCb(null, message.value);
}
},
onFailure: (message: any) => {
console.error(`Main: disconnect ${JSON.stringify(message)}`);
toast(`Main: disconnect ${JSON.stringify(message)}`, ToastIcon.ERROR);
},
subscribe: true,
resubscribe: true
});
const playService = window.webOS.service.request(`luna://${serviceId}/`, {
method:"play",
parameters: {},
onSuccess: (message: any) => {
if (message.value.subscribed === true) {
console.log('Main: Registered play handler with service');
}
else {
if (message.value !== undefined && message.value.playData !== undefined) {
console.log(`Main: Playing ${JSON.stringify(message)}`);
preloadData.getDeviceInfoService.cancel();
startupStorageClearService.cancel();
toastService.cancel();
onConnectService.cancel();
onDisconnectService.cancel();
playService.cancel();
// WebOS 22 and earlier does not work well using the history API,
// so manually handling page navigation...
// history.pushState({}, '', '../main_window/index.html');
window.open('../player/index.html');
}
}
},
onFailure: (message: any) => {
console.error(`Main: play ${JSON.stringify(message)}`);
toast(`Main: play ${JSON.stringify(message)}`, ToastIcon.ERROR);
},
subscribe: true,
resubscribe: true
});
const launchHandler = (args: any) => {
// args don't seem to be passed in via event despite what documentation says...
const params = window.webOSDev.launchParams();
console.log(`Main: (Re)launching FCast Receiver with args: ${JSON.stringify(params)}`);
const lastTimestamp = localStorage.getItem('lastTimestamp');
if (params.playData !== undefined && params.timestamp != lastTimestamp) {
localStorage.setItem('lastTimestamp', params.timestamp);
if (preloadData.getDeviceInfoService !== undefined) {
preloadData.getDeviceInfoService.cancel();
}
if (startupStorageClearService !== undefined) {
startupStorageClearService.cancel();
}
if (toastService !== undefined) {
toastService.cancel();
}
if (onConnectService !== undefined) {
onConnectService.cancel();
}
if (onDisconnectService !== undefined) {
onDisconnectService.cancel();
}
if (playService !== undefined) {
playService.cancel();
}
// WebOS 22 and earlier does not work well using the history API,
// so manually handling page navigation...
// history.pushState({}, '', '../main_window/index.html');
window.open('../player/index.html');
}
},
onFailure: (message: any) => {
console.error(`Main: play ${JSON.stringify(message)}`);
},
subscribe: true,
resubscribe: true
});
};
const launchHandler = (args: any) => {
// args don't seem to be passed in via event despite what documentation says...
const params = window.webOSDev.launchParams();
console.log(`Main: (Re)launching FCast Receiver with args: ${JSON.stringify(params)}`);
document.addEventListener('webOSLaunch', (ags) => { launchHandler(ags)});
document.addEventListener('webOSRelaunch', (ags) => { launchHandler(ags)});
const lastTimestamp = localStorage.getItem('lastTimestamp');
if (params.playData !== undefined && params.timestamp != lastTimestamp) {
localStorage.setItem('lastTimestamp', params.timestamp);
if (preloadData.getDeviceInfoService !== undefined) {
preloadData.getDeviceInfoService.cancel();
// Cannot go back to a state where user was previously casting a video, so exit.
// window.onpopstate = () => {
// window.webOS.platformBack();
// };
document.addEventListener('keydown', (event: any) => {
// console.log("KeyDown", event);
switch (event.keyCode) {
// WebOS 22 and earlier does not work well using the history API,
// so manually handling page navigation...
case RemoteKeyCode.Back:
window.webOS.platformBack();
break;
default:
break;
}
if (playService !== undefined) {
playService.cancel();
}
// WebOS 22 and earlier does not work well using the history API,
// so manually handling page navigation...
// history.pushState({}, '', '../main_window/index.html');
window.open('../player/index.html');
}
};
document.addEventListener('webOSLaunch', (ags) => { console.log('lunch'); launchHandler(ags)});
document.addEventListener('webOSRelaunch', (ags) => { console.log('relun'); launchHandler(ags)});
// Cannot go back to a state where user was previously casting a video, so exit.
// window.onpopstate = () => {
// window.webOS.platformBack();
// };
document.addEventListener('keydown', (event: any) => {
// console.log("KeyDown", event);
switch (event.keyCode) {
// WebOS 22 and earlier does not work well using the history API,
// so manually handling page navigation...
case RemoteKeyCode.Back:
window.webOS.platformBack();
break;
default:
break;
}
});
});
}
catch (err) {
console.error(`Main: preload ${JSON.stringify(err)}`);
toast(`Main: preload ${JSON.stringify(err)}`, ToastIcon.ERROR);
}

View file

@ -8,7 +8,6 @@
<link rel="stylesheet" href="../assets/fonts/inter.css" />
<link rel="stylesheet" href="./common.css" />
<link rel="stylesheet" href="./style.css" />
<script src="./preload.js"></script>
</head>
<body>
@ -29,8 +28,9 @@
</div>
<div id="connection-status">
<div id="waiting-for-connection" class="non-selectable">Waiting for a connection</div>
<div id="spinner" class="lds-ring"><div></div><div></div><div></div><div></div></div>
<div id="connection-status-text" class="non-selectable">Waiting for a connection</div>
<div id="connection-spinner" class="lds-ring"><div></div><div></div><div></div><div></div></div>
<div id="connection-check"><div id="connection-check-mark"></div></div>
</div>
</div>
<div id="detail-view" class="card">
@ -46,9 +46,14 @@
</div>
</div>
<div id="toast-notification">
<div id="toast-icon"></div>
<div id="toast-text"></div>
</div>
<div id="window-can-be-closed" class="non-selectable">App will continue to listen for connections when suspended in the background</div>
</div>
</div>
<script src="./preload.js"></script>
<script src="./renderer.js"></script>
</body>

View file

@ -68,3 +68,24 @@
color: white;
padding-right: 20px;
}
#connection-check {
width: 104px;
height: 104px;
}
#toast-notification {
gap: unset;
top: -250px;
}
#toast-icon {
width: 88px;
height: 88px;
margin-right: 20px;
}
#toast-text {
font-family: InterRegular;
font-size: 28px;
}