properly await all prefs set/remove

Signed-off-by: Joel Jothiprakasam <hijoelj@gmail.com>
This commit is contained in:
Joel Jothiprakasam
2023-04-12 18:37:09 -05:00
parent ee1af810f1
commit 22845b89d4
19 changed files with 146 additions and 140 deletions

View File

@ -76,12 +76,12 @@ class ChatCreatorState extends OptimizedState<ChatCreator> {
addressController.addListener(() {
_debounce?.cancel();
_debounce = Timer(const Duration(milliseconds: 250), () async {
final tuple = await SchedulerBinding.instance.scheduleTask(() {
final tuple = await SchedulerBinding.instance.scheduleTask(() async {
if (addressController.text != oldText) {
oldText = addressController.text;
// if user has typed stuff, remove the message view and show filtered results
if (addressController.text.isNotEmpty && fakeController.value != null) {
cm.setAllInactive();
await cm.setAllInactive();
oldController = fakeController.value;
fakeController.value = null;
}
@ -154,7 +154,7 @@ class ChatCreatorState extends OptimizedState<ChatCreator> {
Future<Chat?> findExistingChat({bool checkDeleted = false, bool update = true}) async {
// no selected items, remove message view
if (selectedContacts.isEmpty) {
cm.setAllInactive();
await cm.setAllInactive();
fakeController.value = null;
return null;
}
@ -201,17 +201,17 @@ class ChatCreatorState extends OptimizedState<ChatCreator> {
// if match, show message view, otherwise hide it
if (update) {
if (existingChat != null) {
cm.setActiveChat(existingChat, clearNotifications: false);
await cm.setActiveChat(existingChat, clearNotifications: false);
cm.activeChat!.controller = cvc(existingChat);
fakeController.value = cm.activeChat!.controller;
} else {
cm.setAllInactive();
await cm.setAllInactive();
fakeController.value = null;
}
}
if (checkDeleted && existingChat?.dateDeleted != null) {
Chat.unDelete(existingChat!);
chats.addChat(existingChat);
await chats.addChat(existingChat);
}
return existingChat;
}
@ -440,7 +440,7 @@ class ChatCreatorState extends OptimizedState<ChatCreator> {
selectedBorderColor: context.theme.colorScheme.bubble(context, iMessage),
selectedColor: context.theme.colorScheme.bubble(context, iMessage),
isSelected: [iMessage, sms],
onPressed: (index) {
onPressed: (index) async {
selectedContacts.clear();
addressController.text = "";
if (index == 0) {
@ -449,7 +449,7 @@ class ChatCreatorState extends OptimizedState<ChatCreator> {
sms = false;
filteredChats = List<Chat>.from(existingChats.where((e) => e.isIMessage));
});
cm.setAllInactive();
await cm.setAllInactive();
fakeController.value = null;
} else {
setState(() {
@ -457,7 +457,7 @@ class ChatCreatorState extends OptimizedState<ChatCreator> {
sms = true;
filteredChats = List<Chat>.from(existingChats.where((e) => !e.isIMessage));
});
cm.setAllInactive();
await cm.setAllInactive();
fakeController.value = null;
}
},
@ -652,7 +652,7 @@ class ChatCreatorState extends OptimizedState<ChatCreator> {
);
await Future.delayed(const Duration(milliseconds: 500));
if (fakeController.value == null) {
cm.setActiveChat(chat, clearNotifications: false);
await cm.setActiveChat(chat, clearNotifications: false);
cm.activeChat!.controller = cvc(chat);
fakeController.value = cm.activeChat!.controller;
}

View File

@ -55,8 +55,10 @@ class _ConversationPeekViewState extends OptimizedState<ConversationPeekView> wi
@override
void initState() {
super.initState();
cm.setActiveChat(widget.chat, clearNotifications: false);
cm.activeChat!.controller = cvController;
Future.delayed(Duration.zero, () async {
await cm.setActiveChat(widget.chat, clearNotifications: false);
cm.activeChat!.controller = cvController;
});
controller = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 150),

View File

@ -87,7 +87,7 @@ class OverflowMenu extends StatelessWidget {
} else if (value == 2) {
final currentChat = cm.activeChat?.chat;
ns.closeAllConversationView(context);
cm.setAllInactive();
await cm.setAllInactive();
await Navigator.of(Get.context!).push(
ThemeSwitcher.buildPageRoute(
builder: (BuildContext context) {
@ -96,7 +96,7 @@ class OverflowMenu extends StatelessWidget {
),
);
if (currentChat != null) {
cm.setActiveChat(currentChat);
await cm.setActiveChat(currentChat);
if (ss.settings.tabletMode.value) {
ns.pushAndRemoveUntil(
context,
@ -146,7 +146,7 @@ class OverflowMenu extends StatelessWidget {
await ss.prefs.setString("selected-dark", "OLED Dark");
await ss.prefs.setString("selected-light", "Bright White");
themeBox.putMany(ts.defaultThemes);
ts.changeTheme(context);
await ts.changeTheme(context);
Get.offAll(() => WillPopScope(
onWillPop: () async => false,
child: TitleBarWrapper(child: SetupView()),
@ -160,7 +160,7 @@ class OverflowMenu extends StatelessWidget {
} else if (value == 5) {
final currentChat = cm.activeChat?.chat;
ns.closeAllConversationView(context);
cm.setAllInactive();
await cm.setAllInactive();
await Navigator.of(Get.context!).push(
ThemeSwitcher.buildPageRoute(
builder: (BuildContext context) {
@ -169,7 +169,7 @@ class OverflowMenu extends StatelessWidget {
),
);
if (currentChat != null) {
cm.setActiveChat(currentChat);
await cm.setActiveChat(currentChat);
if (ss.settings.tabletMode.value) {
ns.pushAndRemoveUntil(
context,

View File

@ -38,8 +38,10 @@ class ConversationViewState extends OptimizedState<ConversationView> {
void initState() {
super.initState();
controller.fromChatCreator = widget.fromChatCreator;
cm.setActiveChat(chat);
cm.activeChat!.controller = controller;
Future.delayed(Duration.zero, () async {
await cm.setActiveChat(chat);
cm.activeChat!.controller = controller;
});
}
@override

View File

@ -50,13 +50,13 @@ class _AdvancedThemingContentState extends OptimizedState<AdvancedThemingContent
BuildContext _context = context;
showDialog(
context: context,
builder: (context) => CreateNewThemeDialog(_context, widget.isDarkMode, currentTheme, (newTheme) {
builder: (context) => CreateNewThemeDialog(_context, widget.isDarkMode, currentTheme, (newTheme) async {
allThemes.add(newTheme);
currentTheme = newTheme;
if (widget.isDarkMode) {
ts.changeTheme(_context, dark: currentTheme);
await ts.changeTheme(_context, dark: currentTheme);
} else {
ts.changeTheme(_context, light: currentTheme);
await ts.changeTheme(_context, light: currentTheme);
}
})
);
@ -192,9 +192,9 @@ class _AdvancedThemingContentState extends OptimizedState<AdvancedThemingContent
var allThemes = ThemeStruct.getThemes();
var currentLight = ThemeStruct.getLightTheme();
var currentDark = ThemeStruct.getDarkTheme();
ss.prefs.setString("previous-light", currentLight.name);
ss.prefs.setString("previous-dark", currentDark.name);
ts.changeTheme(
await ss.prefs.setString("previous-light", currentLight.name);
await ss.prefs.setString("previous-dark", currentDark.name);
await ts.changeTheme(
context,
light: allThemes.firstWhere((element) => element.name == "Music Theme ☀"),
dark: allThemes.firstWhere((element) => element.name == "Music Theme 🌙")
@ -202,16 +202,16 @@ class _AdvancedThemingContentState extends OptimizedState<AdvancedThemingContent
} else if (currentTheme.name == "Music Theme ☀" ||
currentTheme.name == "Music Theme 🌙") {
if (!widget.isDarkMode) {
ThemeStruct previousDark = ts.revertToPreviousDarkTheme();
ts.changeTheme(context, light: value, dark: previousDark);
ThemeStruct previousDark = await ts.revertToPreviousDarkTheme();
await ts.changeTheme(context, light: value, dark: previousDark);
} else {
ThemeStruct previousLight = ts.revertToPreviousLightTheme();
ts.changeTheme(context, light: previousLight, dark: value);
ThemeStruct previousLight = await ts.revertToPreviousLightTheme();
await ts.changeTheme(context, light: previousLight, dark: value);
}
} else if (widget.isDarkMode) {
ts.changeTheme(context, dark: value);
await ts.changeTheme(context, dark: value);
} else {
ts.changeTheme(context, light: value);
await ts.changeTheme(context, light: value);
}
currentTheme = value;
editable = !currentTheme.isPreset;
@ -225,9 +225,9 @@ class _AdvancedThemingContentState extends OptimizedState<AdvancedThemingContent
currentTheme.gradientBg = val;
currentTheme.save();
if (widget.isDarkMode) {
ts.changeTheme(context, dark: currentTheme);
await ts.changeTheme(context, dark: currentTheme);
} else {
ts.changeTheme(context, light: currentTheme);
await ts.changeTheme(context, light: currentTheme);
}
},
initialVal: currentTheme.gradientBg,
@ -318,9 +318,9 @@ class _AdvancedThemingContentState extends OptimizedState<AdvancedThemingContent
currentTheme.data = ThemeStruct.fromMap(map).data;
currentTheme.save();
if (currentTheme.name == ss.prefs.getString("selected-dark")) {
ts.changeTheme(context, dark: currentTheme);
await ts.changeTheme(context, dark: currentTheme);
} else if (currentTheme.name == ss.prefs.getString("selected-light")) {
ts.changeTheme(context, light: currentTheme);
await ts.changeTheme(context, light: currentTheme);
}
},
),
@ -349,7 +349,7 @@ class _AdvancedThemingContentState extends OptimizedState<AdvancedThemingContent
currentTheme.data = ThemeStruct.fromMap(map).data;
setState(() {});
},
onChangeEnd: (double val) {
onChangeEnd: (double val) async {
master = val;
final map = currentTheme.toMap();
final keys = currentTheme.textSizes.keys.toList();
@ -359,9 +359,9 @@ class _AdvancedThemingContentState extends OptimizedState<AdvancedThemingContent
currentTheme.data = ThemeStruct.fromMap(map).data;
currentTheme.save();
if (currentTheme.name == ss.prefs.getString("selected-dark")) {
ts.changeTheme(context, dark: currentTheme);
await ts.changeTheme(context, dark: currentTheme);
} else if (currentTheme.name == ss.prefs.getString("selected-light")) {
ts.changeTheme(context, light: currentTheme);
await ts.changeTheme(context, light: currentTheme);
}
},
backgroundColor: tileColor,
@ -382,15 +382,15 @@ class _AdvancedThemingContentState extends OptimizedState<AdvancedThemingContent
currentTheme.data = ThemeStruct.fromMap(map).data;
setState(() {});
},
onChangeEnd: (double val) {
onChangeEnd: (double val) async {
final map = currentTheme.toMap();
map["data"]["textTheme"][currentTheme.textSizes.keys.toList()[index]]['fontSize'] = ThemeStruct.defaultTextSizes.values.toList()[index] * val;
currentTheme.data = ThemeStruct.fromMap(map).data;
currentTheme.save();
if (currentTheme.name == ss.prefs.getString("selected-dark")) {
ts.changeTheme(context, dark: currentTheme);
await ts.changeTheme(context, dark: currentTheme);
} else if (currentTheme.name == ss.prefs.getString("selected-light")) {
ts.changeTheme(context, light: currentTheme);
await ts.changeTheme(context, light: currentTheme);
}
},
backgroundColor: tileColor,
@ -419,12 +419,12 @@ class _AdvancedThemingContentState extends OptimizedState<AdvancedThemingContent
allThemes.removeWhere((element) => element == currentTheme);
currentTheme.delete();
currentTheme =
widget.isDarkMode ? ts.revertToPreviousDarkTheme() : ts.revertToPreviousLightTheme();
await (widget.isDarkMode ? ts.revertToPreviousDarkTheme() : ts.revertToPreviousLightTheme());
allThemes = ThemeStruct.getThemes();
if (widget.isDarkMode) {
ts.changeTheme(context, dark: currentTheme);
await ts.changeTheme(context, dark: currentTheme);
} else {
ts.changeTheme(context, light: currentTheme);
await ts.changeTheme(context, light: currentTheme);
}
setState(() {});
},

View File

@ -151,9 +151,9 @@ class _ThemingPanelState extends CustomState<ThemingPanel, void, ThemingPanelCon
children: [
Obx(() => SettingsOptions<Skins>(
initial: ss.settings.skin.value,
onChanged: (val) {
onChanged: (val) async {
if (val == null) return;
cm.setAllInactive();
await cm.setAllInactive();
ss.settings.skin.value = val;
saveSettings();
setState(() {});
@ -247,7 +247,7 @@ class _ThemingPanelState extends CustomState<ThemingPanel, void, ThemingPanelCon
if (defaultOpacityDark) {
ss.settings.windowEffectCustomOpacityDark.value = WindowEffects.defaultOpacity(dark: true);
}
ss.prefs.setString('window-effect', effect.toString());
await ss.prefs.setString('window-effect', effect.toString());
await WindowEffects.setEffect(color: context.theme.colorScheme.background);
saveSettings();
},
@ -387,9 +387,9 @@ class _ThemingPanelState extends CustomState<ThemingPanel, void, ThemingPanelCon
currentTheme.name == "Music Theme 🌙") {
ss.settings.colorsFromMedia.value = false;
ss.saveSettings(ss.settings);
ThemeStruct previousDark = ts.revertToPreviousDarkTheme();
ThemeStruct previousLight = ts.revertToPreviousLightTheme();
ts.changeTheme(context, light: previousLight, dark: previousDark);
ThemeStruct previousDark = await ts.revertToPreviousDarkTheme();
ThemeStruct previousLight = await ts.revertToPreviousLightTheme();
await ts.changeTheme(context, light: previousLight, dark: previousDark);
}
ss.settings.monetTheming.value = val ?? Monet.none;
saveSettings();
@ -426,9 +426,9 @@ class _ThemingPanelState extends CustomState<ThemingPanel, void, ThemingPanelCon
var allThemes = ThemeStruct.getThemes();
var currentLight = ThemeStruct.getLightTheme();
var currentDark = ThemeStruct.getDarkTheme();
ss.prefs.setString("previous-light", currentLight.name);
ss.prefs.setString("previous-dark", currentDark.name);
ts.changeTheme(
await ss.prefs.setString("previous-light", currentLight.name);
await ss.prefs.setString("previous-dark", currentDark.name);
await ts.changeTheme(
context,
light: allThemes.firstWhere((element) => element.name == "Music Theme ☀"),
dark: allThemes.firstWhere((element) => element.name == "Music Theme 🌙")
@ -445,9 +445,9 @@ class _ThemingPanelState extends CustomState<ThemingPanel, void, ThemingPanelCon
final darkName = ss.prefs.getString("previous-dark");
var previousLight = allThemes.firstWhere((e) => e.name == lightName);
var previousDark = allThemes.firstWhere((e) => e.name == darkName);
ss.prefs.remove("previous-light");
ss.prefs.remove("previous-dark");
ts.changeTheme(context, light: previousLight, dark: previousDark);
await ss.prefs.remove("previous-light");
await ss.prefs.remove("previous-dark");
await ts.changeTheme(context, light: previousLight, dark: previousDark);
ss.settings.colorsFromMedia.value = val;
saveSettings();
}

View File

@ -857,7 +857,7 @@ class _SettingsPageState extends OptimizedState<SettingsPage> {
await ss.prefs.setString("selected-dark", "OLED Dark");
await ss.prefs.setString("selected-light", "Bright White");
themeBox.putMany(ts.defaultThemes);
ts.changeTheme(context);
await ts.changeTheme(context);
Get.offAll(() => WillPopScope(
onWillPop: () async => false,
child: TitleBarWrapper(child: SetupView()),

View File

@ -46,9 +46,9 @@ class _AdvancedThemingTileState extends OptimizedState<AdvancedThemingTile> {
widget.currentTheme.data = ThemeStruct.fromMap(map).data;
widget.currentTheme.save();
if (widget.currentTheme.name == ss.prefs.getString("selected-dark")) {
ts.changeTheme(_context, dark: widget.currentTheme);
await ts.changeTheme(_context, dark: widget.currentTheme);
} else if (widget.currentTheme.name == ss.prefs.getString("selected-light")) {
ts.changeTheme(_context, light: widget.currentTheme);
await ts.changeTheme(_context, light: widget.currentTheme);
}
}
} else {
@ -69,9 +69,9 @@ class _AdvancedThemingTileState extends OptimizedState<AdvancedThemingTile> {
widget.currentTheme.data = ThemeStruct.fromMap(map).data;
widget.currentTheme.save();
if (widget.currentTheme.name == ss.prefs.getString("selected-dark")) {
ts.changeTheme(_context, dark: widget.currentTheme);
await ts.changeTheme(_context, dark: widget.currentTheme);
} else if (widget.currentTheme.name == ss.prefs.getString("selected-light")) {
ts.changeTheme(_context, light: widget.currentTheme);
await ts.changeTheme(_context, light: widget.currentTheme);
}
}
} else {

View File

@ -59,8 +59,8 @@ class _TabletModeWrapperState extends OptimizedState<TabletModeWrapper> {
setState(() {});
}
});
debounce<double>(_ratio, (val) {
ss.prefs.setDouble('splitRatio', val);
debounce<double>(_ratio, (val) async {
await ss.prefs.setDouble('splitRatio', val);
eventDispatcher.emit('split-refresh', null);
});
}

View File

@ -204,8 +204,8 @@ Future<Null> initApp(bool bubble, List<String> arguments) async {
Logger.info("Detected prior use of custom path option. Migrating...");
copyDirectory(oldCustom, objectBoxDirectory);
}
ss.prefs.remove('use-custom-path');
ss.prefs.remove('custom-path');
await ss.prefs.remove('use-custom-path');
await ss.prefs.remove('custom-path');
}
Logger.info("Opening ObjectBox store from path: ${objectBoxDirectory.path}");
store = await openStore(directory: objectBoxDirectory.path);
@ -238,8 +238,8 @@ Future<Null> initApp(bool bubble, List<String> arguments) async {
}
if (themeBox.isEmpty()) {
ss.prefs.setString("selected-dark", "OLED Dark");
ss.prefs.setString("selected-light", "Bright White");
await ss.prefs.setString("selected-dark", "OLED Dark");
await ss.prefs.setString("selected-light", "Bright White");
themeBox.putMany(ts.defaultThemes);
}
int version = ss.prefs.getInt('dbVersion') ?? (ss.settings.finishedSetup.value ? 1 : databaseVersion);
@ -305,7 +305,7 @@ Future<Null> initApp(bool bubble, List<String> arguments) async {
}
/* ----- SERVICES INITIALIZATION POST OBJECTBOX ----- */
ss.prefs.setInt('dbVersion', databaseVersion);
await ss.prefs.setInt('dbVersion', databaseVersion);
storeStartup.complete();
ss.getFcmData();
if (!kIsWeb) {
@ -373,14 +373,14 @@ Future<Null> initApp(bool bubble, List<String> arguments) async {
width = width.clamp(300, max(300, primary.size.width));
height = height.clamp(300, max(300, primary.size.height));
await windowManager.setSize(Size(width, height));
ss.prefs.setDouble("window-width", width);
ss.prefs.setDouble("window-height", height);
await ss.prefs.setDouble("window-width", width);
await ss.prefs.setDouble("window-height", height);
} else {
Size size = await windowManager.getSize();
width = size.width;
height = size.height;
ss.prefs.setDouble("window-width", width);
ss.prefs.setDouble("window-height", height);
await ss.prefs.setDouble("window-width", width);
await ss.prefs.setDouble("window-height", height);
}
double? posX = ss.prefs.getDouble("window-x");
@ -389,15 +389,15 @@ Future<Null> initApp(bool bubble, List<String> arguments) async {
posX = posX.clamp(0, max(0, primary.size.width - width));
posY = posY.clamp(0, max(0, primary.size.height - height));
await windowManager.setPosition(Offset(posX, posY));
ss.prefs.setDouble("window-x", posX);
ss.prefs.setDouble("window-y", posY);
await ss.prefs.setDouble("window-x", posX);
await ss.prefs.setDouble("window-y", posY);
} else {
await windowManager.setAlignment(Alignment.center);
Offset offset = await windowManager.getPosition();
posX = offset.dx;
posY = offset.dy;
ss.prefs.setDouble("window-x", posX);
ss.prefs.setDouble("window-y", posY);
await ss.prefs.setDouble("window-x", posX);
await ss.prefs.setDouble("window-y", posY);
}
Size size = await windowManager.getSize();
@ -406,8 +406,8 @@ Future<Null> initApp(bool bubble, List<String> arguments) async {
posX = posX.clamp(0, max(0, primary.size.width - width));
posY = posY.clamp(0, max(0, primary.size.height - height));
await windowManager.setPosition(Offset(posX, posY));
ss.prefs.setDouble("window-x", posX);
ss.prefs.setDouble("window-y", posY);
await ss.prefs.setDouble("window-x", posX);
await ss.prefs.setDouble("window-y", posY);
await windowManager.setTitle('BlueBubbles');
if (arguments.firstOrNull == "minimized") {
@ -479,15 +479,15 @@ class DesktopWindowListener extends WindowListener {
@override
void onWindowResized() async {
Size size = await windowManager.getSize();
ss.prefs.setDouble("window-width", size.width);
ss.prefs.setDouble("window-height", size.height);
await ss.prefs.setDouble("window-width", size.width);
await ss.prefs.setDouble("window-height", size.height);
}
@override
void onWindowMoved() async {
Offset offset = await windowManager.getPosition();
ss.prefs.setDouble("window-x", offset.dx);
ss.prefs.setDouble("window-y", offset.dy);
await ss.prefs.setDouble("window-x", offset.dx);
await ss.prefs.setDouble("window-y", offset.dy);
}
}
@ -795,7 +795,7 @@ class _HomeState extends OptimizedState<Home> with WidgetsBindingObserver {
}
if (ss.prefs.getBool('1.11.1-warning') != true) {
ss.prefs.setBool('1.11.1-warning', true);
await ss.prefs.setBool('1.11.1-warning', true);
}
if (!ss.settings.finishedSetup.value) {

View File

@ -151,19 +151,19 @@ class Settings {
Settings save() {
Map<String, dynamic> map = toMap(includeAll: true);
map.forEach((key, value) {
map.forEach((key, value) async {
if (value is bool) {
ss.prefs.setBool(key, value);
await ss.prefs.setBool(key, value);
} else if (value is String) {
ss.prefs.setString(key, value);
await ss.prefs.setString(key, value);
} else if (value is int) {
ss.prefs.setInt(key, value);
await ss.prefs.setInt(key, value);
} else if (value is double) {
ss.prefs.setDouble(key, value);
await ss.prefs.setDouble(key, value);
} else if (value is List || value is Map) {
ss.prefs.setString(key, jsonEncode(value));
await ss.prefs.setString(key, jsonEncode(value));
} else if (value == null) {
ss.prefs.remove(key);
await ss.prefs.remove(key);
}
});
return this;

View File

@ -306,7 +306,7 @@ class Chat {
_latestMessage = message;
dateDeleted = null;
// ignore: argument_type_not_assignable, return_of_invalid_type, invalid_assignment, for_in_of_invalid_element_type
chats.addChat(this);
await chats.addChat(this);
}
}

View File

@ -35,22 +35,24 @@ class FCMData {
FCMData save() {
if (isNull) return this;
ss.prefs.setString('projectID', projectID!);
ss.prefs.setString('storageBucket', storageBucket!);
ss.prefs.setString('apiKey', apiKey!);
ss.prefs.setString('firebaseURL', firebaseURL!);
ss.prefs.setString('clientID', clientID!);
ss.prefs.setString('applicationID', applicationID!);
Future.delayed(Duration.zero, () async {
await ss.prefs.setString('projectID', projectID!);
await ss.prefs.setString('storageBucket', storageBucket!);
await ss.prefs.setString('apiKey', apiKey!);
await ss.prefs.setString('firebaseURL', firebaseURL!);
await ss.prefs.setString('clientID', clientID!);
await ss.prefs.setString('applicationID', applicationID!);
});
return this;
}
static void deleteFcmData() {
ss.prefs.remove('projectID');
ss.prefs.remove('storageBucket');
ss.prefs.remove('apiKey');
ss.prefs.remove('firebaseURL');
ss.prefs.remove('clientID');
ss.prefs.remove('applicationID');
static void deleteFcmData() async {
await ss.prefs.remove('projectID');
await ss.prefs.remove('storageBucket');
await ss.prefs.remove('apiKey');
await ss.prefs.remove('firebaseURL');
await ss.prefs.remove('clientID');
await ss.prefs.remove('applicationID');
}
static FCMData getFCM() {

View File

@ -704,7 +704,7 @@ class Chat {
if (dateDeleted != null) {
dateDeleted = null;
save(updateDateDeleted: true);
chats.addChat(this);
await chats.addChat(this);
}
if (isArchived! && !_latestMessage!.isFromMe! && ss.settings.unarchiveOnNewMessage.value) {
toggleArchived(false);

View File

@ -41,23 +41,25 @@ class FCMData {
FCMData save() {
if (kIsWeb) return this;
fcmDataBox.put(this);
ss.prefs.setString('projectID', projectID!);
ss.prefs.setString('storageBucket', storageBucket!);
ss.prefs.setString('apiKey', apiKey!);
ss.prefs.setString('firebaseURL', firebaseURL!);
ss.prefs.setString('clientID', clientID!);
ss.prefs.setString('applicationID', applicationID!);
Future.delayed(Duration.zero, () async {
await ss.prefs.setString('projectID', projectID!);
await ss.prefs.setString('storageBucket', storageBucket!);
await ss.prefs.setString('apiKey', apiKey!);
await ss.prefs.setString('firebaseURL', firebaseURL!);
await ss.prefs.setString('clientID', clientID!);
await ss.prefs.setString('applicationID', applicationID!);
});
return this;
}
static void deleteFcmData() {
static void deleteFcmData() async {
fcmDataBox.removeAll();
ss.prefs.remove('projectID');
ss.prefs.remove('storageBucket');
ss.prefs.remove('apiKey');
ss.prefs.remove('firebaseURL');
ss.prefs.remove('clientID');
ss.prefs.remove('applicationID');
await ss.prefs.remove('projectID');
await ss.prefs.remove('storageBucket');
await ss.prefs.remove('apiKey');
await ss.prefs.remove('firebaseURL');
await ss.prefs.remove('clientID');
await ss.prefs.remove('applicationID');
}
static FCMData getFCM() {

View File

@ -141,7 +141,7 @@ class MethodChannelService extends GetxService {
final recentReplyGuid = ss.prefs.getString("recent-reply")?.split("/").first;
final recentReplyText = ss.prefs.getString("recent-reply")?.split("/").last;
if (recentReplyGuid == data["guid"] && recentReplyText == data["text"]) return;
ss.prefs.setString("recent-reply", "${data["guid"]}/${data["text"]}");
await ss.prefs.setString("recent-reply", "${data["guid"]}/${data["text"]}");
Logger.info("Updated recent reply cache to ${ss.prefs.getString("recent-reply")}");
Chat? chat = Chat.findOne(guid: data["chat"]);
if (chat == null) {

View File

@ -14,27 +14,25 @@ class ChatManager extends GetxService {
ChatLifecycleManager? activeChat;
final Map<String, ChatLifecycleManager> _chatControllers = {};
void setAllInactive() {
Future<void> setAllInactive() async {
Logger.debug('Setting all chats to inactive');
activeChat?.controller = null;
activeChat = null;
ss.prefs.remove('lastOpenedChat');
await ss.prefs.remove('lastOpenedChat');
_chatControllers.forEach((key, value) {
value.isActive = false;
value.isAlive = false;
});
}
void setActiveChat(Chat chat, {clearNotifications = true}) {
Future<void> setActiveChat(Chat chat, {clearNotifications = true}) async {
eventDispatcher.emit("update-highlight", chat.guid);
Logger.debug('Setting active chat to ${chat.guid} (${chat.displayName})');
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
await ss.prefs.setString('lastOpenedChat', chat.guid);
});
createChatController(chat, active: true);
await createChatController(chat, active: true);
await ss.prefs.setString('lastOpenedChat', chat.guid);
if (clearNotifications) {
chat.toggleHasUnread(false, force: true);
}
@ -52,7 +50,7 @@ class ChatManager extends GetxService {
bool isChatActive(String guid) => (getChatController(guid)?.isActive ?? false) && (getChatController(guid)?.isAlive ?? false);
ChatLifecycleManager createChatController(Chat chat, {active = false}) {
Future<ChatLifecycleManager> createChatController(Chat chat, {active = false}) async {
Logger.debug('Creating chat controller for ${chat.guid} (${chat.displayName})');
// If a chat is passed, get the chat and set it be active and make sure it's stored
@ -62,7 +60,7 @@ class ChatManager extends GetxService {
// If we are setting a new active chat, we need to clear the active statuses on
// all of the other chat controllers
if (active) {
setAllInactive();
await setAllInactive();
activeChat = controller;
}

View File

@ -43,14 +43,14 @@ class ChatsService extends GetxService {
// refresh the latest message
chat.dbLatestMessage;
}
addChat(chat);
await addChat(chat);
}
currentCount = newCount;
});
} else {
countSub = WebListeners.newChat.listen((chat) async {
if (!ss.settings.finishedSetup.value) return;
addChat(chat);
await addChat(chat);
});
}
}
@ -82,7 +82,7 @@ class ChatsService extends GetxService {
}
for (Chat c in temp) {
cm.createChatController(c);
await cm.createChatController(c);
}
newChats.addAll(temp);
@ -138,9 +138,9 @@ class ChatsService extends GetxService {
}
}
void addChat(Chat toAdd) {
Future<void> addChat(Chat toAdd) async {
chats.add(toAdd);
cm.createChatController(toAdd);
await cm.createChatController(toAdd);
sort();
}

View File

@ -317,7 +317,7 @@ class ThemesService extends GetxService {
return Platform.isWindows ? _applyWindowsAccent(light, dark) : _applyMonet(light, dark);
}
ThemeStruct revertToPreviousDarkTheme() {
Future<ThemeStruct> revertToPreviousDarkTheme() async {
List<ThemeStruct> allThemes = ThemeStruct.getThemes();
final darkName = ss.prefs.getString("previous-dark");
ThemeStruct? previous = allThemes.firstWhereOrNull((e) => e.name == darkName);
@ -325,12 +325,12 @@ class ThemesService extends GetxService {
previous ??= defaultThemes.firstWhere((element) => element.name == "OLED Dark");
// Remove the previous flags
ss.prefs.remove("previous-dark");
await ss.prefs.remove("previous-dark");
return previous;
}
ThemeStruct revertToPreviousLightTheme() {
Future<ThemeStruct> revertToPreviousLightTheme() async {
List<ThemeStruct> allThemes = ThemeStruct.getThemes();
final lightName = ss.prefs.getString("previous-light");
ThemeStruct? previous = allThemes.firstWhereOrNull((e) => e.name == lightName);
@ -338,16 +338,16 @@ class ThemesService extends GetxService {
previous ??= defaultThemes.firstWhere((element) => element.name == "Bright White");
// Remove the previous flags
ss.prefs.remove("previous-light");
await ss.prefs.remove("previous-light");
return previous;
}
void changeTheme(BuildContext context, {ThemeStruct? light, ThemeStruct? dark}) {
Future<void> changeTheme(BuildContext context, {ThemeStruct? light, ThemeStruct? dark}) async {
light?.save();
dark?.save();
if (light != null) ss.prefs.setString("selected-light", light.name);
if (dark != null) ss.prefs.setString("selected-dark", dark.name);
if (light != null) await ss.prefs.setString("selected-light", light.name);
if (dark != null) await ss.prefs.setString("selected-dark", dark.name);
_loadTheme(context);
}