fix: survive corrupt preferences at startup; drop CocoaPods leftovers
Some checks failed
Security / Security check (push) Failing after 2s

A black window on launch, no error anywhere: main() awaited
loadPersistedEndpoint before the first frame, and
SharedPreferences.getBool threw 'int is not a subtype of bool?' —
the store is writable from outside the app and hub.secure had been
written as int 0. Pref reads now go through defensive typed helpers
(int coerces to bool, wrong types fall back to defaults), and every
pre-frame restore step is failure-isolated: a broken store can cost
a preference, never the first frame. Regression tests stage the
corrupt store (the exact observed value and worse).

Also removes the CocoaPods leftovers from the macOS project
(Podfile, [CP] script phases, Pods framework references, xcconfig
includes): the project builds via Swift Package Manager, and the
dual wiring ran both dependency managers on every build — Flutter's
persistent 'removing CocoaPods will improve build time' warning.
Verified: clean profile build produces a launchable bundle (plugins
statically linked via SwiftPM), suite green, analyze clean.

Signed-off-by: flemming-it <stefan.a.flemming@googlemail.com>
This commit is contained in:
flemming-it 2026-07-15 10:46:22 +02:00
parent 61ca365d5e
commit 06f023aada
9 changed files with 130 additions and 148 deletions

View file

@ -34,16 +34,44 @@ import 'widgets/widgets.dart';
/// and quick-glance proof that you're seeing the current build.
const String kStudioVersion = '0.70.0';
/// Run one pre-frame restore step, absorbing any failure. Everything
/// before `runApp` is a black window waiting to happen: an exception
/// here (a corrupt preference store, an unreadable file) used to kill
/// startup with no visible error at all. Each step degrades to its
/// default instead; the app MUST reach the first frame.
Future<T> _restoreOr<T>(T fallback, Future<T> Function() step) async {
try {
return await step();
} catch (e) {
debugPrint('startup restore step failed (using default): $e');
return fallback;
}
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// Restore the persisted endpoint, theme mode, locale, and
// (when installed) the operator's theme-plugin choice
// before the first frame so nothing flickers on startup.
await HubService.instance.loadPersistedEndpoint();
await SystemActions.loadFaiBinaryOverride();
final themeMode = await HubService.instance.loadThemeMode();
final locale = await HubService.instance.loadLocale();
final themePlugin = await loadActiveThemePlugin();
// Every step is failure-isolated: one broken store must not
// stop the others, and nothing here may prevent runApp.
await _restoreOr(null, () async {
await HubService.instance.loadPersistedEndpoint();
return null;
});
await _restoreOr(null, () async {
await SystemActions.loadFaiBinaryOverride();
return null;
});
final themeMode = await _restoreOr(
ThemeModeValue.system,
() => HubService.instance.loadThemeMode(),
);
final locale = await _restoreOr(
const Locale('en'),
() => HubService.instance.loadLocale(),
);
final themePlugin = await _restoreOr(null, loadActiveThemePlugin);
runApp(
StudioApp(
initialThemeMode: themeMode,