Skip to content

Commit 75f40e9

Browse files
add-linux-support
1 parent c1d47af commit 75f40e9

10 files changed

Lines changed: 832 additions & 4 deletions

File tree

lib/core/data/local/remote/api/flowline_service.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,18 @@ class FlowlineService implements IFlowlineService {
5454
}
5555
}
5656

57-
await _secureStorage.write(flowLineKey, json.encode(decoded['flowLine']));
58-
final ref = ProviderContainer();
59-
final settings = ref.read(settingsProvider.notifier);
60-
await settings.updateSettingsBasedOnFlowLine();
57+
await _secureStorage.write(
58+
flowLineKey, json.encode(decoded['flowLine']));
59+
final ref = ProviderContainer();
60+
try {
61+
final settings = ref.read(settingsProvider.notifier);
62+
await settings.updateSettingsBasedOnFlowLine();
63+
} finally {
64+
ref.dispose();
65+
}
66+
} else {
67+
throw Exception('Invalid flowline format');
68+
}
6169
} else {
6270
throw Exception('Flowline is empty, cannot save');
6371
}

linux/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES})
106106
COMPONENT Runtime)
107107
endforeach(bundled_library)
108108

109+
if(DEFYX_DXCORE_LIB_SOURCE AND EXISTS "${DEFYX_DXCORE_LIB_SOURCE}")
110+
install(FILES "${DEFYX_DXCORE_LIB_SOURCE}"
111+
DESTINATION "${CMAKE_INSTALL_PREFIX}"
112+
COMPONENT Runtime)
113+
install(FILES "${DEFYX_DXCORE_LIB_SOURCE}"
114+
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
115+
COMPONENT Runtime)
116+
else()
117+
message(STATUS "DXcore library not available for installation; skipping bundle copy.")
118+
endif()
119+
109120
# Copy the native assets provided by the build.dart from all packages.
110121
set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/")
111122
install(DIRECTORY "${NATIVE_ASSETS_DIR}"

linux/runner/CMakeLists.txt

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ project(runner LANGUAGES CXX)
99
add_executable(${BINARY_NAME}
1010
"main.cc"
1111
"my_application.cc"
12+
"defyx_core.cpp"
13+
"defyx_linux_plugin.cc"
1214
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
1315
)
1416

@@ -22,5 +24,96 @@ add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
2224
# Add dependency libraries. Add any application-specific dependencies here.
2325
target_link_libraries(${BINARY_NAME} PRIVATE flutter)
2426
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
27+
target_link_libraries(${BINARY_NAME} PRIVATE dl)
2528

2629
target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
30+
31+
# --- DXcore native library build and packaging --------------------------------
32+
33+
# Allow overriding the DXcore source directory and built library via env vars.
34+
if(NOT DEFYX_DXCORE_DIR AND DEFINED ENV{DEFYX_DXCORE_DIR})
35+
set(DEFYX_DXCORE_DIR "$ENV{DEFYX_DXCORE_DIR}")
36+
endif()
37+
if(NOT DEFYX_DXCORE_LIB AND DEFINED ENV{DEFYX_DXCORE_LIB})
38+
set(DEFYX_DXCORE_LIB "$ENV{DEFYX_DXCORE_LIB}")
39+
endif()
40+
41+
get_filename_component(_runner_dir "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)
42+
43+
set(_dxcore_source_candidates "")
44+
if(DEFYX_DXCORE_LIB)
45+
get_filename_component(_override_lib "${DEFYX_DXCORE_LIB}" ABSOLUTE)
46+
list(APPEND _dxcore_source_candidates "${_override_lib}")
47+
endif()
48+
49+
set(_runner_local_lib "${_runner_dir}/libDXcore.so")
50+
list(APPEND _dxcore_source_candidates "${_runner_local_lib}")
51+
52+
if(DEFYX_DXCORE_DIR)
53+
get_filename_component(_dxcore_root "${DEFYX_DXCORE_DIR}" ABSOLUTE)
54+
else()
55+
get_filename_component(_dxcore_root "${_runner_dir}/../../../DXcore-private" ABSOLUTE)
56+
endif()
57+
58+
set(_dxcore_repo_lib "${_dxcore_root}/libDXcore.so")
59+
list(APPEND _dxcore_source_candidates "${_dxcore_repo_lib}")
60+
61+
set(_dxcore_source "")
62+
foreach(candidate IN LISTS _dxcore_source_candidates)
63+
if(EXISTS "${candidate}")
64+
set(_dxcore_source "${candidate}")
65+
break()
66+
endif()
67+
endforeach()
68+
69+
set(_have_dxcore_lib FALSE)
70+
71+
find_program(GO_EXECUTABLE go)
72+
if(NOT _dxcore_source AND GO_EXECUTABLE AND EXISTS "${_dxcore_root}")
73+
set(_dxcore_source "${_dxcore_repo_lib}")
74+
add_custom_target(dxcore_shared_lib
75+
COMMAND ${CMAKE_COMMAND} -E env GO111MODULE=on ${GO_EXECUTABLE} build -buildmode=c-shared -o "${_dxcore_source}" ./DXcore/linux
76+
WORKING_DIRECTORY "${_dxcore_root}"
77+
COMMENT "Building libDXcore.so via Go"
78+
VERBATIM
79+
)
80+
add_dependencies(${BINARY_NAME} dxcore_shared_lib)
81+
elseif(NOT _dxcore_source)
82+
if(NOT GO_EXECUTABLE)
83+
message(WARNING "Go executable not found; libDXcore.so will not be rebuilt automatically.")
84+
elseif(NOT EXISTS "${_dxcore_root}")
85+
message(WARNING "DXcore source directory '${_dxcore_root}' is missing; libDXcore.so cannot be rebuilt.")
86+
endif()
87+
endif()
88+
89+
if(_dxcore_source)
90+
set(_have_dxcore_lib TRUE)
91+
endif()
92+
93+
if(_have_dxcore_lib)
94+
set(DEFYX_DXCORE_LIB_SOURCE "${_dxcore_source}" PARENT_SCOPE)
95+
set(DEFYX_DXCORE_LIB_NAME "libDXcore.so" PARENT_SCOPE)
96+
endif()
97+
98+
if(NOT PROJECT_BUILD_DIR)
99+
set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/")
100+
endif()
101+
102+
set(_bundle_config "${CMAKE_BUILD_TYPE}")
103+
if("${_bundle_config}" STREQUAL "")
104+
set(_bundle_config "Debug")
105+
endif()
106+
string(TOLOWER "${_bundle_config}" _bundle_config_lower)
107+
set(_bundle_dir "${PROJECT_BUILD_DIR}linux/x64/${_bundle_config_lower}/bundle")
108+
109+
if(_have_dxcore_lib)
110+
add_custom_command(TARGET ${BINARY_NAME} POST_BUILD
111+
COMMAND ${CMAKE_COMMAND} -E make_directory "${_bundle_dir}"
112+
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_dxcore_source}" "${_bundle_dir}/libDXcore.so"
113+
COMMAND ${CMAKE_COMMAND} -E make_directory "${_bundle_dir}/lib"
114+
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_dxcore_source}" "${_bundle_dir}/lib/libDXcore.so"
115+
COMMENT "Copying libDXcore.so into Flutter Linux bundle (${_bundle_config_lower})"
116+
)
117+
else()
118+
message(WARNING "libDXcore.so not found and cannot be built; VPN core will be unavailable in the Linux build.")
119+
endif()

0 commit comments

Comments
 (0)