Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit 1cc1047

Browse files
authored
Merge pull request #154 from codeoverflow-org/feature/dashboard-first-startup-pw-notice
Add password notice in dashbord on first startup
2 parents 2de19bc + 11ac63b commit 1cc1047

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

nodecg-io-core/dashboard/authentication.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const inputPassword = document.getElementById("inputPassword") as HTMLInputEleme
99
const divAuth = document.getElementById("divAuth");
1010
const divMain = document.getElementById("divMain");
1111
const spanPasswordNotice = document.getElementById("spanPasswordNotice") as HTMLSpanElement;
12+
const pFirstStartup = document.getElementById("pFirstStartup");
1213

1314
// Add key listener to password input
1415
inputPassword?.addEventListener("keyup", function (event) {
@@ -25,12 +26,14 @@ nodecg.socket.on("connect", () => {
2526
loadFramework();
2627
} else {
2728
updateLoadedStatus();
29+
updateFirstStartupLabel();
2830
}
2931
});
3032

3133
document.addEventListener("DOMContentLoaded", () => {
3234
// Render loaded status for initial load
3335
updateLoadedStatus();
36+
updateFirstStartupLabel();
3437
});
3538

3639
export async function isLoaded(): Promise<boolean> {
@@ -71,3 +74,12 @@ export async function loadFramework(): Promise<void> {
7174

7275
updateLoadedStatus();
7376
}
77+
78+
async function updateFirstStartupLabel(): Promise<void> {
79+
const isFirstStartup: boolean = await nodecg.sendMessage("isFirstStartup");
80+
if (isFirstStartup) {
81+
pFirstStartup?.classList.add("hidden");
82+
} else {
83+
pFirstStartup?.classList.remove("hidden");
84+
}
85+
}

nodecg-io-core/dashboard/panel.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
<p>Current status: <span id="spanLoaded">Unknown</span></p>
1111

1212
<div id="divAuth">
13+
<p id="pFirstStartup" class="hidden">
14+
This seems to be your first startup of nodecg-io. Please choose a password which will be used to encrypt
15+
all your credentials.
16+
</p>
1317
<p>Login:</p>
1418
<div class="margins">
1519
<label for="inputPassword">Password: </label>

nodecg-io-core/extension/messageManager.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ export class MessageManager {
141141
ack?.(undefined, result);
142142
}
143143
});
144+
145+
this.nodecg.listenFor("isFirstStartup", (_msg: undefined, ack) => {
146+
if (!ack?.handled) {
147+
ack?.(undefined, this.persist.isFirstStartup());
148+
}
149+
});
144150
}
145151

146152
authRequired<M extends PasswordMessage, V>(handler: ListenForCallback<M, V>): ListenForCallback<M, V> {

nodecg-io-core/extension/persistenceManager.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ export class PersistenceManager {
8686
return this.password !== undefined;
8787
}
8888

89+
/**
90+
* Returns whether this is the first startup aka. whether any encrypted data has been saved.
91+
* If this returns true {{@link load}} will accept any password and use it to encrypt the configuration.
92+
*/
93+
isFirstStartup(): boolean {
94+
return this.encryptedData.value.cipherText !== undefined;
95+
}
96+
8997
/**
9098
* Decrypts and loads the locally stored configuration using the passed password.
9199
* @param password the password of the encrypted config.

0 commit comments

Comments
 (0)