Add Linux support

This commit is contained in:
2023-11-26 15:12:51 +08:00
parent 3dada54d8c
commit 9810214903
5 changed files with 29 additions and 4 deletions

View File

@@ -39,7 +39,7 @@ Config? _prefs;
EHApi? _api;
Future<String> _getJarPath() async {
if (isWindows) {
if (isWindows || isLinux) {
try {
final p = await platformPath.getCurrentExe();
if (p != null) {
@@ -60,7 +60,7 @@ Future<void> prepareJar() async {
}
Future<void> preparePrefs() async {
if (isWindows) {
if (isWindows || isLinux) {
try {
var tmp = WindowsConfig();
tmp.reload();

View File

@@ -17,7 +17,7 @@ class LogsFile {
IOSink? _cached;
Future<void> init() async {
if (_cachedLogDirectory != null) return;
if (isWindows) {
if (isWindows || isLinux) {
try {
final p = await platformPath.getCurrentExe();
if (p != null) {

View File

@@ -4,6 +4,7 @@ import 'package:flutter/foundation.dart';
bool get isDesktop =>
!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS);
bool get isWindows => !kIsWeb && Platform.isWindows;
bool get isLinux => !kIsWeb && Platform.isLinux;
bool get isAndroid => !kIsWeb && Platform.isAndroid;
bool get isIOS => !kIsWeb && Platform.isIOS;

View File

@@ -7,7 +7,7 @@ project(runner LANGUAGES CXX)
set(BINARY_NAME "eh_downloader_flutter")
# The unique GTK application identifier for this application. See:
# https://wiki.gnome.org/HowDoI/ChooseApplicationID
set(APPLICATION_ID "com.example.eh_downloader_flutter")
set(APPLICATION_ID "com.lifegpc.ehf")
# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
# versions of CMake.

View File

@@ -10,10 +10,28 @@
struct _MyApplication {
GtkApplication parent_instance;
char** dart_entrypoint_arguments;
FlMethodChannel* path_channel;
};
G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
static void on_path_channel_call(FlMethodChannel* channel, FlMethodCall* method_call,
gpointer user_data) {
const gchar* method = fl_method_call_get_name(method_call);
if (strcmp(method, "getCurrentExe") == 0) {
g_autoptr(GError) local_err = NULL;
gchar* exe_path = g_file_read_link("/proc/self/exe", &local_err);
if (local_err == NULL) {
fl_method_call_respond(method_call, FL_METHOD_RESPONSE(fl_method_success_response_new(fl_value_new_string(exe_path))), nullptr);
g_free(exe_path);
} else {
fl_method_call_respond_error(method_call, "get_current_exe_error", local_err->message, nullptr, nullptr);
}
} else {
fl_method_call_respond_not_implemented(method_call, nullptr);
}
}
// Implements GApplication::activate.
static void my_application_activate(GApplication* application) {
MyApplication* self = MY_APPLICATION(application);
@@ -58,6 +76,11 @@ static void my_application_activate(GApplication* application) {
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
fl_register_plugins(FL_PLUGIN_REGISTRY(view));
g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
self->path_channel = fl_method_channel_new(
fl_engine_get_binary_messenger(fl_view_get_engine(view)), "lifegpc.eh_downloader_flutter/path",
FL_METHOD_CODEC(codec));
fl_method_channel_set_method_call_handler(self->path_channel, on_path_channel_call, self, nullptr);
gtk_widget_grab_focus(GTK_WIDGET(view));
}
@@ -85,6 +108,7 @@ static gboolean my_application_local_command_line(GApplication* application, gch
static void my_application_dispose(GObject* object) {
MyApplication* self = MY_APPLICATION(object);
g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev);
g_clear_object(&self->path_channel);
G_OBJECT_CLASS(my_application_parent_class)->dispose(object);
}