Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions api/lib/src/helpers/asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ extension AssetFileTypeHelper on AssetFileType {
'application/x-text-butterfly',
'application/json',
],
AssetFileType.image => ['image/*'],
AssetFileType.image => [
'image/png',
'image/jpeg',
'image/gif',
'image/bmp',
'image/x-icon',
],
AssetFileType.markdown => ['text/markdown'],
AssetFileType.pdf => ['application/pdf'],
AssetFileType.svg => ['image/svg+xml'],
AssetFileType.page => ['application/json'],
AssetFileType.page => ['application/x-butterfly-page', 'application/json'],
AssetFileType.xopp => ['application/zip'],
AssetFileType.archive => [
'application/zip',
Expand All @@ -55,12 +61,7 @@ extension AssetFileTypeHelper on AssetFileType {
AssetFileType.rawText => ['text/plain'],
};

bool isMimeType(String mimeType) {
final mime = getMimeTypes();
return mime.any((m) {
return RegExp(m).hasMatch(mimeType);
});
}
bool isMimeType(String mimeType) => getMimeTypes().contains(mimeType);

bool isNote() => this == AssetFileType.note || this == AssetFileType.textNote;

Expand Down
12 changes: 1 addition & 11 deletions app/lib/api/save.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import 'dart:convert';
import 'dart:io';

import 'package:butterfly/helpers/asset.dart';
import 'package:butterfly_api/butterfly_api.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:butterfly/src/generated/i18n/app_localizations.dart';
import 'package:lw_sysapi/lw_sysapi.dart';
import 'package:super_clipboard/super_clipboard.dart';

Future<void> exportSvg(
BuildContext context,
Expand Down Expand Up @@ -92,13 +90,5 @@ Future<void> writeClipboardData(
AssetFileType type,
Uint8List data,
) async {
final clipboard = SystemClipboard.instance;
if (clipboard != null) {
final item = DataWriterItem();
final format = type.getClipboardFormats().first;
item.add(format(data));
clipboard.write([item]);
} else {
clipboardManager.setContent((data: data, type: type.name));
}
clipboardManager.setContent((data: data, type: type.getMimeTypes().first));
}
3 changes: 0 additions & 3 deletions app/lib/dialogs/collaboration/dialog.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'dart:convert';
import 'dart:io';
import 'dart:ui' as ui;

import 'package:butterfly/api/open.dart';
import 'package:butterfly/api/save.dart';
Expand All @@ -18,7 +16,6 @@ import 'package:networker/networker.dart';
import 'package:phosphor_flutter/phosphor_flutter.dart';
import 'package:barcode/barcode.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:super_clipboard/super_clipboard.dart';

part 'start.dart';
part 'view.dart';
Expand Down
27 changes: 1 addition & 26 deletions app/lib/dialogs/collaboration/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,7 @@ class ViewCollaborationDialog extends StatelessWidget {
child: IconButton.filledTonal(
icon: const Icon(PhosphorIconsLight.copy),
onPressed: () async {
final clipboard = SystemClipboard.instance;
if (clipboard == null) {
exportSvg(context, svg, false);
} else {
final item = DataWriterItem();
item.add(Formats.svg.lazy(() => utf8.encode(svg)));
item.add(
Formats.png.lazy(() async {
final PictureInfo pictureInfo = await vg
.loadPicture(SvgStringLoader(svg), null);
final image = await pictureInfo.picture.toImage(
256,
256,
);
final byteData = await image.toByteData(
format: ui.ImageByteFormat.png,
);
pictureInfo.picture.dispose();
image.dispose();
return byteData!.buffer.asUint8List();
}),
);
item.add(Formats.uri(NamedUri(uri)));
item.add(Formats.plainText(connect));
await clipboard.write([item]);
}
exportSvg(context, svg, false);
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
Expand Down
15 changes: 13 additions & 2 deletions app/lib/handlers/import.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,23 @@ class ImportHandler extends Handler<ImportTool> {
NoteData document,
AssetService assetService,
DocumentPage page,
EventContext context,
) async {
if (_renderers != null) return _renderers!;
final renderers = data.elements
.map((e) => Renderer.fromInstance(e))
.whereType<Renderer<PadElement>>()
.toList();
await Future.wait(
renderers.map(
(e) async => await e.setup(
context.getTransformCubit(),
document,
assetService,
page,
),
),
);
_renderers = renderers;
return renderers;
}
Expand Down Expand Up @@ -52,7 +63,7 @@ class ImportHandler extends Handler<ImportTool> {
_offset = transform.localToGlobal(localPosition);
final state = context.getState();
if (state == null) return;
await _load(state.data, state.assetService, state.page);
await _load(state.data, state.assetService, state.page, context);
context.refreshForegrounds();
}

Expand All @@ -69,7 +80,7 @@ class ImportHandler extends Handler<ImportTool> {
);
context.addDocumentEvent(
ElementsCreated(
(await _load(state.data, state.assetService, state.page))
(await _load(state.data, state.assetService, state.page, context))
.map(
(e) => e
.transform(position: _offset, relative: true)
Expand Down
32 changes: 0 additions & 32 deletions app/lib/helpers/asset.dart

This file was deleted.

74 changes: 15 additions & 59 deletions app/lib/services/import.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:archive/archive.dart';
import 'package:butterfly/api/file_system.dart';
import 'package:butterfly/cubits/current_index.dart';
import 'package:butterfly/cubits/transform.dart';
import 'package:butterfly/helpers/asset.dart';
import 'package:butterfly/services/asset.dart';
import 'package:butterfly_api/butterfly_text.dart' as text;
import 'package:flutter/foundation.dart';
Expand All @@ -27,7 +26,6 @@ import 'package:lw_sysapi/lw_sysapi.dart';
import 'package:material_leap/material_leap.dart';
import 'package:butterfly/src/generated/i18n/app_localizations.dart';
import 'package:pdfrx/pdfrx.dart';
import 'package:super_clipboard/super_clipboard.dart';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as p;

Expand Down Expand Up @@ -331,31 +329,6 @@ class ImportService {
};
}

Future<Uint8List?>? _readFileFromClipboard(
DataReader reader,
FileFormat format,
) {
final c = Completer<Uint8List?>();
final progress = reader.getFile(
format,
(file) async {
try {
final all = await file.readAll();
c.complete(all);
} catch (e) {
c.completeError(e);
}
},
onError: (e) {
c.completeError(e);
},
);
if (progress == null) {
c.complete(null);
}
return c.future;
}

@useResult
Future<ImportResult?> importClipboard(
NoteData document, {
Expand All @@ -364,38 +337,21 @@ class ImportService {
}) async {
Uint8List? data;
AssetFileType? type;
final clipboard = SystemClipboard.instance;
if (clipboard != null) {
final reader = await clipboard.read();
final result = AssetFileType.values
.map((e) {
final format = e.getClipboardFormats().firstWhereOrNull(
(f) => reader.canProvide(f),
);
return format == null ? null : (e, format);
})
.nonNulls
.firstOrNull;
if (result == null) return null;
if (result.$2 is FileFormat) {
data = await _readFileFromClipboard(reader, result.$2 as FileFormat);
} else if (result.$2 is ValueFormat<Uint8List>) {
data = await reader.readValue(result.$2 as ValueFormat<Uint8List>);
}
type = result.$1;
} else {
final clipboard = context.read<ClipboardManager>();
final content = clipboard.getContent();
data = content?.data;
try {
type = AssetFileType.values.byName(content?.type ?? '');
} catch (e) {
await showDialog(
context: context,
builder: (context) =>
UnknownImportConfirmationDialog(message: e.toString()),
);
}
final clipboard = context.read<ClipboardManager>();
final content = await clipboard.getContent(
types: AssetFileType.values.expand((e) => e.getMimeTypes()).toList(),
);
data = content?.data;
try {
type = AssetFileType.values.firstWhereOrNull(
(element) => element.isMimeType(content?.type ?? ''),
);
} catch (e) {
await showDialog(
context: context,
builder: (context) =>
UnknownImportConfirmationDialog(message: e.toString()),
);
}
if (data == null || type == null) return null;
return import(
Expand Down
8 changes: 0 additions & 8 deletions app/linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

#include <dynamic_color/dynamic_color_plugin.h>
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
#include <irondash_engine_context/irondash_engine_context_plugin.h>
#include <screen_retriever_linux/screen_retriever_linux_plugin.h>
#include <super_native_extensions/super_native_extensions_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
#include <window_manager/window_manager_plugin.h>

Expand All @@ -21,15 +19,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin");
flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar);
g_autoptr(FlPluginRegistrar) irondash_engine_context_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "IrondashEngineContextPlugin");
irondash_engine_context_plugin_register_with_registrar(irondash_engine_context_registrar);
g_autoptr(FlPluginRegistrar) screen_retriever_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverLinuxPlugin");
screen_retriever_linux_plugin_register_with_registrar(screen_retriever_linux_registrar);
g_autoptr(FlPluginRegistrar) super_native_extensions_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "SuperNativeExtensionsPlugin");
super_native_extensions_plugin_register_with_registrar(super_native_extensions_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
Expand Down
2 changes: 0 additions & 2 deletions app/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
list(APPEND FLUTTER_PLUGIN_LIST
dynamic_color
flutter_secure_storage_linux
irondash_engine_context
screen_retriever_linux
super_native_extensions
url_launcher_linux
window_manager
)
Expand Down
8 changes: 2 additions & 6 deletions app/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,30 @@ import Foundation

import connectivity_plus
import cryptography_flutter_plus
import device_info_plus
import dynamic_color
import file_picker
import flutter_secure_storage_darwin
import irondash_engine_context
import lw_sysapi
import network_info_plus
import package_info_plus
import screen_retriever_macos
import share_plus
import shared_preferences_foundation
import super_native_extensions
import url_launcher_macos
import window_manager

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin"))
CryptographyFlutterPlugin.register(with: registry.registrar(forPlugin: "CryptographyFlutterPlugin"))
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin"))
FilePickerPlugin.register(with: registry.registrar(forPlugin: "FilePickerPlugin"))
FlutterSecureStorageDarwinPlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStorageDarwinPlugin"))
IrondashEngineContextPlugin.register(with: registry.registrar(forPlugin: "IrondashEngineContextPlugin"))
SwiftLwSysapiPlugin.register(with: registry.registrar(forPlugin: "SwiftLwSysapiPlugin"))
NetworkInfoPlusPlugin.register(with: registry.registrar(forPlugin: "NetworkInfoPlusPlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
ScreenRetrieverMacosPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverMacosPlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SuperNativeExtensionsPlugin.register(with: registry.registrar(forPlugin: "SuperNativeExtensionsPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
}
Loading
Loading