forked from VOICEVOX/voicevox
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33529dd
commit d55b42b
Showing
13 changed files
with
396 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import AsyncLock from "async-lock"; | ||
import { Preferences } from "@capacitor/preferences"; | ||
import { defaultEngine } from "@/backend/browser/contract"; | ||
|
||
import { BaseConfigManager, Metadata } from "@/backend/common/ConfigManager"; | ||
import { ConfigType, EngineId, engineSettingSchema } from "@/type/preload"; | ||
|
||
let configManager: MobileConfigManager | undefined; | ||
const entryKey = `${import.meta.env.VITE_APP_NAME}-config`; | ||
|
||
const configManagerLock = new AsyncLock(); | ||
const defaultEngineId = EngineId(defaultEngine.uuid); | ||
|
||
export async function getConfigManager() { | ||
await configManagerLock.acquire("configManager", async () => { | ||
if (!configManager) { | ||
configManager = new MobileConfigManager(); | ||
await configManager.initialize(); | ||
} | ||
}); | ||
|
||
if (!configManager) { | ||
throw new Error("configManager is undefined"); | ||
} | ||
|
||
return configManager; | ||
} | ||
|
||
class MobileConfigManager extends BaseConfigManager { | ||
protected getAppVersion() { | ||
return import.meta.env.VITE_APP_VERSION; | ||
} | ||
protected async exists() { | ||
return !!(await Preferences.get({ key: entryKey }).then((v) => v.value)); | ||
} | ||
protected async load(): Promise<Record<string, unknown> & Metadata> { | ||
const db = await Preferences.get({ key: entryKey }); | ||
return JSON.parse(db.value || "{}"); | ||
} | ||
|
||
protected async save(data: ConfigType & Metadata) { | ||
await Preferences.set({ key: entryKey, value: JSON.stringify(data) }); | ||
} | ||
|
||
protected getDefaultConfig() { | ||
const baseConfig = super.getDefaultConfig(); | ||
baseConfig.engineSettings[defaultEngineId] ??= engineSettingSchema.parse( | ||
{} | ||
); | ||
return baseConfig; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.