From a958f53edc74038a33ce317b86b5db0511d0d024 Mon Sep 17 00:00:00 2001 From: Andrew Gundersen Date: Thu, 11 Feb 2021 15:32:00 -0600 Subject: [PATCH] moving splash code from components to views --- src/background/session.ts | 11 ++++ src/components/login/index.vue | 95 --------------------------------- src/components/splash/index.vue | 73 ------------------------- src/router.ts | 7 +++ src/views/splash.vue | 61 ++++++++++++++++++++- 5 files changed, 77 insertions(+), 170 deletions(-) delete mode 100644 src/components/login/index.vue delete mode 100644 src/components/splash/index.vue diff --git a/src/background/session.ts b/src/background/session.ts index 6fb80eb..80a74aa 100644 --- a/src/background/session.ts +++ b/src/background/session.ts @@ -32,15 +32,20 @@ let auth = false; const authSession = async (_event, payload: string | UserCreds | null): Promise => { return new Promise((resolve, reject) => { + console.log('authenticating...'); + backgroundMitt.on('auth-res', (res: string) => { + if (res === 'locked') { reject(res); } else { auth = true; resolve(res); } + }); + if (!payload) { socket.send('no-token'); } else if (typeof payload === 'string' || payload instanceof String) { @@ -74,7 +79,10 @@ export const sendMessage = (content: TextMessage | Buffer) => { } } +// Run every time we want to connect to backend. export const initSession = () => { + + // Close existing sockets. if (socket) { socket.removeAllListeners(); socket.terminate(); @@ -82,6 +90,7 @@ export const initSession = () => { success = false; } + // Init new socket. socket = new WebSocket(`${ip}:${port}`); socket.binaryType = 'arraybuffer'; @@ -89,6 +98,7 @@ export const initSession = () => { ipcMain.removeHandler('auth-user'); // avoid setting duplicate handlers ipcMain.handle('auth-user', authSession); + // Connect to the backend. socket.on('open', () => { console.log('Success! Connected to Crimata Servers.'); @@ -101,6 +111,7 @@ export const initSession = () => { }); + // Handle for failed connect, try again. socket.on('error', (_e) => { console.log('ERROR: Failed to connect.'); socket.removeAllListeners(); diff --git a/src/components/login/index.vue b/src/components/login/index.vue deleted file mode 100644 index c75d625..0000000 --- a/src/components/login/index.vue +++ /dev/null @@ -1,95 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/components/splash/index.vue b/src/components/splash/index.vue deleted file mode 100644 index 3b0a133..0000000 --- a/src/components/splash/index.vue +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - diff --git a/src/router.ts b/src/router.ts index f8aa2bf..eedf589 100644 --- a/src/router.ts +++ b/src/router.ts @@ -5,12 +5,19 @@ import { RouteRecordRaw } from "vue-router"; import Home from "@/views/home.vue"; +import Splash from "@/views/splash.vue"; import { useAuth } from '@/modules/auth'; // Define the routes (/*) for the app here. const routes: Array = [ { path: "/", + name: "splash", + component: Splash, + meta: { requiresAuth: false }, + }, + { + path: "/home", name: "home", component: Home, meta: { requiresAuth: true }, diff --git a/src/views/splash.vue b/src/views/splash.vue index dbe7d0f..1db66eb 100644 --- a/src/views/splash.vue +++ b/src/views/splash.vue @@ -1,5 +1,47 @@ \ No newline at end of file + + + \ No newline at end of file -- 2.43.0