Tweak collectibles logic to await data writing

This commit is contained in:
Shawn 2023-11-20 12:56:38 -07:00
parent 395fa12ad0
commit 97cb83733c
3 changed files with 9 additions and 9 deletions

View File

@ -640,14 +640,14 @@
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = "Wonderous WidgetExtension.entitlements";
CODE_SIGN_ENTITLEMENTS = "WonderousWidgetExtension.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = S3TL5AY6Y3;
GCC_C_LANGUAGE_STANDARD = gnu11;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Wonderous Widget/Info.plist";
INFOPLIST_FILE = "WonderousWidget/Info.plist";
INFOPLIST_KEY_CFBundleDisplayName = "Wonderous Widget";
INFOPLIST_KEY_NSHumanReadableCopyright = "";
IPHONEOS_DEPLOYMENT_TARGET = 16.4;

View File

@ -38,6 +38,8 @@ class CollectiblesLogic with ThrottledSaveLoadMixin {
void setState(String id, int state) {
Map<String, int> states = Map.of(statesById.value);
states[id] = state;
statesById.value = states;
if (state == CollectibleState.discovered) {
final data = fromId(id)!;
_updateHomeWidgetTextData(
@ -46,8 +48,6 @@ class CollectiblesLogic with ThrottledSaveLoadMixin {
imageUrl: data.imageUrlSmall,
);
}
states[id] = state;
statesById.value = states;
scheduleSave();
}
@ -99,14 +99,14 @@ class CollectiblesLogic with ThrottledSaveLoadMixin {
Future<void> _updateHomeWidgetTextData({String title = '', String id = '', String imageUrl = ''}) async {
// Save title
HomeWidget.saveWidgetData<String>('lastDiscoveredTitle', title);
await HomeWidget.saveWidgetData<String>('lastDiscoveredTitle', title);
// Subtitle
String subTitle = '';
if(id.isNotEmpty){
final artifactData = await artifactLogic.getArtifactByID(id);
subTitle = artifactData?.date ?? '';
}
HomeWidget.saveWidgetData<String>('lastDiscoveredSubTitle', subTitle);
await HomeWidget.saveWidgetData<String>('lastDiscoveredSubTitle', subTitle);
// Image,
// Download, convert to base64 string and write to shared widget data
String imageBase64 = '';
@ -115,8 +115,8 @@ class CollectiblesLogic with ThrottledSaveLoadMixin {
imageBase64 = base64Encode(bytes);
debugPrint('Saving base64 bytes: $imageBase64');
}
HomeWidget.saveWidgetData<String>('lastDiscoveredImageData', imageBase64);
HomeWidget.updateWidget(iOSName: _appName);
await HomeWidget.saveWidgetData<String>('lastDiscoveredImageData', imageBase64);
await HomeWidget.updateWidget(iOSName: _appName);
}
@override

View File

@ -1,7 +1,7 @@
name: wonders
description: Explore the famous wonders of the world.
publish_to: "none"
version: 2.1.0
version: 2.1.1
environment:
sdk: ">=2.17.0 <3.0.0"