Skip to content

Commit

Permalink
add linux kdf copy step & build step renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
takenagain committed Dec 23, 2024
1 parent 31cf94a commit 7858120
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/komodo_defi_framework/app_build/build_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"coins": {
"fetch_at_build_enabled": true,
"update_commit_on_build": true,
"bundled_coins_repo_commit": "642abea7172b81db24b16bffc13783b9a0e400f5",
"bundled_coins_repo_commit": "78be0d03414110e38f27521bd8b5a85e24cee3a0",
"coins_repo_api_url": "https://api.github.com/repos/KomodoPlatform/coins",
"coins_repo_content_url": "https://komodoplatform.github.io/coins",
"coins_repo_branch": "master",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,13 @@ class KdfOperationsLocalExecutable implements IKdfOperations {
final appSupportParentDir = Directory(p.dirname(appSupportDir.path));
final appSupportGrandParentDir =
Directory(p.dirname(appSupportParentDir.path));
final homeDir = Platform.environment['HOME'] ?? '';

final files = [
'/usr/local/bin/kdf',
'/usr/bin/kdf',
'$homeDir/.local/bin/kdf',
'$homeDir/bin/kdf',
p.join(Directory.current.path, 'kdf'),
p.join(Directory.current.path, 'kdf.exe'),
p.join(appSupportDir.path, 'kdf'),
Expand Down
11 changes: 11 additions & 0 deletions packages/komodo_defi_framework/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ target_include_directories(${PLUGIN_NAME} INTERFACE
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter)
target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK)

# Copy kdf binary to $HOME/.local/bin/kdf to make it accessible
set(FINAL_INSTALL_DIR "$ENV{HOME}/.local/bin")
set(KDF_PATH "${CMAKE_CURRENT_SOURCE_DIR}/bin/kdf")

add_custom_command(
TARGET ${PLUGIN_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${KDF_PATH}
"${FINAL_INSTALL_DIR}/kdf"
)

# List of absolute paths to libraries that should be bundled with the plugin
set(mm2_bundled_libraries
"${CMAKE_CURRENT_SOURCE_DIR}/libmm2.so"
Expand Down
40 changes: 40 additions & 0 deletions packages/komodo_defi_framework/linux/mm2_plugin.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <flutter_linux/flutter_linux.h>

#include "mm2_plugin.h"

struct _Mm2Plugin {
GObject parent_instance;
};

G_DEFINE_TYPE(Mm2Plugin, mm2_plugin, g_object_get_type())

static void mm2_plugin_dispose(GObject* object) {
G_OBJECT_CLASS(mm2_plugin_parent_class)->dispose(object);
}

static void mm2_plugin_class_init(Mm2PluginClass* klass) {
G_OBJECT_CLASS(klass)->dispose = mm2_plugin_dispose;
}

static void mm2_plugin_init(Mm2Plugin* self) {}

static void method_call_cb(FlMethodChannel* channel, FlMethodCall* method_call,
gpointer user_data) {
// Handle method calls here
}

void mm2_plugin_register_with_registrar(FlPluginRegistrar* registrar) {
Mm2Plugin* plugin = MM2_PLUGIN(
g_object_new(mm2_plugin_get_type(), nullptr));

g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
g_autoptr(FlMethodChannel) channel =
fl_method_channel_new(fl_plugin_registrar_get_messenger(registrar),
"mm2",
FL_METHOD_CODEC(codec));
fl_method_channel_set_method_call_handler(channel, method_call_cb,
g_object_ref(plugin),
g_object_unref);

g_object_unref(plugin);
}
16 changes: 16 additions & 0 deletions packages/komodo_defi_framework/linux/mm2_plugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef FLUTTER_PLUGIN_MM2_PLUGIN_H_
#define FLUTTER_PLUGIN_MM2_PLUGIN_H_

#include <flutter_linux/flutter_linux.h>

G_BEGIN_DECLS

#define MM2_TYPE_PLUGIN (mm2_plugin_get_type())

G_DECLARE_FINAL_TYPE(Mm2Plugin, mm2_plugin, MM2, PLUGIN, GObject)

void mm2_plugin_register_with_registrar(FlPluginRegistrar* registrar);

G_END_DECLS

#endif // FLUTTER_PLUGIN_MM2_PLUGIN_H_
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,23 @@ class FetchDefiApiStep extends BuildStep {
// file build size or if it is required for cache-busting.
}
if (_isBinaryExecutable(platform)) {
_renameExecutable(destinationFolder);
_setExecutablePermissions(destinationFolder);
}
return Future.value();
}

/// if executable is named "mm2" or "mm2.exe", then rename to "kdf"
void _renameExecutable(String destinationFolder) {
final executableName = Platform.isWindows ? 'mm2.exe' : 'mm2';
final executablePath = path.join(destinationFolder, executableName);
if (FileSystemEntity.isFileSync(executablePath)) {
final newExecutablePath = path.join(destinationFolder, 'kdf');
File(executablePath).renameSync(newExecutablePath);
_log.info('Renamed executable from $executableName to kdf');
}
}

Future<void> _extractZipFile(
String zipFilePath,
String destinationFolder,
Expand Down

0 comments on commit 7858120

Please sign in to comment.