diff --git a/.gitignore b/.gitignore index 06bd92264..451a2f02f 100644 --- a/.gitignore +++ b/.gitignore @@ -60,6 +60,9 @@ GTAGS GRTAGS GPATH version.txt - -lokinet-bootstrap.exe -regdbhelper.dll + +lokinet-bootstrap.exe +regdbhelper.dll +# xcode +xcuserdata/ + diff --git a/daemon/main.cpp b/daemon/main.cpp index cbac238dd..ec6d938f4 100644 --- a/daemon/main.cpp +++ b/daemon/main.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include @@ -136,6 +137,7 @@ main(int argc, char *argv[]) ("g,generate", "generate client config", cxxopts::value()) ("r,router", "generate router config", cxxopts::value()) ("f,force", "overwrite", cxxopts::value()) + ("c,colour", "colour output", cxxopts::value()->default_value("true")) ("d,debug", "debug mode - UNENCRYPTED TRAFFIC", cxxopts::value()) ("config","path to configuration file", cxxopts::value()); @@ -158,6 +160,12 @@ main(int argc, char *argv[]) llarp::LogDebug("debug logging activated"); } + if(!result["colour"].as< bool >()) + { + llarp::LogContext::Instance().logStream = + std::make_unique< llarp::OStreamLogStream >(false, std::cerr); + } + if(result.count("help")) { std::cout << options.help() << std::endl; diff --git a/daemon/rcutil.cpp b/daemon/rcutil.cpp index 2b8b11618..7d7b997be 100644 --- a/daemon/rcutil.cpp +++ b/daemon/rcutil.cpp @@ -55,6 +55,7 @@ main(int argc, char* argv[]) options.add_options() ("v,verbose", "Verbose", cxxopts::value()) + ("c,colour", "colour output", cxxopts::value()->default_value("true")) ("h,help", "help", cxxopts::value()) ("j,json", "output in json", cxxopts::value()) ("dump", "dump rc file", cxxopts::value >(), "FILE"); @@ -70,7 +71,8 @@ main(int argc, char* argv[]) { SetLogLevel(llarp::eLogDebug); llarp::LogContext::Instance().logStream = - std::make_unique< llarp::OStreamLogStream >(std::cerr); + std::make_unique< llarp::OStreamLogStream >( + result["colour"].as< bool >(), std::cerr); llarp::LogDebug("debug logging activated"); } diff --git a/llarp/util/logging/logger.cpp b/llarp/util/logging/logger.cpp index b2c507c2a..9e99a4781 100644 --- a/llarp/util/logging/logger.cpp +++ b/llarp/util/logging/logger.cpp @@ -19,7 +19,7 @@ namespace llarp #define _LOGSTREAM_INIT #else using Stream_t = OStreamLogStream; -#define _LOGSTREAM_INIT std::cout +#define _LOGSTREAM_INIT true, std::cout #endif #endif diff --git a/llarp/util/logging/ostream_logger.cpp b/llarp/util/logging/ostream_logger.cpp index a9220b0f0..233b99ed4 100644 --- a/llarp/util/logging/ostream_logger.cpp +++ b/llarp/util/logging/ostream_logger.cpp @@ -3,7 +3,8 @@ namespace llarp { - OStreamLogStream::OStreamLogStream(std::ostream& out) : m_Out(out) + OStreamLogStream::OStreamLogStream(bool withColours, std::ostream& out) + : m_withColours(withColours), m_Out(out) { } @@ -12,22 +13,25 @@ namespace llarp const char* fname, int lineno, const std::string& nodename) const { - switch(lvl) + if(m_withColours) { - case eLogNone: - break; - case eLogDebug: - ss << (char)27 << "[0m"; - break; - case eLogInfo: - ss << (char)27 << "[1m"; - break; - case eLogWarn: - ss << (char)27 << "[1;33m"; - break; - case eLogError: - ss << (char)27 << "[1;31m"; - break; + switch(lvl) + { + case eLogNone: + break; + case eLogDebug: + ss << (char)27 << "[0m"; + break; + case eLogInfo: + ss << (char)27 << "[1m"; + break; + case eLogWarn: + ss << (char)27 << "[1;33m"; + break; + case eLogError: + ss << (char)27 << "[1;31m"; + break; + } } ss << "[" << LogLevelToString(lvl) << "] "; ss << "[" << nodename << "]" @@ -38,7 +42,9 @@ namespace llarp void OStreamLogStream::PostLog(std::stringstream& ss) const { - ss << (char)27 << "[0;0m" << std::endl; + if(m_withColours) + ss << (char)27 << "[0;0m"; + ss << std::endl; } void diff --git a/llarp/util/logging/ostream_logger.hpp b/llarp/util/logging/ostream_logger.hpp index 74532a59b..c29d8a791 100644 --- a/llarp/util/logging/ostream_logger.hpp +++ b/llarp/util/logging/ostream_logger.hpp @@ -8,7 +8,7 @@ namespace llarp { struct OStreamLogStream : public ILogStream { - OStreamLogStream(std::ostream& out); + OStreamLogStream(bool withColours, std::ostream& out); ~OStreamLogStream() override = default; @@ -27,6 +27,7 @@ namespace llarp } private: + bool m_withColours; std::ostream& m_Out; }; } // namespace llarp diff --git a/llarp/util/logging/win32_logger.cpp b/llarp/util/logging/win32_logger.cpp index 9012626f2..65e359804 100644 --- a/llarp/util/logging/win32_logger.cpp +++ b/llarp/util/logging/win32_logger.cpp @@ -8,7 +8,7 @@ static short old_attrs; namespace llarp { Win32LogStream::Win32LogStream(std::ostream& out) - : OStreamLogStream(out), m_Out(out) + : OStreamLogStream(true, out), m_Out(out) { // Attempt to use ANSI escapes directly // if the modern console is active. diff --git a/ui-macos/lokinet.xcodeproj/project.pbxproj b/ui-macos/lokinet.xcodeproj/project.pbxproj new file mode 100644 index 000000000..a4b6a7c5a --- /dev/null +++ b/ui-macos/lokinet.xcodeproj/project.pbxproj @@ -0,0 +1,621 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 51; + objects = { + +/* Begin PBXBuildFile section */ + 7B28BD1A232EA8B40073B955 /* DNSManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B28BD19232EA8B40073B955 /* DNSManager.swift */; }; + 7B28BD1C232EB6EF0073B955 /* LokinetRunner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B28BD1B232EB6EF0073B955 /* LokinetRunner.swift */; }; + 7BED5B7A232D78D900DF603F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BED5B79232D78D900DF603F /* AppDelegate.swift */; }; + 7BED5B7C232D78D900DF603F /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BED5B7B232D78D900DF603F /* ViewController.swift */; }; + 7BED5B7E232D78DB00DF603F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7BED5B7D232D78DB00DF603F /* Assets.xcassets */; }; + 7BED5B81232D78DB00DF603F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7BED5B7F232D78DB00DF603F /* Main.storyboard */; }; + 7BED5B8D232D78DB00DF603F /* lokinetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BED5B8C232D78DB00DF603F /* lokinetTests.swift */; }; + 7BED5B98232D78DB00DF603F /* lokinetUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BED5B97232D78DB00DF603F /* lokinetUITests.swift */; }; + 7BED5BA6232E7E6600DF603F /* LokinetLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BED5BA5232E7E6600DF603F /* LokinetLog.swift */; }; + 7BED5BA8232E831B00DF603F /* StreamReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BED5BA7232E831B00DF603F /* StreamReader.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 7BED5B89232D78DB00DF603F /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 7BED5B6E232D78D900DF603F /* Project object */; + proxyType = 1; + remoteGlobalIDString = 7BED5B75232D78D900DF603F; + remoteInfo = lokinet; + }; + 7BED5B94232D78DB00DF603F /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 7BED5B6E232D78D900DF603F /* Project object */; + proxyType = 1; + remoteGlobalIDString = 7BED5B75232D78D900DF603F; + remoteInfo = lokinet; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 7B28BD19232EA8B40073B955 /* DNSManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DNSManager.swift; sourceTree = ""; }; + 7B28BD1B232EB6EF0073B955 /* LokinetRunner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LokinetRunner.swift; sourceTree = ""; }; + 7BED5B76232D78D900DF603F /* lokinet.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = lokinet.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 7BED5B79232D78D900DF603F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 7BED5B7B232D78D900DF603F /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 7BED5B7D232D78DB00DF603F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 7BED5B80232D78DB00DF603F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 7BED5B82232D78DB00DF603F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 7BED5B83232D78DB00DF603F /* lokinet.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = lokinet.entitlements; sourceTree = ""; }; + 7BED5B88232D78DB00DF603F /* lokinetTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = lokinetTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 7BED5B8C232D78DB00DF603F /* lokinetTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = lokinetTests.swift; sourceTree = ""; }; + 7BED5B8E232D78DB00DF603F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 7BED5B93232D78DB00DF603F /* lokinetUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = lokinetUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 7BED5B97232D78DB00DF603F /* lokinetUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = lokinetUITests.swift; sourceTree = ""; }; + 7BED5B99232D78DB00DF603F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 7BED5BA5232E7E6600DF603F /* LokinetLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LokinetLog.swift; sourceTree = ""; }; + 7BED5BA7232E831B00DF603F /* StreamReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StreamReader.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 7BED5B73232D78D900DF603F /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 7BED5B85232D78DB00DF603F /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 7BED5B90232D78DB00DF603F /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 7BED5B6D232D78D900DF603F = { + isa = PBXGroup; + children = ( + 7BED5B78232D78D900DF603F /* lokinet */, + 7BED5B8B232D78DB00DF603F /* lokinetTests */, + 7BED5B96232D78DB00DF603F /* lokinetUITests */, + 7BED5B77232D78D900DF603F /* Products */, + 7BED5BA9232E993E00DF603F /* Frameworks */, + ); + sourceTree = ""; + }; + 7BED5B77232D78D900DF603F /* Products */ = { + isa = PBXGroup; + children = ( + 7BED5B76232D78D900DF603F /* lokinet.app */, + 7BED5B88232D78DB00DF603F /* lokinetTests.xctest */, + 7BED5B93232D78DB00DF603F /* lokinetUITests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 7BED5B78232D78D900DF603F /* lokinet */ = { + isa = PBXGroup; + children = ( + 7BED5B79232D78D900DF603F /* AppDelegate.swift */, + 7BED5B7B232D78D900DF603F /* ViewController.swift */, + 7BED5B7D232D78DB00DF603F /* Assets.xcassets */, + 7BED5B7F232D78DB00DF603F /* Main.storyboard */, + 7BED5B82232D78DB00DF603F /* Info.plist */, + 7BED5B83232D78DB00DF603F /* lokinet.entitlements */, + 7BED5BA5232E7E6600DF603F /* LokinetLog.swift */, + 7B28BD19232EA8B40073B955 /* DNSManager.swift */, + 7BED5BA7232E831B00DF603F /* StreamReader.swift */, + 7B28BD1B232EB6EF0073B955 /* LokinetRunner.swift */, + ); + path = lokinet; + sourceTree = ""; + }; + 7BED5B8B232D78DB00DF603F /* lokinetTests */ = { + isa = PBXGroup; + children = ( + 7BED5B8C232D78DB00DF603F /* lokinetTests.swift */, + 7BED5B8E232D78DB00DF603F /* Info.plist */, + ); + path = lokinetTests; + sourceTree = ""; + }; + 7BED5B96232D78DB00DF603F /* lokinetUITests */ = { + isa = PBXGroup; + children = ( + 7BED5B97232D78DB00DF603F /* lokinetUITests.swift */, + 7BED5B99232D78DB00DF603F /* Info.plist */, + ); + path = lokinetUITests; + sourceTree = ""; + }; + 7BED5BA9232E993E00DF603F /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 7BED5B75232D78D900DF603F /* lokinet */ = { + isa = PBXNativeTarget; + buildConfigurationList = 7BED5B9C232D78DB00DF603F /* Build configuration list for PBXNativeTarget "lokinet" */; + buildPhases = ( + 7BED5B72232D78D900DF603F /* Sources */, + 7BED5B73232D78D900DF603F /* Frameworks */, + 7BED5B74232D78D900DF603F /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = lokinet; + productName = lokinet; + productReference = 7BED5B76232D78D900DF603F /* lokinet.app */; + productType = "com.apple.product-type.application"; + }; + 7BED5B87232D78DB00DF603F /* lokinetTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 7BED5B9F232D78DB00DF603F /* Build configuration list for PBXNativeTarget "lokinetTests" */; + buildPhases = ( + 7BED5B84232D78DB00DF603F /* Sources */, + 7BED5B85232D78DB00DF603F /* Frameworks */, + 7BED5B86232D78DB00DF603F /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 7BED5B8A232D78DB00DF603F /* PBXTargetDependency */, + ); + name = lokinetTests; + productName = lokinetTests; + productReference = 7BED5B88232D78DB00DF603F /* lokinetTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; + 7BED5B92232D78DB00DF603F /* lokinetUITests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 7BED5BA2232D78DB00DF603F /* Build configuration list for PBXNativeTarget "lokinetUITests" */; + buildPhases = ( + 7BED5B8F232D78DB00DF603F /* Sources */, + 7BED5B90232D78DB00DF603F /* Frameworks */, + 7BED5B91232D78DB00DF603F /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 7BED5B95232D78DB00DF603F /* PBXTargetDependency */, + ); + name = lokinetUITests; + productName = lokinetUITests; + productReference = 7BED5B93232D78DB00DF603F /* lokinetUITests.xctest */; + productType = "com.apple.product-type.bundle.ui-testing"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 7BED5B6E232D78D900DF603F /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1020; + LastUpgradeCheck = 1020; + ORGANIZATIONNAME = Loki; + TargetAttributes = { + 7BED5B75232D78D900DF603F = { + CreatedOnToolsVersion = 10.2.1; + SystemCapabilities = { + com.apple.ApplicationGroups.Mac = { + enabled = 0; + }; + com.apple.NetworkExtensions = { + enabled = 0; + }; + com.apple.Sandbox = { + enabled = 0; + }; + }; + }; + 7BED5B87232D78DB00DF603F = { + CreatedOnToolsVersion = 10.2.1; + TestTargetID = 7BED5B75232D78D900DF603F; + }; + 7BED5B92232D78DB00DF603F = { + CreatedOnToolsVersion = 10.2.1; + TestTargetID = 7BED5B75232D78D900DF603F; + }; + }; + }; + buildConfigurationList = 7BED5B71232D78D900DF603F /* Build configuration list for PBXProject "lokinet" */; + compatibilityVersion = "Xcode 10.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 7BED5B6D232D78D900DF603F; + productRefGroup = 7BED5B77232D78D900DF603F /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 7BED5B75232D78D900DF603F /* lokinet */, + 7BED5B87232D78DB00DF603F /* lokinetTests */, + 7BED5B92232D78DB00DF603F /* lokinetUITests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 7BED5B74232D78D900DF603F /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 7BED5B7E232D78DB00DF603F /* Assets.xcassets in Resources */, + 7BED5B81232D78DB00DF603F /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 7BED5B86232D78DB00DF603F /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 7BED5B91232D78DB00DF603F /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 7BED5B72232D78D900DF603F /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 7BED5BA8232E831B00DF603F /* StreamReader.swift in Sources */, + 7BED5B7C232D78D900DF603F /* ViewController.swift in Sources */, + 7BED5BA6232E7E6600DF603F /* LokinetLog.swift in Sources */, + 7B28BD1A232EA8B40073B955 /* DNSManager.swift in Sources */, + 7B28BD1C232EB6EF0073B955 /* LokinetRunner.swift in Sources */, + 7BED5B7A232D78D900DF603F /* AppDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 7BED5B84232D78DB00DF603F /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 7BED5B8D232D78DB00DF603F /* lokinetTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 7BED5B8F232D78DB00DF603F /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 7BED5B98232D78DB00DF603F /* lokinetUITests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 7BED5B8A232D78DB00DF603F /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 7BED5B75232D78D900DF603F /* lokinet */; + targetProxy = 7BED5B89232D78DB00DF603F /* PBXContainerItemProxy */; + }; + 7BED5B95232D78DB00DF603F /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 7BED5B75232D78D900DF603F /* lokinet */; + targetProxy = 7BED5B94232D78DB00DF603F /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 7BED5B7F232D78DB00DF603F /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 7BED5B80232D78DB00DF603F /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 7BED5B9A232D78DB00DF603F /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + DEVELOPMENT_TEAM = 23TKR8Q2XE; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.14; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 7BED5B9B232D78DB00DF603F /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEVELOPMENT_TEAM = 23TKR8Q2XE; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.14; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 7BED5B9D232D78DB00DF603F /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_ENTITLEMENTS = lokinet/lokinet.entitlements; + CODE_SIGN_IDENTITY = "Mac Developer"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_TEAM = 23TKR8Q2XE; + INFOPLIST_FILE = lokinet/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 10.14; + PRODUCT_BUNDLE_IDENTIFIER = loki.lokinet; + PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 7BED5B9E232D78DB00DF603F /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_ENTITLEMENTS = lokinet/lokinet.entitlements; + CODE_SIGN_IDENTITY = "Mac Developer"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_TEAM = 23TKR8Q2XE; + INFOPLIST_FILE = lokinet/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 10.14; + PRODUCT_BUNDLE_IDENTIFIER = loki.lokinet; + PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; + 7BED5BA0232D78DB00DF603F /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = lokinetTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = loki.lokinetTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/lokinet.app/Contents/MacOS/lokinet"; + }; + name = Debug; + }; + 7BED5BA1232D78DB00DF603F /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = lokinetTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = loki.lokinetTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/lokinet.app/Contents/MacOS/lokinet"; + }; + name = Release; + }; + 7BED5BA3232D78DB00DF603F /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = lokinetUITests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = loki.lokinetUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_TARGET_NAME = lokinet; + }; + name = Debug; + }; + 7BED5BA4232D78DB00DF603F /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = lokinetUITests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = loki.lokinetUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_TARGET_NAME = lokinet; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 7BED5B71232D78D900DF603F /* Build configuration list for PBXProject "lokinet" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 7BED5B9A232D78DB00DF603F /* Debug */, + 7BED5B9B232D78DB00DF603F /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 7BED5B9C232D78DB00DF603F /* Build configuration list for PBXNativeTarget "lokinet" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 7BED5B9D232D78DB00DF603F /* Debug */, + 7BED5B9E232D78DB00DF603F /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 7BED5B9F232D78DB00DF603F /* Build configuration list for PBXNativeTarget "lokinetTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 7BED5BA0232D78DB00DF603F /* Debug */, + 7BED5BA1232D78DB00DF603F /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 7BED5BA2232D78DB00DF603F /* Build configuration list for PBXNativeTarget "lokinetUITests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 7BED5BA3232D78DB00DF603F /* Debug */, + 7BED5BA4232D78DB00DF603F /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 7BED5B6E232D78D900DF603F /* Project object */; +} diff --git a/ui-macos/lokinet.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/ui-macos/lokinet.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..a6a9a9a05 --- /dev/null +++ b/ui-macos/lokinet.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/ui-macos/lokinet.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/ui-macos/lokinet.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/ui-macos/lokinet.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/ui-macos/lokinet.xcodeproj/xcshareddata/xcschemes/lokinet.xcscheme b/ui-macos/lokinet.xcodeproj/xcshareddata/xcschemes/lokinet.xcscheme new file mode 100644 index 000000000..bf40928c4 --- /dev/null +++ b/ui-macos/lokinet.xcodeproj/xcshareddata/xcschemes/lokinet.xcscheme @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ui-macos/lokinet/AppDelegate.swift b/ui-macos/lokinet/AppDelegate.swift new file mode 100644 index 000000000..c95c3e2c2 --- /dev/null +++ b/ui-macos/lokinet/AppDelegate.swift @@ -0,0 +1,23 @@ +// +// AppDelegate.swift +// lokinet +// +// Copyright © 2019 Loki. All rights reserved. +// + +import Cocoa + +@NSApplicationMain +class AppDelegate: NSObject, NSApplicationDelegate { + + + + func applicationDidFinishLaunching(_ aNotification: Notification) { + // Insert code here to initialize your application + } + + func applicationWillTerminate(_ aNotification: Notification) { + // Insert code here to tear down your application + } +} + diff --git a/ui-macos/lokinet/Assets.xcassets/AppIcon.appiconset/Contents.json b/ui-macos/lokinet/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 000000000..2db2b1c7c --- /dev/null +++ b/ui-macos/lokinet/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,58 @@ +{ + "images" : [ + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/ui-macos/lokinet/Assets.xcassets/Contents.json b/ui-macos/lokinet/Assets.xcassets/Contents.json new file mode 100644 index 000000000..da4a164c9 --- /dev/null +++ b/ui-macos/lokinet/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/ui-macos/lokinet/Base.lproj/Main.storyboard b/ui-macos/lokinet/Base.lproj/Main.storyboard new file mode 100644 index 000000000..813b7c2a0 --- /dev/null +++ b/ui-macos/lokinet/Base.lproj/Main.storyboard @@ -0,0 +1,226 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ui-macos/lokinet/DNSManager.swift b/ui-macos/lokinet/DNSManager.swift new file mode 100644 index 000000000..3c713dc81 --- /dev/null +++ b/ui-macos/lokinet/DNSManager.swift @@ -0,0 +1,72 @@ +// +// DNSManager.swift +// lokinet +// +// Copyright © 2019 Loki. All rights reserved. +// + +import Foundation + +func split(str: String?) -> [String] { + let res = str?.components(separatedBy: NSCharacterSet.whitespacesAndNewlines) ?? [] + return res.filter({!$0.isEmpty}) +} + +class DNSManager { + static let netSetup = URL(fileURLWithPath: "/usr/sbin/networksetup") + + let oldDNSSettings: [String] + let interface: String + + static func getOldSettings(interface: String) -> [String] { + let netprocess = Process() + netprocess.executableURL = DNSManager.netSetup + netprocess.arguments = ["-getdnsservers", interface] + + do { + let pipe = Pipe() + netprocess.standardOutput = pipe + try netprocess.run() + let data = pipe.fileHandleForReading.readDataToEndOfFile() + let asStr = String(data: data, encoding: .ascii) + + return split(str: asStr).filter({$0 != "127.0.0.1"}) + } catch { + return [] + } + } + + func setNewSettings() throws { + let netprocess = Process() + netprocess.executableURL = DNSManager.netSetup + + netprocess.arguments = ["-setdnsservers", self.interface, "127.0.0.1"] + + try netprocess.run() + } + + func restoreOldSettings() { + let netprocess = Process() + netprocess.executableURL = DNSManager.netSetup + + netprocess.arguments = ["-setdnsservers", self.interface] + netprocess.arguments?.append(contentsOf: oldDNSSettings) + + do { + try netprocess.run() + print("Overriding DNS Settings of \(self.oldDNSSettings)") + } catch { + // do nothing + } + } + + init(interface: String) { + self.interface = interface + self.oldDNSSettings = DNSManager.getOldSettings(interface: interface) + print("Overriding DNS Settings of \(self.oldDNSSettings)") + } + + deinit { + restoreOldSettings() + } +} diff --git a/ui-macos/lokinet/Info.plist b/ui-macos/lokinet/Info.plist new file mode 100644 index 000000000..06d8a48d9 --- /dev/null +++ b/ui-macos/lokinet/Info.plist @@ -0,0 +1,34 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSApplicationCategoryType + public.app-category.productivity + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSHumanReadableCopyright + Copyright © 2019 Loki. All rights reserved. + NSMainStoryboardFile + Main + NSPrincipalClass + NSApplication + + diff --git a/ui-macos/lokinet/LokinetLog.swift b/ui-macos/lokinet/LokinetLog.swift new file mode 100644 index 000000000..c1385feae --- /dev/null +++ b/ui-macos/lokinet/LokinetLog.swift @@ -0,0 +1,32 @@ +// +// LokinetLog.swift +// lokinet +// +// Copyright © 2019 Loki. All rights reserved. +// + +import AppKit + +final class LokinetLog : NSTextView { + + var runner: LokinetRunner? + + override init(frame: NSRect, textContainer: NSTextContainer?) { + super.init(frame: frame, textContainer: textContainer) + self.runner = LokinetRunner(window: self, interface: "Wi-Fi") + + self.runner?.start() + } + + required init?(coder: NSCoder) { + super.init(coder: coder) + self.runner = LokinetRunner(window: self, interface: "Wi-Fi") + + self.runner?.start() + } + + func append(string: String) { + self.textStorage?.append(NSAttributedString(string: string + "\n")) + self.scrollToEndOfDocument(nil) + } +} diff --git a/ui-macos/lokinet/LokinetRunner.swift b/ui-macos/lokinet/LokinetRunner.swift new file mode 100644 index 000000000..63ab2d98f --- /dev/null +++ b/ui-macos/lokinet/LokinetRunner.swift @@ -0,0 +1,76 @@ +// +// LokinetRunner.swift +// lokinet +// +// Copyright © 2019 Loki. All rights reserved. +// + +import Foundation + +class LokinetRunner { + static let PATH_KEY = "lokinetPath" + static let DEFAULT_PATH = URL(fileURLWithPath: "/usr/local/bin/lokinet") + + var lokinetPath: URL? + var process = Process() + let dnsManager: DNSManager + weak var window: LokinetLog? + + init(window: LokinetLog, interface: String) { + self.dnsManager = DNSManager(interface: interface) + self.window = window + configure() + } + + func configure() { + let defaults = UserDefaults.standard; + + self.lokinetPath = defaults.url(forKey: LokinetRunner.PATH_KEY) ?? LokinetRunner.DEFAULT_PATH + defaults.set(self.lokinetPath, forKey: LokinetRunner.PATH_KEY) + } + + func enableDNS() { + do { + try dnsManager.setNewSettings() + } catch { + self.window?.presentError(error) + } + } + + func start() { + process.executableURL = self.lokinetPath + process.arguments = ["--colour=false"] + let outputPipe = Pipe() + process.standardOutput = outputPipe + process.standardError = outputPipe + + do { + try process.run() + } catch { + self.window?.presentError(error) + } + + guard let reader = StreamReader(fh: outputPipe.fileHandleForReading) else { + let err = NSError(domain: "lokinet", code: 0, userInfo: ["msg": "Failed to read from filehandle"]) + self.window?.presentError(err) + return + } + + DispatchQueue.global(qos: .background).async { + for line in reader { + DispatchQueue.main.async { + self.window?.append(string: line) + } + } + } + + enableDNS() + } + + deinit { + if process.isRunning { + process.terminate() + process.waitUntilExit() + } + } +} diff --git a/ui-macos/lokinet/StreamReader.swift b/ui-macos/lokinet/StreamReader.swift new file mode 100644 index 000000000..39e0c4eae --- /dev/null +++ b/ui-macos/lokinet/StreamReader.swift @@ -0,0 +1,73 @@ +// +// StreamReader.swift +// lokinet +// +// Copyright © 2019 Loki. All rights reserved. +// + +import Foundation + +final class StreamReader { + let encoding : String.Encoding + let chunkSize : Int + + var fileHandle : FileHandle! + var buffer : Data + let delimData : Data + var atEof : Bool = false + + init?(fh: FileHandle, delimiter: String = "\n", encoding : String.Encoding = .utf8, chunkSize : Int = 4096) { + self.chunkSize = chunkSize + self.encoding = encoding + self.fileHandle = fh + + guard let delimData = delimiter.data(using: encoding) else { + return nil + } + self.delimData = delimData + self.buffer = Data(capacity: chunkSize) + } + + /// Return next line, or nil on EOF. + func nextLine() -> String? { + precondition(fileHandle != nil, "Attempt to read from closed file") + + if atEof { + return nil + } + + // Read data chunks from file until a line delimiter is found: + while !atEof { + if let range = buffer.range(of: delimData) { + // Convert complete line (excluding the delimiter) to a string: + let line = String(data: buffer.subdata(in: 0.. 0 { + buffer.append(tmpData) + } else { + // EOF or read error. + atEof = true + if buffer.count > 0 { + // Buffer contains last line in file (not terminated by delimiter). + let line = String(data: buffer as Data, encoding: encoding) + buffer.count = 0 + return line + } + } + } + + return nil + } +} + +extension StreamReader : Sequence { + func makeIterator() -> AnyIterator { + return AnyIterator { + return self.nextLine() + } + } +} diff --git a/ui-macos/lokinet/ViewController.swift b/ui-macos/lokinet/ViewController.swift new file mode 100644 index 000000000..7a95f4c57 --- /dev/null +++ b/ui-macos/lokinet/ViewController.swift @@ -0,0 +1,22 @@ +// +// ViewController.swift +// lokinet +// +// Copyright © 2019 Loki. All rights reserved. +// + +import Cocoa + +class ViewController: NSViewController { + + override func viewDidLoad() { + super.viewDidLoad() + } + + override var representedObject: Any? { + didSet { + // Update the view, if already loaded. + } + } +} + diff --git a/ui-macos/lokinet/lokinet.entitlements b/ui-macos/lokinet/lokinet.entitlements new file mode 100644 index 000000000..2eb7e333a --- /dev/null +++ b/ui-macos/lokinet/lokinet.entitlements @@ -0,0 +1,8 @@ + + + + + com.apple.security.application-groups + + + diff --git a/ui-macos/lokinetTests/Info.plist b/ui-macos/lokinetTests/Info.plist new file mode 100644 index 000000000..6c40a6cd0 --- /dev/null +++ b/ui-macos/lokinetTests/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/ui-macos/lokinetTests/lokinetTests.swift b/ui-macos/lokinetTests/lokinetTests.swift new file mode 100644 index 000000000..e95c64178 --- /dev/null +++ b/ui-macos/lokinetTests/lokinetTests.swift @@ -0,0 +1,33 @@ +// +// lokinetTests.swift +// lokinetTests +// +// Copyright © 2019 Loki. All rights reserved. +// + +import XCTest +@testable import lokinet + +class lokinetTests: XCTestCase { + + override func setUp() { + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testExample() { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + func testPerformanceExample() { + // This is an example of a performance test case. + self.measure { + // Put the code you want to measure the time of here. + } + } + +} diff --git a/ui-macos/lokinetUITests/Info.plist b/ui-macos/lokinetUITests/Info.plist new file mode 100644 index 000000000..6c40a6cd0 --- /dev/null +++ b/ui-macos/lokinetUITests/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/ui-macos/lokinetUITests/lokinetUITests.swift b/ui-macos/lokinetUITests/lokinetUITests.swift new file mode 100644 index 000000000..79e381db0 --- /dev/null +++ b/ui-macos/lokinetUITests/lokinetUITests.swift @@ -0,0 +1,33 @@ +// +// lokinetUITests.swift +// lokinetUITests +// +// Copyright © 2019 Loki. All rights reserved. +// + +import XCTest + +class lokinetUITests: XCTestCase { + + override func setUp() { + // Put setup code here. This method is called before the invocation of each test method in the class. + + // In UI tests it is usually best to stop immediately when a failure occurs. + continueAfterFailure = false + + // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. + XCUIApplication().launch() + + // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testExample() { + // Use recording to get started writing UI tests. + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + +}