diff --git a/app/lib/api/file_system.dart b/app/lib/api/file_system.dart index 94dfee2a19..339be16e88 100644 --- a/app/lib/api/file_system.dart +++ b/app/lib/api/file_system.dart @@ -322,9 +322,7 @@ class ButterflyFileSystem { Future updatePack(PackAssetLocation location, NoteData newPack) => buildPackSystem( - location.namespace.isEmpty - ? null - : settingsCubit.state.getRemote(location.namespace), + settingsCubit.getRemote(location.namespace), ).updateFile(location.key, newPack); void removeCachedDocumentSystem(ExternalStorage? storage) { diff --git a/app/lib/bloc/document_state.dart b/app/lib/bloc/document_state.dart index 39129fa2f6..37fcfdb71f 100644 --- a/app/lib/bloc/document_state.dart +++ b/app/lib/bloc/document_state.dart @@ -256,7 +256,7 @@ class DocumentLoadSuccess extends DocumentLoaded { !absolute && (location.fileType?.isNote() ?? false) && (location.remote.isEmpty || - (settingsCubit.state + (settingsCubit .getRemote(location.remote) ?.hasDocumentCached(location.path) ?? false)))); diff --git a/app/lib/cubits/current_index.dart b/app/lib/cubits/current_index.dart index 3c23073f96..b8678db68d 100644 --- a/app/lib/cubits/current_index.dart +++ b/app/lib/cubits/current_index.dart @@ -1889,9 +1889,8 @@ class CurrentIndexCubit extends Cubit { void exitHideUI() => emit(state.copyWith(hideUi: HideState.visible)); - ExternalStorage? getRemoteStorage() => state.location.remote.isEmpty - ? null - : state.settingsCubit.state.getRemote(state.location.remote); + ExternalStorage? getRemoteStorage() => + state.settingsCubit.getRemote(state.location.remote); final _savingLock = Lock(); diff --git a/app/lib/cubits/settings.dart b/app/lib/cubits/settings.dart index 2f5054fd13..d55bb56cdb 100644 --- a/app/lib/cubits/settings.dart +++ b/app/lib/cubits/settings.dart @@ -666,12 +666,13 @@ sealed class ButterflySettings with _$ButterflySettings, LeapSettings { } ExternalStorage? getRemote(String? identifier) { - if (identifier?.isEmpty ?? true) { + if (identifier == null) { return getDefaultRemote(); } - return connections.firstWhereOrNull( - (e) => e.identifier == (identifier ?? defaultRemote), - ); + if (identifier.isEmpty) { + return null; + } + return connections.firstWhereOrNull((e) => e.identifier == identifier); } bool hasRemote(String identifier) { @@ -1043,9 +1044,7 @@ class SettingsCubit extends Cubit } ExternalStorage? getRemote([String? remote]) { - return state.connections.firstWhereOrNull( - (element) => element.identifier == (remote ?? state.defaultRemote), - ); + return state.getRemote(remote); } Future toggleStarred(AssetLocation location) { diff --git a/app/lib/handlers/pen.dart b/app/lib/handlers/pen.dart index a7d171ad1c..2571b79be7 100644 --- a/app/lib/handlers/pen.dart +++ b/app/lib/handlers/pen.dart @@ -31,12 +31,11 @@ class PenHandler extends Handler with ColoredHandler { DocumentInfo info, [ Area? currentArea, ]) => [...elements.values, ..._submittedElements] - .map((e) { - if (e.points.length > 1) { - return PenRenderer(e.copyWith(id: createUniqueId())); - } - return null; - }) + .map( + (e) => e.points.length > 1 + ? PenRenderer(e.copyWith(id: createUniqueId())) + : null, + ) .whereType() .toList(); diff --git a/app/lib/services/sync.dart b/app/lib/services/sync.dart index 73d17e79a8..a7ea603b7e 100644 --- a/app/lib/services/sync.dart +++ b/app/lib/services/sync.dart @@ -444,7 +444,7 @@ class SyncService { } RemoteSync? _createSync(String remote) { - final storage = settingsCubit.state.getRemote(remote); + final storage = settingsCubit.getRemote(remote); if (storage == null) { talker.warning('Remote storage not found: $remote'); return null; diff --git a/app/lib/views/main.dart b/app/lib/views/main.dart index 88b188d0a4..c46947466b 100644 --- a/app/lib/views/main.dart +++ b/app/lib/views/main.dart @@ -92,9 +92,7 @@ class _ProjectPageState extends State { final fileSystem = context.read(); var location = widget.location; final absolute = widget.absolute; - final remote = location != null - ? settingsCubit.state.getRemote(location.remote) - : settingsCubit.state.getDefaultRemote(); + final remote = settingsCubit.getRemote(location?.remote); final documentSystem = fileSystem.buildDocumentSystem(remote); final embedding = widget.embedding; if (embedding != null) { diff --git a/app/lib/widgets/connection_button.dart b/app/lib/widgets/connection_button.dart index aaf0174819..0606691bdb 100644 --- a/app/lib/widgets/connection_button.dart +++ b/app/lib/widgets/connection_button.dart @@ -31,9 +31,11 @@ class _ConnectionButtonState extends State { _updateConnection(); } - void _updateConnection() => _currentConnection = (widget.currentRemote == null - ? null - : context.read().state.getRemote(widget.currentRemote)); + void _updateConnection() { + final currentRemote = widget.currentRemote; + final settingsCubit = context.read(); + _currentConnection = settingsCubit.getRemote(currentRemote ?? ''); + } @override void didUpdateWidget(covariant ConnectionButton oldWidget) { diff --git a/metadata/en-US/changelogs/170.txt b/metadata/en-US/changelogs/170.txt index cd624c7112..cf71890052 100644 --- a/metadata/en-US/changelogs/170.txt +++ b/metadata/en-US/changelogs/170.txt @@ -3,6 +3,7 @@ * Add option to enable/disable thumbnails for notes ([#984](https://github.com/LinwoodDev/Butterfly/issues/984)) * Add favorite templates to settings export * Add long press action for double/triple touch shortcuts +* Fix opening local files when default storage is set to cloud * Fix stamp handler * Fix scaling on multiple elements * Fix preview element will shown after submitting