Skip to content

Commit

Permalink
Fix incorrect settings loading when updating DB by adding return to t…
Browse files Browse the repository at this point in the history
…he splash init function
  • Loading branch information
WilliamKarolDiCioccio committed Oct 13, 2024
1 parent 70b769d commit 03859e5
Showing 1 changed file with 44 additions and 37 deletions.
81 changes: 44 additions & 37 deletions app/lib/frontend/screens/splash.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,56 +37,62 @@ class SplashScreen extends StatelessWidget {

/// All loading and initialization code that returns or yields data
/// needed for the material app or locale provider creation must be placed in the main function.
Future<void> _init() async {
final prefs = await SharedPreferences.getInstance();
Future<bool> _init() async {
try {
final prefs = await SharedPreferences.getInstance();

// Supabase
// Supabase

await Supabase.initialize(
url: Env.supabaseUrl,
anonKey: Env.supabaseAnonKey,
);
await Supabase.initialize(
url: Env.supabaseUrl,
anonKey: Env.supabaseAnonKey,
);

// Rive
// Rive

await RiveFile.initialize();
await RiveFile.initialize();

// Discord RPC
// Discord RPC

final discordRPCEnabled = prefs.getBool('discordRPCEnabled') ?? false;
final discordRPCEnabled = prefs.getBool('discordRPCEnabled') ?? false;

if (discordRPCEnabled) {
DiscordRPC.initialize();
if (discordRPCEnabled) {
DiscordRPC.initialize();

final rpc = DiscordRPC(
applicationId: '1288789740338020392',
);
final rpc = DiscordRPC(
applicationId: '1288789740338020392',
);

rpc.start(autoRegister: true);
rpc.updatePresence(
DiscordPresence(
state: 'Chatting in OpenLocalUI 🚀',
details: 'github.com/WilliamKarolDiCioccio/open_local_ui',
startTimeStamp: DateTime.now().millisecondsSinceEpoch,
),
);
}
rpc.start(autoRegister: true);
rpc.updatePresence(
DiscordPresence(
state: 'Chatting in OpenLocalUI 🚀',
details: 'github.com/WilliamKarolDiCioccio/open_local_ui',
startTimeStamp: DateTime.now().millisecondsSinceEpoch,
),
);
}

// Dependency injection
// Dependency injection

final getIt = GetIt.instance;
final getIt = GetIt.instance;

getIt.registerSingleton<OllamaAPIProvider>(OllamaAPIProvider());
getIt.registerSingleton<ChatSessionsDB>(ChatSessionsDB());
getIt.registerSingleton<OllamaModelsDB>(OllamaModelsDB());
getIt.registerSingleton<OllamaAPIProvider>(OllamaAPIProvider());
getIt.registerSingleton<ChatSessionsDB>(ChatSessionsDB());
getIt.registerSingleton<OllamaModelsDB>(OllamaModelsDB());

await GetIt.instance<OllamaAPIProvider>().startOllama();
await GetIt.instance<ChatSessionsDB>().init();
await GetIt.instance<OllamaModelsDB>().init();
await GetIt.instance<OllamaAPIProvider>().startOllama();
await GetIt.instance<ChatSessionsDB>().init();
await GetIt.instance<OllamaModelsDB>().init();

// Preload assets
// Preload assets

await _preloadAssets();
} catch (e) {
return false;
}

await _preloadAssets();
return true;
}

@override
Expand All @@ -97,7 +103,8 @@ class SplashScreen extends StatelessWidget {
return FutureBuilder(
future: _init(),
builder: (context, snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
if (snapshot.connectionState != ConnectionState.done ||
!snapshot.hasData) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
Expand Down Expand Up @@ -126,7 +133,7 @@ class SplashScreen extends StatelessWidget {
backgroundColor: AdaptiveTheme.of(context).theme.primaryColor,
splashTransition: SplashTransition.fadeTransition,
pageTransitionType: PageTransitionType.theme,
duration: 1500,
duration: 750,
animationDuration: const Duration(seconds: 1),
);
},
Expand Down

0 comments on commit 03859e5

Please sign in to comment.