fix linux

This commit is contained in:
Naoufal 2023-03-03 12:35:47 -05:00
parent 7af41bcf45
commit dbae375ebd
16 changed files with 824 additions and 120 deletions

View File

@ -1,4 +1,8 @@
# This is a generated file; do not edit or check into version control. # This is a generated file; do not edit or check into version control.
bitsdojo_window=/home/naoufal/.pub-cache/hosted/pub.dev/bitsdojo_window-0.1.5/
bitsdojo_window_linux=/home/naoufal/.pub-cache/hosted/pub.dev/bitsdojo_window_linux-0.1.3/
bitsdojo_window_macos=/home/naoufal/.pub-cache/hosted/pub.dev/bitsdojo_window_macos-0.1.3/
bitsdojo_window_windows=/home/naoufal/.pub-cache/hosted/pub.dev/bitsdojo_window_windows-0.1.5/
device_info_plus=/home/naoufal/.pub-cache/hosted/pub.dev/device_info_plus-4.1.3/ device_info_plus=/home/naoufal/.pub-cache/hosted/pub.dev/device_info_plus-4.1.3/
device_info_plus_linux=/home/naoufal/.pub-cache/hosted/pub.dev/device_info_plus_linux-3.0.0/ device_info_plus_linux=/home/naoufal/.pub-cache/hosted/pub.dev/device_info_plus_linux-3.0.0/
device_info_plus_macos=/home/naoufal/.pub-cache/hosted/pub.dev/device_info_plus_macos-3.0.0/ device_info_plus_macos=/home/naoufal/.pub-cache/hosted/pub.dev/device_info_plus_macos-3.0.0/
@ -13,5 +17,3 @@ path_provider_linux=/home/naoufal/.pub-cache/hosted/pub.dev/path_provider_linux-
path_provider_windows=/home/naoufal/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.3/ path_provider_windows=/home/naoufal/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.3/
pdfx=/home/naoufal/.pub-cache/hosted/pub.dev/pdfx-2.3.0/ pdfx=/home/naoufal/.pub-cache/hosted/pub.dev/pdfx-2.3.0/
printing=/home/naoufal/.pub-cache/hosted/pub.dev/printing-5.10.1/ printing=/home/naoufal/.pub-cache/hosted/pub.dev/printing-5.10.1/
screen_retriever=/home/naoufal/.pub-cache/hosted/pub.dev/screen_retriever-0.1.6/
window_manager=/home/naoufal/.pub-cache/hosted/pub.dev/window_manager-0.3.0/

File diff suppressed because one or more lines are too long

14
.kdev4/pdf_tools.kdev4 Normal file
View File

@ -0,0 +1,14 @@
[Buildset]
BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00\x12\x00p\x00d\x00f\x00_\x00t\x00o\x00o\x00l\x00s)
[Launch]
Launch Configurations=Launch Configuration 0
[Launch][Launch Configuration 0]
Configured Launch Modes=execute
Configured Launchers=scriptAppLauncher
Name=New Script Application Launcher
Type=Script Application
[Project]
VersionControlSupport=kdevgit

View File

@ -1,19 +1,25 @@
import 'dart:io'; import 'dart:io';
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:file_picker/file_picker.dart'; import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:pdf/pdf.dart'; import 'package:pdf/pdf.dart';
import 'package:printing/printing.dart';
import 'package:pdf/widgets.dart' as pw; import 'package:pdf/widgets.dart' as pw;
import 'package:window_manager/window_manager.dart'; import 'package:printing/printing.dart';
Future<void> main() async { Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
// Must add this line.
await windowManager.ensureInitialized();
if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) { if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
await windowManager.setSize(const Size(450, 300)); doWhenWindowReady(() {
const initialSize = Size(600, 300);
appWindow.minSize = initialSize;
appWindow.maxSize = initialSize;
appWindow.size = initialSize;
appWindow.alignment = Alignment.center;
appWindow.show();
});
} }
runApp(const MyApp()); runApp(const MyApp());
} }
@ -28,15 +34,126 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> { class _MyAppState extends State<MyApp> {
String _openFilePath = ""; String _openFilePath = "";
bool loading = false;
String? _encryption = ""; String? _encryption = "";
double _dpi = 200; double _dpi = 200;
@override
Widget build(BuildContext context) {
// test();
return MaterialApp(
home: Scaffold(
//appBar: AppBar(title: const Text("PDF Tools")),
body: Row(
children: [
RightSide(
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(children: [
Row(
children: [
Expanded(
child: ElevatedButton(
onPressed: (loading) ? null : () => openFile(),
child: Flex(
direction: Axis.vertical,
children: const [
Icon(Icons.folder),
Text("Open pdf")
],
)),
),
const SizedBox(
width: 10,
),
Expanded(
child: ElevatedButton(
onPressed: (_openFilePath.isEmpty || loading)
? null
: () => saveFile(),
child: Flex(
direction: Axis.vertical,
children: const [
Icon(Icons.save),
Text("save"),
],
)),
),
],
),
Padding(
padding: const EdgeInsets.only(top: 10, bottom: 10),
child: Row(
children: [
Expanded(
child: Container(
decoration: BoxDecoration(
borderRadius:
const BorderRadius.all(Radius.circular(5)),
border: Border.all(
color: Colors.grey,
width: 1,
)),
padding: const EdgeInsets.only(top: 10, bottom: 10),
child: Padding(
padding: const EdgeInsets.only(left: 5, right: 5),
child: Text(_openFilePath),
),
),
),
],
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max,
children: [
const Text("Quality :"),
Expanded(
child: Slider(
min: 100,
max: 500,
divisions: 20,
label: _dpi.toString(),
value: _dpi,
onChanged: (_openFilePath.isEmpty || loading)
? null
: (value) {
setState(() {
_dpi = value;
});
},
),
),
Text(_dpi.toString()),
],
),
const SizedBox(height: 10),
TextField(
enabled: (_openFilePath.isNotEmpty),
decoration: const InputDecoration(
labelText: 'Encrypt (Optional)',
border: OutlineInputBorder(),
),
controller: TextEditingController(text: _encryption),
onSubmitted: (value) {
setState(() {
_encryption = value;
});
},
),
const SizedBox(height: 10),
]),
))
],
),
),
);
}
Future convert(String savePath) async { Future convert(String savePath) async {
final pdf = pw.Document(); final pdf = pw.Document();
final file = File(savePath); final file = File(savePath);
final doc = await File(_openFilePath).readAsBytes();
final openddPdf = await rootBundle.load(_openFilePath);
var doc = openddPdf.buffer.asUint8List();
// var tempDir = Directory.systemTemp.createTempSync(); // var tempDir = Directory.systemTemp.createTempSync();
// int index = 1; // int index = 1;
@ -60,111 +177,79 @@ class _MyAppState extends State<MyApp> {
} }
void openFile() async { void openFile() async {
setState(() {
loading = true;
});
FilePickerResult? result = await FilePicker.platform FilePickerResult? result = await FilePicker.platform
.pickFiles(allowMultiple: false, lockParentWindow: true); .pickFiles(allowMultiple: false, lockParentWindow: true);
if (result != null) { if (result != null) {
setState(() { setState(() {
_openFilePath = result.files.first.path!; _openFilePath = result.files.first.path!;
}); });
} else {
// User canceled the picker
} }
setState(() {
loading = false;
});
} }
Future saveFile() async { Future saveFile() async {
setState(() {
loading = true;
});
var savePath = await FilePicker.platform var savePath = await FilePicker.platform
.saveFile(allowedExtensions: ['pdf'], lockParentWindow: true); .saveFile(allowedExtensions: ['pdf'], lockParentWindow: true);
if (savePath != null) { if (savePath != null) {
return await convert(savePath); await convert(savePath);
} else { }
// User canceled the picker setState(() {
loading = false;
});
} }
} }
final backgroundStartColor = Colors.grey.shade50;
final backgroundEndColor = Colors.grey.shade300;
// ignore: must_be_immutable
class RightSide extends StatelessWidget {
RightSide({Key? key, required this.body}) : super(key: key);
Widget body;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// test(); return Expanded(
return MaterialApp( child: Container(
home: Scaffold( decoration: BoxDecoration(
appBar: AppBar(title: const Text("PDF Tools")), gradient: LinearGradient(
body: SizedBox( begin: Alignment.topCenter,
width: double.infinity, end: Alignment.bottomCenter,
child: Padding( colors: [backgroundStartColor, backgroundEndColor],
padding: const EdgeInsets.all(8.0), stops: const [0.0, 1.0]),
child: Column( ),
child: Column(children: [
WindowTitleBarBox(
child: Row(
children: [ children: [
Text(_openFilePath), Expanded(child: MoveWindow()),
Column(children: [ const WindowButtons(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max,
children: [
const Text("Quality :"),
Expanded(
child: Slider(
min: 100,
max: 500,
divisions: 20,
label: _dpi.toString(),
value: _dpi,
onChanged: (value) {
setState(() {
_dpi = value;
});
},
),
),
Text(_dpi.toString()),
],
),
const SizedBox(height: 10),
TextField(
decoration: const InputDecoration(
labelText: 'Encrypt (Optional)',
border: OutlineInputBorder(),
),
controller: TextEditingController(text: _encryption),
onSubmitted: (value) {
setState(() {
_encryption = value;
});
},
),
const SizedBox(height: 10),
Row(
children: [
ElevatedButton(
onPressed: () => openFile(),
child: Flex(
direction: Axis.vertical,
children: const [
Icon(Icons.folder),
Text("Open pdf")
],
)),
ElevatedButton(
onPressed: () async {
await saveFile();
showDialog(
context: context,
builder: (context) => Text("ok"),
);
},
child: Flex(
direction: Axis.vertical,
children: const [
Icon(Icons.save),
Text("save"),
],
)),
],
),
])
], ],
), ),
), ),
), body
]),
), ),
); );
} }
} }
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(),
CloseWindowButton(),
],
);
}
}

View File

@ -6,18 +6,14 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <bitsdojo_window_linux/bitsdojo_window_plugin.h>
#include <printing/printing_plugin.h> #include <printing/printing_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <window_manager/window_manager_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) { void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) bitsdojo_window_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "BitsdojoWindowPlugin");
bitsdojo_window_plugin_register_with_registrar(bitsdojo_window_linux_registrar);
g_autoptr(FlPluginRegistrar) printing_registrar = g_autoptr(FlPluginRegistrar) printing_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "PrintingPlugin"); fl_plugin_registry_get_registrar_for_plugin(registry, "PrintingPlugin");
printing_plugin_register_with_registrar(printing_registrar); printing_plugin_register_with_registrar(printing_registrar);
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
g_autoptr(FlPluginRegistrar) window_manager_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
window_manager_plugin_register_with_registrar(window_manager_registrar);
} }

View File

@ -3,9 +3,8 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
bitsdojo_window_linux
printing printing
screen_retriever
window_manager
) )
list(APPEND FLUTTER_FFI_PLUGIN_LIST list(APPEND FLUTTER_FFI_PLUGIN_LIST

View File

@ -1,3 +1,4 @@
#include <bitsdojo_window_linux/bitsdojo_window_plugin.h>
#include "my_application.h" #include "my_application.h"
#include <flutter_linux/flutter_linux.h> #include <flutter_linux/flutter_linux.h>
@ -47,7 +48,9 @@ static void my_application_activate(GApplication* application) {
gtk_window_set_title(window, "pdf_tools"); gtk_window_set_title(window, "pdf_tools");
} }
gtk_window_set_default_size(window, 1280, 720); auto bdw = bitsdojo_window_from(window); // <--- add this line
bdw->setCustomFrame(true); // <-- add this line
//gtk_window_set_default_size(window, 1280, 720); // <-- comment this line
gtk_widget_show(GTK_WIDGET(window)); gtk_widget_show(GTK_WIDGET(window));
g_autoptr(FlDartProject) project = fl_dart_project_new(); g_autoptr(FlDartProject) project = fl_dart_project_new();

View File

@ -5,18 +5,16 @@
import FlutterMacOS import FlutterMacOS
import Foundation import Foundation
import bitsdojo_window_macos
import device_info_plus_macos import device_info_plus_macos
import path_provider_foundation import path_provider_foundation
import pdfx import pdfx
import printing import printing
import screen_retriever
import window_manager
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
BitsdojoWindowPlugin.register(with: registry.registrar(forPlugin: "BitsdojoWindowPlugin"))
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin")) DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
PdfxPlugin.register(with: registry.registrar(forPlugin: "PdfxPlugin")) PdfxPlugin.register(with: registry.registrar(forPlugin: "PdfxPlugin"))
PrintingPlugin.register(with: registry.registrar(forPlugin: "PrintingPlugin")) PrintingPlugin.register(with: registry.registrar(forPlugin: "PrintingPlugin"))
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
} }

4
pdf_tools.kdev4 Normal file
View File

@ -0,0 +1,4 @@
[Project]
CreatedFrom=
Manager=KDevGenericManager
Name=pdf_tools

11
pdf_tools.sublime-project Normal file
View File

@ -0,0 +1,11 @@
{
"folders":
[
{
"path": ".",
}
],
"debugger_configurations":
[
],
}

596
pdf_tools.sublime-workspace Normal file

File diff suppressed because one or more lines are too long

View File

@ -41,9 +41,9 @@ dependencies:
path_provider: ^2.0.12 path_provider: ^2.0.12
pdfx: ^2.3.0 pdfx: ^2.3.0
printing: ^5.10.1 printing: ^5.10.1
window_manager: ^0.3.0
flutter_localizations: flutter_localizations:
sdk: flutter sdk: flutter
bitsdojo_window: ^0.1.5
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

BIN
tt

Binary file not shown.

BIN
tt.pdf

Binary file not shown.

View File

@ -6,18 +6,15 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <bitsdojo_window_windows/bitsdojo_window_plugin.h>
#include <pdfx/pdfx_plugin.h> #include <pdfx/pdfx_plugin.h>
#include <printing/printing_plugin.h> #include <printing/printing_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <window_manager/window_manager_plugin.h>
void RegisterPlugins(flutter::PluginRegistry* registry) { void RegisterPlugins(flutter::PluginRegistry* registry) {
BitsdojoWindowPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("BitsdojoWindowPlugin"));
PdfxPluginRegisterWithRegistrar( PdfxPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PdfxPlugin")); registry->GetRegistrarForPlugin("PdfxPlugin"));
PrintingPluginRegisterWithRegistrar( PrintingPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PrintingPlugin")); registry->GetRegistrarForPlugin("PrintingPlugin"));
ScreenRetrieverPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
WindowManagerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
} }

View File

@ -3,10 +3,9 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
bitsdojo_window_windows
pdfx pdfx
printing printing
screen_retriever
window_manager
) )
list(APPEND FLUTTER_FFI_PLUGIN_LIST list(APPEND FLUTTER_FFI_PLUGIN_LIST