From 11ac63b2aec0f2f7becf991e4a03a4a25a0e94e2 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 1 Jan 2021 13:15:48 +0100 Subject: [PATCH] Add password notice in dashbord on first startup --- nodecg-io-core/dashboard/authentication.ts | 12 ++++++++++++ nodecg-io-core/dashboard/panel.html | 4 ++++ nodecg-io-core/extension/messageManager.ts | 6 ++++++ nodecg-io-core/extension/persistenceManager.ts | 8 ++++++++ 4 files changed, 30 insertions(+) diff --git a/nodecg-io-core/dashboard/authentication.ts b/nodecg-io-core/dashboard/authentication.ts index c6e308f05..35832da71 100644 --- a/nodecg-io-core/dashboard/authentication.ts +++ b/nodecg-io-core/dashboard/authentication.ts @@ -9,6 +9,7 @@ const inputPassword = document.getElementById("inputPassword") as HTMLInputEleme const divAuth = document.getElementById("divAuth"); const divMain = document.getElementById("divMain"); const spanPasswordNotice = document.getElementById("spanPasswordNotice") as HTMLSpanElement; +const pFirstStartup = document.getElementById("pFirstStartup"); // Add key listener to password input inputPassword?.addEventListener("keyup", function (event) { @@ -25,12 +26,14 @@ nodecg.socket.on("connect", () => { loadFramework(); } else { updateLoadedStatus(); + updateFirstStartupLabel(); } }); document.addEventListener("DOMContentLoaded", () => { // Render loaded status for initial load updateLoadedStatus(); + updateFirstStartupLabel(); }); export async function isLoaded(): Promise { @@ -71,3 +74,12 @@ export async function loadFramework(): Promise { updateLoadedStatus(); } + +async function updateFirstStartupLabel(): Promise { + const isFirstStartup: boolean = await nodecg.sendMessage("isFirstStartup"); + if (isFirstStartup) { + pFirstStartup?.classList.add("hidden"); + } else { + pFirstStartup?.classList.remove("hidden"); + } +} diff --git a/nodecg-io-core/dashboard/panel.html b/nodecg-io-core/dashboard/panel.html index c4d8e6351..4aaeb5c18 100644 --- a/nodecg-io-core/dashboard/panel.html +++ b/nodecg-io-core/dashboard/panel.html @@ -10,6 +10,10 @@

Current status: Unknown

+

Login:

diff --git a/nodecg-io-core/extension/messageManager.ts b/nodecg-io-core/extension/messageManager.ts index 7d89c7015..b38a75efa 100644 --- a/nodecg-io-core/extension/messageManager.ts +++ b/nodecg-io-core/extension/messageManager.ts @@ -141,6 +141,12 @@ export class MessageManager { ack?.(undefined, result); } }); + + this.nodecg.listenFor("isFirstStartup", (_msg: undefined, ack) => { + if (!ack?.handled) { + ack?.(undefined, this.persist.isFirstStartup()); + } + }); } authRequired(handler: ListenForCallback): ListenForCallback { diff --git a/nodecg-io-core/extension/persistenceManager.ts b/nodecg-io-core/extension/persistenceManager.ts index 24220458e..56543909a 100644 --- a/nodecg-io-core/extension/persistenceManager.ts +++ b/nodecg-io-core/extension/persistenceManager.ts @@ -86,6 +86,14 @@ export class PersistenceManager { return this.password !== undefined; } + /** + * Returns whether this is the first startup aka. whether any encrypted data has been saved. + * If this returns true {{@link load}} will accept any password and use it to encrypt the configuration. + */ + isFirstStartup(): boolean { + return this.encryptedData.value.cipherText !== undefined; + } + /** * Decrypts and loads the locally stored configuration using the passed password. * @param password the password of the encrypted config.