mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-16 17:27:39 +00:00
theme installed check
This commit is contained in:
parent
436a15cfbe
commit
e1e1397f17
2 changed files with 48 additions and 7 deletions
|
@ -191,14 +191,31 @@ void main() async {
|
|||
await MainDB.instance.initMainDB();
|
||||
ThemeService.instance.init(MainDB.instance);
|
||||
|
||||
// if (MainDB.instance.isar.stackThemes.countSync() < 2) {
|
||||
// install default themes
|
||||
final lightZip = await rootBundle.load("assets/default_themes/light.zip");
|
||||
final darkZip = await rootBundle.load("assets/default_themes/dark.zip");
|
||||
|
||||
await ThemeService.instance.install(themeArchive: lightZip);
|
||||
await ThemeService.instance.install(themeArchive: darkZip);
|
||||
// }
|
||||
if (!(await ThemeService.instance.verifyInstalled(themeId: "light"))) {
|
||||
Logging.instance.log(
|
||||
"Installing default light theme...",
|
||||
level: LogLevel.Info,
|
||||
);
|
||||
final lightZip = await rootBundle.load("assets/default_themes/light.zip");
|
||||
await ThemeService.instance.install(themeArchive: lightZip);
|
||||
Logging.instance.log(
|
||||
"Installing default light theme... finished",
|
||||
level: LogLevel.Info,
|
||||
);
|
||||
}
|
||||
if (!(await ThemeService.instance.verifyInstalled(themeId: "dark"))) {
|
||||
Logging.instance.log(
|
||||
"Installing default dark theme... ",
|
||||
level: LogLevel.Info,
|
||||
);
|
||||
final darkZip = await rootBundle.load("assets/default_themes/dark.zip");
|
||||
await ThemeService.instance.install(themeArchive: darkZip);
|
||||
Logging.instance.log(
|
||||
"Installing default dark theme... finished",
|
||||
level: LogLevel.Info,
|
||||
);
|
||||
}
|
||||
|
||||
runApp(const ProviderScope(child: MyApp()));
|
||||
}
|
||||
|
|
|
@ -89,6 +89,30 @@ class ThemeService {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO more thorough check/verification of theme
|
||||
Future<bool> verifyInstalled({required String themeId}) async {
|
||||
final dbHasTheme =
|
||||
await db.isar.stackThemes.where().themeIdEqualTo(themeId).count() > 0;
|
||||
if (dbHasTheme) {
|
||||
final themesDir = await StackFileSystem.applicationThemesDirectory();
|
||||
final jsonFileExists =
|
||||
await File("${themesDir.path}/$themeId/theme.json").exists();
|
||||
final assetsDirExists =
|
||||
await Directory("${themesDir.path}/$themeId/assets").exists();
|
||||
|
||||
if (!jsonFileExists || !assetsDirExists) {
|
||||
Logging.instance.log(
|
||||
"Theme $themeId found in DB but is missing files",
|
||||
level: LogLevel.Warning,
|
||||
);
|
||||
}
|
||||
|
||||
return jsonFileExists && assetsDirExists;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> fetchThemeList() async {
|
||||
// todo fetch actual themes from server
|
||||
throw UnimplementedError();
|
||||
|
|
Loading…
Reference in a new issue