Skip to content

Commit

Permalink
Add openPath and switchTab to globalThis
Browse files Browse the repository at this point in the history
Changed FS table saving slightly
  • Loading branch information
james-pre committed Oct 14, 2024
1 parent dffff22 commit 621cf23
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,29 +248,31 @@ function loadConfig(configs: Record<string, string>[]): void {
}
}

function saveConfig(configs: Record<string, string>[], noLocalStorage: boolean = false): void {
function saveTable(table: string, noLocalStorage: boolean = false): void {
if (!fs.existsSync('/etc')) {
fs.mkdirSync('/etc');
}
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);
const table = localStorage.getItem('fstab')!;
loadConfig(fromFSTable(table));
saveTable(table, true);
}

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

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

$('#config .download').on('click', () => {
Expand All @@ -279,7 +281,7 @@ $('#config .download').on('click', () => {
});

$('#config .save').on('click', () => {
saveConfig(parseConfig());
saveTable(toFSTable(parseConfig()));
});

$<HTMLInputElement>('#config .auto-load').on('change', e => {
Expand Down

0 comments on commit 621cf23

Please sign in to comment.