mirror of
https://github.com/lifegpc/bookdownload.git
synced 2026-07-08 01:31:31 +08:00
Add settings page
This commit is contained in:
30
src/config.ts
Normal file
30
src/config.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { loadConfig, saveConfig } from "./utils";
|
||||
|
||||
type QdConfigData = {
|
||||
AutoSaveChapter?: boolean;
|
||||
}
|
||||
|
||||
export class QdConfig {
|
||||
static STORAGE_KEY = 'qd_config';
|
||||
config?: QdConfigData;
|
||||
constructor() {
|
||||
}
|
||||
async init() {
|
||||
this.config = await loadConfig<QdConfigData>(QdConfig.STORAGE_KEY, {});
|
||||
}
|
||||
async save() {
|
||||
if (!this.config) {
|
||||
throw new Error('Config not initialized');
|
||||
}
|
||||
await saveConfig(QdConfig.STORAGE_KEY, this.config);
|
||||
}
|
||||
get AutoSaveChapter(): boolean {
|
||||
return this.config?.AutoSaveChapter ?? false;
|
||||
}
|
||||
set AutoSaveChapter(value: boolean) {
|
||||
if (!this.config) {
|
||||
throw new Error('Config not initialized');
|
||||
}
|
||||
this.config.AutoSaveChapter = value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user