From d91cf92e86af74dc21d5672f027e702ce138b39f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Dias?= Date: Wed, 23 Jun 2021 09:00:14 +0100 Subject: [PATCH] Transition to real server and some bug fixes --- appdashboard.js | 2 +- index.html | 2 +- v2/api/apiserver.js | 2 ++ v2/app.js | 2 +- v2/device/apphelperdevices.js | 44 ++++++++++++++++++++++------------- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/appdashboard.js b/appdashboard.js index 6c5ada6..7a62d89 100644 --- a/appdashboard.js +++ b/appdashboard.js @@ -366,7 +366,7 @@ export class AppDashboard extends App{ } try{ await doIt(); - }catch(error){ + }catch(error){ await ControlDialogOk.showAndWait({title:"Error Loading Join Desktop",text:`Couldn't load the app. (${error}). Please check your connection and try again.`,timeout:30000}) } } diff --git a/index.html b/index.html index 1ce2393..6fd678c 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ Join diff --git a/v2/api/apiserver.js b/v2/api/apiserver.js index e217de0..ef87cfa 100644 --- a/v2/api/apiserver.js +++ b/v2/api/apiserver.js @@ -39,6 +39,8 @@ const deleteAutorization = async (endpoint,parameters) => await del(`${JOIN_BASE export class ApiServer{ static async getDevices(){ const result = await getRegistration("listDevices"); + if(!result.success) throw Error(result.errorMessage); + return result.records; // const result = await gapi.client.registration.listDevices(); // const devicesRaw = result.result.records; diff --git a/v2/app.js b/v2/app.js index fd8cc91..3778e11 100644 --- a/v2/app.js +++ b/v2/app.js @@ -632,7 +632,7 @@ export class App{ return; } if(!this.myDeviceName){ - const confirmed = confirm("Do you want to register this browser as a Join device so you can interact with it remotely?\n\nPlease note that this is a beta feature and may not fully work yet.") + const confirmed = confirm("Do you want to register this browser as a Join device so you can interact with it remotely?") this.alreadyAskedRegistration = true; if(!confirmed) return; diff --git a/v2/device/apphelperdevices.js b/v2/device/apphelperdevices.js index d9c33ac..970de54 100644 --- a/v2/device/apphelperdevices.js +++ b/v2/device/apphelperdevices.js @@ -126,25 +126,37 @@ export class AppHelperDevices extends AppHelperBase{ await app.updateDevice(device); } async loadDevicesFromServer(){ + app.controlTop.loading = true; await app.loadJoinApis(); - const devices = new Devices(await ApiServer.getDevices()); - const existing = await this.getDevices(); - if(existing){ - existing.transferSockets(devices); - } - await this.refreshDevices(devices); - await this.updateDBDevices(devices); - if(devices.length > 0){ - UtilDOM.show(this.controlCommands); - } - await devices.testLocalNetworkDevices({allowUnsecureContent:app.allowUnsecureContent,token:await app.getAuthToken()}); - await this.refreshDevices(devices); - app.controlTop.loading = false; + try{ + const devicesFromServer = await ApiServer.getDevices(); + const devices = new Devices(devicesFromServer); + const existing = await this.getDevices(); + if(existing){ + existing.transferSockets(devices); + } + await this.refreshDevices(devices); + await this.updateDBDevices(devices); + if(devices.length > 0){ + UtilDOM.show(this.controlCommands); + } + await devices.testLocalNetworkDevices({allowUnsecureContent:app.allowUnsecureContent,token:await app.getAuthToken()}); + await this.refreshDevices(devices); + app.controlTop.loading = false; + + // await app.checkConnectedClients(); + EventBus.post(devices); + return devices; - // await app.checkConnectedClients(); - EventBus.post(devices); - return devices; + }catch(error){ + + const {ControlDialogOk} = await import("../dialog/controldialog.js"); + await ControlDialogOk.showAndWait({title:"Error Loading Join Desktop",text:`Seems like your user is no longer authenticated. Will now sign out so you can sign in again.`,timeout:30000}) + const googleAccount = await app.googleAccount; + await googleAccount.signOut(); + return new Devices(); + } } async onConnectViaLocalNetworkSuccess(){ await this.refreshDevices();