mirror of
https://gitlab.com/futo-org/fcast.git
synced 2025-08-04 08:17:01 +00:00
Changed connection detection on window re-create
This commit is contained in:
parent
bff3440a8e
commit
9a7924ebce
7 changed files with 32 additions and 45 deletions
|
@ -18,20 +18,15 @@ if (TARGET === 'electron') {
|
|||
// @ts-ignore
|
||||
const electronAPI = __non_webpack_require__('electron');
|
||||
|
||||
// Since event is sent async during window startup, could fire off before or after renderer.js is loaded
|
||||
electronAPI.ipcRenderer.on('startup-storage-clear', () => {
|
||||
localStorage.clear();
|
||||
});
|
||||
|
||||
electronAPI.ipcRenderer.on("device-info", (_event, value: any) => {
|
||||
preloadData.deviceInfo = value;
|
||||
})
|
||||
|
||||
electronAPI.contextBridge.exposeInMainWorld('targetAPI', {
|
||||
onStartupStorageClear: (callback: any) => electronAPI.ipcRenderer.on('startup-storage-clear', callback),
|
||||
onDeviceInfo: (callback: any) => electronAPI.ipcRenderer.on("device-info", callback),
|
||||
onConnect: (callback: any) => electronAPI.ipcRenderer.on("connect", callback),
|
||||
onDisconnect: (callback: any) => electronAPI.ipcRenderer.on("disconnect", callback),
|
||||
onPing: (callback: any) => electronAPI.ipcRenderer.on("ping", callback),
|
||||
getDeviceInfo: () => preloadData.deviceInfo,
|
||||
});
|
||||
|
||||
|
@ -39,17 +34,17 @@ if (TARGET === 'electron') {
|
|||
} else if (TARGET === 'webOS') {
|
||||
try {
|
||||
preloadData = {
|
||||
onStartupStorageClearCb: () => { localStorage.clear(); },
|
||||
onDeviceInfoCb: () => { console.log('Main: Callback not set while fetching device info'); },
|
||||
onConnectCb: (_, value: any) => { console.log('Main: Callback not set while calling onConnect'); },
|
||||
onDisconnectCb: (_, value: any) => { console.log('Main: Callback not set while calling onDisconnect'); },
|
||||
onPingCb: (_, value: any) => { console.log('Main: Callback not set while calling onPing'); },
|
||||
};
|
||||
|
||||
window.targetAPI = {
|
||||
onStartupStorageClear: (callback: () => void) => preloadData.onStartupStorageClearCb = callback,
|
||||
onDeviceInfo: (callback: () => void) => preloadData.onDeviceInfoCb = callback,
|
||||
onConnect: (callback: (_, value: any) => void) => preloadData.onConnectCb = callback,
|
||||
onDisconnect: (callback: (_, value: any) => void) => preloadData.onDisconnectCb = callback,
|
||||
onPing: (callback: (_, value: any) => void) => preloadData.onPingCb = callback,
|
||||
getDeviceInfo: () => preloadData.deviceInfo,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -6,22 +6,19 @@ import { toast, ToastIcon } from '../components/Toast';
|
|||
const connectionStatusText = document.getElementById("connection-status-text");
|
||||
const connectionStatusSpinner = document.getElementById("connection-spinner");
|
||||
const connectionStatusCheck = document.getElementById("connection-check");
|
||||
let connections = JSON.parse(localStorage.getItem('connections')) ?? [];
|
||||
if (connections.length > 0) {
|
||||
connections.forEach(connection => {
|
||||
onConnect(connection);
|
||||
});
|
||||
}
|
||||
let connections = [];
|
||||
|
||||
window.targetAPI.onStartupStorageClear((_event, value: any) => {
|
||||
localStorage.clear();
|
||||
localStorage.setItem('connections', JSON.stringify(connections));
|
||||
// Window might be re-created while devices are still connected
|
||||
window.targetAPI.onPing((_event, value: any) => {
|
||||
if (connections.length === 0) {
|
||||
connections.push(value.id);
|
||||
onConnect(value.id);
|
||||
}
|
||||
});
|
||||
|
||||
window.targetAPI.onDeviceInfo(renderIPsAndQRCode);
|
||||
window.targetAPI.onConnect((_event, value: any) => {
|
||||
connections.push(value.id);
|
||||
localStorage.setItem('connections', JSON.stringify(connections));
|
||||
onConnect(value);
|
||||
});
|
||||
window.targetAPI.onDisconnect((_event, value: any) => {
|
||||
|
@ -29,7 +26,6 @@ window.targetAPI.onDisconnect((_event, value: any) => {
|
|||
const index = connections.indexOf(value.id);
|
||||
if (index != -1) {
|
||||
connections.splice(index, 1);
|
||||
localStorage.setItem('connections', JSON.stringify(connections));
|
||||
}
|
||||
|
||||
if (connections.length === 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue