diff --git a/contrib/mac.sh b/contrib/mac.sh index 855f6bcc5..9460fd3bc 100755 --- a/contrib/mac.sh +++ b/contrib/mac.sh @@ -25,7 +25,7 @@ cmake \ -DCMAKE_BUILD_TYPE=Release \ "$@" \ .. -ninja sign +ninja sign -j1 echo -e "Build complete, your app is here:\n" ls -lad $(pwd)/Lokinet.app diff --git a/contrib/macos/lokinet.Info.plist.in b/contrib/macos/lokinet.Info.plist.in index c03953cde..6608e7b30 100644 --- a/contrib/macos/lokinet.Info.plist.in +++ b/contrib/macos/lokinet.Info.plist.in @@ -9,7 +9,7 @@ Lokinet CFBundleExecutable - Lokinet + lokinet-gui CFBundleIdentifier org.lokinet diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt index 93e93162a..07841ff81 100644 --- a/daemon/CMakeLists.txt +++ b/daemon/CMakeLists.txt @@ -1,4 +1,3 @@ - set(exetargets lokinet) if(APPLE) @@ -56,7 +55,6 @@ foreach(exe ${exetargets}) endif() target_link_libraries(${exe} PUBLIC liblokinet) target_include_directories(${exe} PUBLIC "${PROJECT_SOURCE_DIR}") - add_log_tag(${exe}) if(should_install) if(APPLE) install(TARGETS ${exe} @@ -69,6 +67,36 @@ foreach(exe ${exetargets}) endif() endforeach() +set(default_with_gui OFF) +if(APPLE) + set(default_with_gui ON) +endif() + +option(WITH_GUI "build electron gui from source" ${default_with_gui}) + +if (WITH_GUI) + find_program(YARN yarn REQUIRED) + message(STATUS "Found yarn: ${YARN}") + if(NOT GUI_GIT_REPO) + set(GUI_GIT_REPO "https://github.com/oxen-io/lokinet-gui") + endif() + if(NOT GUI_GIT_BRANCH) + set(GUI_GIT_BRANCH "stable") + endif() + if(NOT YARN_TARGET) + set(YARN_TARGET pack:raw) + if(APPLE) + set(YARN_TARGET macos:raw) + endif() + endif() + message(STATUS "will build gui: ${GUI_GIT_REPO} (branch: ${GUI_GIT_BRANCH}) using ${YARN} ${YARN_TARGET}") + add_custom_target(lokinet-gui + COMMAND rm -rf "${PROJECT_BINARY_DIR}/lokinet-gui" && git clone "${GUI_GIT_REPO}" -b ${GUI_GIT_BRANCH} "${PROJECT_BINARY_DIR}/lokinet-gui" && cd "${PROJECT_BINARY_DIR}/lokinet-gui" && ${YARN} install --frozen-lockfile && ${YARN} ${YARN_TARGET}) +else() + message(STATUS "not building gui") + add_custom_target(lokinet-gui COMMAND "true") +endif() + if(APPLE) option(MACOS_SYSTEM_EXTENSION "Build the network extension as a system extension rather than a plugin. This must be ON for non-app store release builds, and must be OFF for dev builds and Mac App Store distribution builds" @@ -154,18 +182,9 @@ if(APPLE) $/Contents/embedded.provisionprofile) endif() - add_custom_command(TARGET lokinet - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROJECT_SOURCE_DIR}/contrib/bootstrap/mainnet.signed - $/Contents/Resources/bootstrap.signed - COMMAND mkdir -p $/${lokinet_ext_dir} - COMMAND cp -a $ $/${lokinet_ext_dir} - ${post_build_pp} - ) - set_target_properties(lokinet PROPERTIES - OUTPUT_NAME Lokinet + OUTPUT_NAME Lokinet MACOSX_BUNDLE TRUE MACOSX_BUNDLE_INFO_STRING "Lokinet IP Packet Onion Router" MACOSX_BUNDLE_BUNDLE_NAME "Lokinet" @@ -178,15 +197,29 @@ if(APPLE) MACOSX_BUNDLE_COPYRIGHT "© 2022, The Oxen Project" RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}" ) + set(copy_gui) + if(BUILD_GUI) + set(copy_gui COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_BINARY_DIR}/lokinet-gui/release/mac/lokinet-gui.app $) + endif() + + add_custom_target(assemble + DEPENDS lokinet lokinet-extension lokinet-gui + ${copy_gui} + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROJECT_SOURCE_DIR}/contrib/bootstrap/mainnet.signed + $/Contents/Resources/bootstrap.signed + COMMAND mkdir -p $/${lokinet_ext_dir} + COMMAND cp -a $ $/${lokinet_ext_dir} + ${post_build_pp}) if(NOT CODESIGN) message(STATUS "codesigning disabled") add_custom_target( sign - DEPENDS lokinet lokinet-extension + DEPENDS assemble COMMAND "true") + elseif(CODESIGN) - set(SIGN_TARGET "${PROJECT_BINARY_DIR}/lokinet.app") + set(SIGN_TARGET "${PROJECT_BINARY_DIR}/Lokinet.app") if(MACOS_SYSTEM_EXTENSION) set(LOKINET_ENTITLEMENTS_TYPE sysext) else() @@ -198,7 +231,7 @@ if(APPLE) @ONLY) add_custom_target( sign - DEPENDS "${PROJECT_BINARY_DIR}/sign.sh" lokinet lokinet-extension + DEPENDS "${PROJECT_BINARY_DIR}/sign.sh" assemble COMMAND "${PROJECT_BINARY_DIR}/sign.sh" ) diff --git a/daemon/lokinet.swift b/daemon/lokinet.swift index 1d8e0a106..319c16af5 100644 --- a/daemon/lokinet.swift +++ b/daemon/lokinet.swift @@ -16,14 +16,13 @@ class LokinetMain: NSObject, NSApplicationDelegate { let netextBundleId = "org.lokinet.network-extension" func applicationDidFinishLaunching(_: Notification) { - if self.mode == START { + if mode == START { startNetworkExtension() - } else if self.mode == STOP { + } else if mode == STOP { tearDownVPNTunnel() } else { - self.result(msg: HELP_STRING) + result(msg: HELP_STRING) } - } func bail() { @@ -33,7 +32,7 @@ class LokinetMain: NSObject, NSApplicationDelegate { func result(msg: String) { NSLog(msg) // TODO: does lokinet continue after this? - self.bail() + bail() } func tearDownVPNTunnel() { @@ -58,19 +57,18 @@ class LokinetMain: NSObject, NSApplicationDelegate { } func startNetworkExtension() { -#if MACOS_SYSTEM_EXTENSION - NSLog("Loading Lokinet network extension") - // Start by activating the system extension - let activationRequest = OSSystemExtensionRequest.activationRequest(forExtensionWithIdentifier: netextBundleId, queue: .main) - activationRequest.delegate = self - OSSystemExtensionManager.shared.submitRequest(activationRequest) -#else - setupVPNTunnel() -#endif + #if MACOS_SYSTEM_EXTENSION + NSLog("Loading Lokinet network extension") + // Start by activating the system extension + let activationRequest = OSSystemExtensionRequest.activationRequest(forExtensionWithIdentifier: netextBundleId, queue: .main) + activationRequest.delegate = self + OSSystemExtensionManager.shared.submitRequest(activationRequest) + #else + setupVPNTunnel() + #endif } func setupVPNTunnel() { - NSLog("Starting up Lokinet tunnel") NETunnelProviderManager.loadAllFromPreferences { [self] (savedManagers: [NETunnelProviderManager]?, error: Error?) in if let error = error { @@ -113,7 +111,7 @@ class LokinetMain: NSObject, NSApplicationDelegate { self.initializeConnectionObserver() try self.vpnManager.connection.startVPNTunnel() } catch let error as NSError { - self.result(msg: error.localizedDescription) + self.result(msg: error.localizedDescription) } catch { self.result(msg: "There was a fatal error") } @@ -145,32 +143,32 @@ class LokinetMain: NSObject, NSApplicationDelegate { #if MACOS_SYSTEM_EXTENSION -extension LokinetMain: OSSystemExtensionRequestDelegate { - - func request(_ request: OSSystemExtensionRequest, didFinishWithResult result: OSSystemExtensionRequest.Result) { - guard result == .completed else { - NSLog("Unexpected result %d for system extension request", result.rawValue) - return + extension LokinetMain: OSSystemExtensionRequestDelegate { + func request(_: OSSystemExtensionRequest, didFinishWithResult result: OSSystemExtensionRequest.Result) { + guard result == .completed else { + NSLog("Unexpected result %d for system extension request", result.rawValue) + return + } + NSLog("Lokinet system extension loaded") + setupVPNTunnel() } - NSLog("Lokinet system extension loaded") - setupVPNTunnel() - } - func request(_ request: OSSystemExtensionRequest, didFailWithError error: Error) { - NSLog("System extension request failed: %@", error.localizedDescription) - } + func request(_: OSSystemExtensionRequest, didFailWithError error: Error) { + NSLog("System extension request failed: %@", error.localizedDescription) + } - func requestNeedsUserApproval(_ request: OSSystemExtensionRequest) { - NSLog("Extension %@ requires user approval", request.identifier) - } + func requestNeedsUserApproval(_ request: OSSystemExtensionRequest) { + NSLog("Extension %@ requires user approval", request.identifier) + } - func request(_ request: OSSystemExtensionRequest, - actionForReplacingExtension existing: OSSystemExtensionProperties, - withExtension extension: OSSystemExtensionProperties) -> OSSystemExtensionRequest.ReplacementAction { - NSLog("Replacing extension %@ version %@ with version %@", request.identifier, existing.bundleShortVersion, `extension`.bundleShortVersion) - return .replace + func request(_ request: OSSystemExtensionRequest, + actionForReplacingExtension existing: OSSystemExtensionProperties, + withExtension extension: OSSystemExtensionProperties) -> OSSystemExtensionRequest.ReplacementAction + { + NSLog("Replacing extension %@ version %@ with version %@", request.identifier, existing.bundleShortVersion, `extension`.bundleShortVersion) + return .replace + } } -} #endif diff --git a/llarp/apple/PacketTunnelProvider.m b/llarp/apple/PacketTunnelProvider.m index 1e32d33b5..17e76d4f1 100644 --- a/llarp/apple/PacketTunnelProvider.m +++ b/llarp/apple/PacketTunnelProvider.m @@ -213,7 +213,7 @@ static void del_default_route(void* ctx) { NSString* dns_ip = [NSString stringWithUTF8String:conf.dns_bind_ip]; #else // TODO: placeholder - NSString* dns_ip = @"127.0.0.1"; + NSString* dns_ip = ip; #endif NSLog(@"setting dns to %@", dns_ip); NEDNSSettings* dns = [[NEDNSSettings alloc] initWithServers:@[dns_ip]]; diff --git a/readme.md b/readme.md index fde25a89d..fd5d51cd0 100644 --- a/readme.md +++ b/readme.md @@ -93,9 +93,9 @@ build 1 or many cross targets: ### MacOS -Lokinet ~~is~~ will be available on the Apple App store. +Source code compilation of Lokinet by end users is not supported or permitted by apple on their platforms, see [this](contrib/macos/README.txt) for more information. -Source code compilation of Lokinet by end users is not supported or permitted by apple on their platforms, see [this](contrib/macos/README.txt) for more information. If you find this disagreeable consider using a platform that permits compiling from source. +If you find this disagreeable consider using a platform that permits compiling from source. ### Windows