Fix opening local files when default storage is set to cloud

This commit is contained in:
CodeDoctorDE
2026-03-09 21:16:39 +01:00
parent 499f238892
commit 931b574fa2
9 changed files with 23 additions and 27 deletions

View File

@@ -322,9 +322,7 @@ class ButterflyFileSystem {
Future<void> 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) {

View File

@@ -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))));

View File

@@ -1889,9 +1889,8 @@ class CurrentIndexCubit extends Cubit<CurrentIndex> {
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();

View File

@@ -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<ButterflySettings>
}
ExternalStorage? getRemote([String? remote]) {
return state.connections.firstWhereOrNull(
(element) => element.identifier == (remote ?? state.defaultRemote),
);
return state.getRemote(remote);
}
Future<void> toggleStarred(AssetLocation location) {

View File

@@ -31,12 +31,11 @@ class PenHandler extends Handler<PenTool> 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<Renderer>()
.toList();

View File

@@ -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;

View File

@@ -92,9 +92,7 @@ class _ProjectPageState extends State<ProjectPage> {
final fileSystem = context.read<ButterflyFileSystem>();
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) {

View File

@@ -31,9 +31,11 @@ class _ConnectionButtonState extends State<ConnectionButton> {
_updateConnection();
}
void _updateConnection() => _currentConnection = (widget.currentRemote == null
? null
: context.read<SettingsCubit>().state.getRemote(widget.currentRemote));
void _updateConnection() {
final currentRemote = widget.currentRemote;
final settingsCubit = context.read<SettingsCubit>();
_currentConnection = settingsCubit.getRemote(currentRemote ?? '');
}
@override
void didUpdateWidget(covariant ConnectionButton oldWidget) {

View File

@@ -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