Skip to content

Commit

Permalink
Added fstab save and auto-load from localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Oct 13, 2024
1 parent 934299e commit 0d33fee
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
39 changes: 30 additions & 9 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,23 +248,44 @@ function loadConfig(configs: Record<string, string>[]): void {
}
}

$('#config .add').on('click', createNewMountConfig);

$('#config .save').on('click', () => {
const configs = parseConfig();
function saveConfig(configs: Record<string, string>[], noLocalStorage: boolean = false): void {
if (!fs.existsSync('/etc')) {
fs.mkdirSync('/etc');
}
fs.writeFileSync('/etc/fstab', toFSTable(configs));
const table = toFSTable(configs);
if (!noLocalStorage) localStorage.fstab = table;
fs.writeFileSync('/etc/fstab', table);
}

$<HTMLInputElement>('#config .auto-load')[0].checked = 'autoLoad' in localStorage;

if (localStorage.autoLoad && localStorage.fstab) {
const config = fromFSTable(localStorage.getItem('fstab')!);
loadConfig(config);
saveConfig(config, true);
}

$('#config .add').on('click', createNewMountConfig);

$('#config .upload').on('click', () => {
void upload()
.then(response => response.text())
.then(table => loadConfig(fromFSTable(table)));
});

$('#config .download').on('click', () => {
const configs = parseConfig();
download(toFSTable(configs), 'fstab');
});

$('#config .upload').on('click', () => {
void upload()
.then(response => response.text())
.then(table => loadConfig(fromFSTable(table)));
$('#config .save').on('click', () => {
saveConfig(parseConfig());
});

$<HTMLInputElement>('#config .auto-load').on('change', e => {
if (e.target.checked) {
localStorage.autoLoad = 1;
} else {
localStorage.removeItem('autoLoad');
}
});
12 changes: 8 additions & 4 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
</div>

<ul id="config" class="tab">
<strong class="title">Configuration</strong>
<div class="top">
<p><strong>Configuration</strong></p>
<input type="checkbox" name="auto-load" class="auto-load" />
<label for="autoload">Auto-load</label>
</div>

<template id="mount">
<li class="mount">
Expand All @@ -29,15 +33,15 @@
</template>

<button class="add">+</button>
<div class="right">
<div class="manage">
<button class="upload">Upload</button>
<button class="download">Download</button>
<button class="save">Save</button>
</div>
</ul>

<ul id="explorer" class="tab" style="display: none">
<strong class="title">Explorer</strong>
<strong class="top">Explorer</strong>

<li class="header">
<p class="name">Name</p>
Expand All @@ -55,7 +59,7 @@
</ul>

<div id="editor" class="tab" style="display: none">
<strong class="title">Editor</strong>
<strong class="top">Editor</strong>

<textarea class="content"></textarea>
</div>
Expand Down
11 changes: 9 additions & 2 deletions src/styles.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* {
color: #bbb;
color-scheme: dark;
}

body {
Expand All @@ -26,6 +27,7 @@ select {
border: 1px solid #888;
border-radius: 0.25em;
padding: 0.25em;
accent-color: #bbb;
}

textarea:focus,
Expand Down Expand Up @@ -76,7 +78,7 @@ input:focus {
inset: 3em 0.5em 0.5em;
margin: 0;

.title {
.top {
position: absolute;
left: 1em;
top: 0.5em;
Expand All @@ -98,11 +100,16 @@ input:focus {
padding: 0.5em 1em;
}

.right {
.manage {
position: absolute;
right: 1em;
bottom: 1em;
}

li {
position: relative;
top: 6em;
}
}

#explorer {
Expand Down

0 comments on commit 0d33fee

Please sign in to comment.