From 1c95e41c8ae458ecd507df279913495673693960 Mon Sep 17 00:00:00 2001 From: Yeon Vinzenz Varapragasam Date: Mon, 29 Jan 2024 23:54:17 +0100 Subject: [PATCH] Fix Login redirect --- public/app/handlers.js | 7 ++++++- src/App.tsx | 7 +++++-- src/components/Bars/BarTop.tsx | 7 +++++-- src/pages/Login/LoginRedirect.tsx | 5 ++++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/public/app/handlers.js b/public/app/handlers.js index 70d1e343..2052ff51 100644 --- a/public/app/handlers.js +++ b/public/app/handlers.js @@ -1,4 +1,4 @@ -const { app, shell } = require('electron') +const { app, shell, BrowserWindow } = require('electron') const path = require('path') const { generateMfaQr, handleVerifyOTP } = require('./otp.js') const { coreParams, isCC, defaultCoreParams, store } = require('./core.js') @@ -12,6 +12,11 @@ const handlers = async (wind, subprocesses, event, parameters) => { case 'verify_otp': handleVerifyOTP(event, parameters) break + case 'get-all-windows': + const allWIndows = BrowserWindow.getAllWindows() + console.log('allWIndows', allWIndows) + wind.webContents.send('fromMain', ['all-windows', allWIndows]) + break case 'generate-mfa-qr': generateMfaQr(event, parameters) break diff --git a/src/App.tsx b/src/App.tsx index 5d711d1c..0f7d4643 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -77,8 +77,8 @@ export default function App() { 'padding: 3px 5px; border-radius: 5px; color: #ffffff; background-color: #038fc7;' ) if (isElectron()) { - ;(window as any).api.send('toMain', { command: 'get-platform' }) - ;(window as any).api.send('toMain', { command: 'get-core-params' }) + ;(window as any)?.api?.send('toMain', { command: 'get-platform' }) + ;(window as any)?.api?.send('toMain', { command: 'get-core-params' }) } }, []) ;(window as any).api?.receive('fromMain', (parameters: any) => { @@ -109,6 +109,9 @@ export default function App() { if (parameters === 'clear-frontend') { deleteFrontendConfig() } + if (parameters === 'all-windows') { + console.log('all-windows', parameters[1]) + } }) useEffect(() => { diff --git a/src/components/Bars/BarTop.tsx b/src/components/Bars/BarTop.tsx index 00b0c7be..e6975806 100644 --- a/src/components/Bars/BarTop.tsx +++ b/src/components/Bars/BarTop.tsx @@ -185,7 +185,7 @@ const TopBar = () => { const updateNotificationInterval = useStore( (state) => state.updateNotificationInterval ) - + const isCreator = localStorage.getItem('ledfx-cloud-role') === 'creator' const invisible = () => { switch (pathname.split('/')[1]) { case 'device': @@ -431,7 +431,7 @@ const TopBar = () => { Change Host - {isCC && ( + {isCC && isCreator && ( @@ -484,6 +484,9 @@ const TopBar = () => { '_blank', 'noopener,noreferrer' ) + setTimeout(() => { + window.location.reload() + }, 5000) } }} > diff --git a/src/pages/Login/LoginRedirect.tsx b/src/pages/Login/LoginRedirect.tsx index 510c3169..63238cef 100644 --- a/src/pages/Login/LoginRedirect.tsx +++ b/src/pages/Login/LoginRedirect.tsx @@ -1,6 +1,7 @@ import { useEffect, useState } from 'react' import { useNavigate, useLocation, useParams } from 'react-router-dom' import axios from 'axios' +import isElectron from 'is-electron' const cloud = axios.create({ baseURL: 'https://strapi.yeonv.com' @@ -46,7 +47,9 @@ const LoginRedirect = () => { 'username' )}. You will be redirected in a few seconds...` ) - setTimeout(() => history('/devices'), 2000) // Redirect to homepage after 3 sec + setTimeout(() => { + return isElectron() ? window.close() : history('/devices') + }, 2000) }) .catch((err) => { // eslint-disable-next-line no-console