未验证 提交 8a7f064b 编写于 作者: Q qsniyg 提交者: GitHub

Add option to configure the displayed welcome username (#744)

上级 b462528d
...@@ -323,6 +323,19 @@ async function displayTitleScreen() { ...@@ -323,6 +323,19 @@ async function displayTitleScreen() {
}); });
} }
// Returns the user's desired display name
async function getDisplayName() {
let user = settings.username || null;
if (user)
return user;
try {
user = await require("username")();
} catch (e) {}
return user;
}
// Create the UI's html structure and initialize the terminal client and the keyboard // Create the UI's html structure and initialize the terminal client and the keyboard
async function initUI() { async function initUI() {
document.body.innerHTML += `<section class="mod_column" id="mod_column_left"> document.body.innerHTML += `<section class="mod_column" id="mod_column_left">
...@@ -367,11 +380,14 @@ async function initUI() { ...@@ -367,11 +380,14 @@ async function initUI() {
let greeter = document.getElementById("main_shell_greeting"); let greeter = document.getElementById("main_shell_greeting");
require("username")().then(user => { getDisplayName().then(user => {
greeter.innerHTML += `Welcome back, <em>${user}</em>`; if (user) {
}).catch(() => { greeter.innerHTML += `Welcome back, <em>${user}</em>`;
greeter.innerHTML += "Welcome back"; } else {
greeter.innerHTML += "Welcome back";
}
}); });
greeter.setAttribute("style", "opacity: 1;"); greeter.setAttribute("style", "opacity: 1;");
document.getElementById("filesystem").setAttribute("style", ""); document.getElementById("filesystem").setAttribute("style", "");
...@@ -618,6 +634,11 @@ window.openSettings = async () => { ...@@ -618,6 +634,11 @@ window.openSettings = async () => {
<td>Custom shell environment override</td> <td>Custom shell environment override</td>
<td><input type="text" id="settingsEditor-env" value="${window.settings.env}"></td> <td><input type="text" id="settingsEditor-env" value="${window.settings.env}"></td>
</tr> </tr>
<tr>
<td>username</td>
<td>Custom username to display at boot</td>
<td><input type="text" id="settingsEditor-username" value="${window.settings.username}"></td>
</tr>
<tr> <tr>
<td>keyboard</td> <td>keyboard</td>
<td>On-screen keyboard layout code</td> <td>On-screen keyboard layout code</td>
...@@ -788,6 +809,7 @@ window.writeSettingsFile = () => { ...@@ -788,6 +809,7 @@ window.writeSettingsFile = () => {
shell: document.getElementById("settingsEditor-shell").value, shell: document.getElementById("settingsEditor-shell").value,
cwd: document.getElementById("settingsEditor-cwd").value, cwd: document.getElementById("settingsEditor-cwd").value,
env: document.getElementById("settingsEditor-env").value, env: document.getElementById("settingsEditor-env").value,
username: document.getElementById("settingsEditor-username").value,
keyboard: document.getElementById("settingsEditor-keyboard").value, keyboard: document.getElementById("settingsEditor-keyboard").value,
theme: document.getElementById("settingsEditor-theme").value, theme: document.getElementById("settingsEditor-theme").value,
termFontSize: Number(document.getElementById("settingsEditor-termFontSize").value), termFontSize: Number(document.getElementById("settingsEditor-termFontSize").value),
...@@ -899,7 +921,7 @@ window.openShortcutsHelp = () => { ...@@ -899,7 +921,7 @@ window.openShortcutsHelp = () => {
<th>Trigger</th> <th>Trigger</th>
<th>Command</th> <th>Command</th>
<tr> <tr>
${customList} ${customList}
</table> </table>
</details> </details>
<br>`, <br>`,
...@@ -914,7 +936,7 @@ window.openShortcutsHelp = () => { ...@@ -914,7 +936,7 @@ window.openShortcutsHelp = () => {
let wrap1 = document.getElementById('shortcutsHelpAccordeon1'); let wrap1 = document.getElementById('shortcutsHelpAccordeon1');
let wrap2 = document.getElementById('shortcutsHelpAccordeon2'); let wrap2 = document.getElementById('shortcutsHelpAccordeon2');
wrap1.addEventListener('toggle', e => { wrap1.addEventListener('toggle', e => {
wrap2.open = !wrap1.open; wrap2.open = !wrap1.open;
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册