Changeset 4369b7d for launchers


Ignore:
Timestamp:
Sep 22, 2018 12:11:43 PM (2 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
829eb665
Parents:
46ac0087 (diff), 70fa2dae (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge of 'dba1ad61c390f95055923ae1fb35e60552f617c6'

and 'f84ff8b356783cf12619b83a8104e55fe76a7411'

Location:
launchers/macosx
Files:
4 added
3 deleted
14 edited

Legend:

Unmodified
Added
Removed
  • launchers/macosx/AppDelegate.h

    r46ac0087 r4369b7d  
    66#include <memory.h>
    77
     8#ifdef __cplusplus
     9#include <unistd.h>
     10#include <sys/types.h>
     11#include <pwd.h>
     12#include <assert.h>
     13#endif
     14
    815#include <Cocoa/Cocoa.h>
     16#include "SBridge.h"
    917
    1018
    1119#include "RouterTask.h"
    12 #include "JavaHelper.h"
    1320
    1421
     
    2835@class ExtractMetaInfo;
    2936
    30 
    31 
    3237@interface ExtractMetaInfo : NSObject
    3338@property (copy) NSString* i2pBase;
     
    3641@property (copy) NSString* jarFile;
    3742@end
     43
     44
    3845#ifdef __cplusplus
    39 #include "JavaHelper.h"
    4046
    41 inline void sendUserNotification(NSString* title, NSString* informativeText, NSImage* contentImage = NULL, bool makeSound = false) {
     47inline const char* RealHomeDirectory() {
     48  struct passwd *pw = getpwuid(getuid());
     49  assert(pw);
     50  return pw->pw_dir;
     51}
     52
     53inline std::string getDefaultBaseDir()
     54{
     55  // Figure out base directory
     56  auto homeDir = RealHomeDirectory();
     57  const char* pathFromHome = "%s/Library/I2P";
     58  char buffer[strlen(homeDir)+strlen(pathFromHome)];
     59  sprintf(buffer, pathFromHome, homeDir);
     60  std::string i2pBaseDir(buffer);
     61  return i2pBaseDir;
     62}
     63
     64inline void sendUserNotification(NSString* title, NSString* informativeText, bool makeSound = false) {
    4265  NSUserNotification *userNotification = [[NSUserNotification alloc] init];
    4366 
     
    5679};
    5780
    58 using maybeAnRouterRunner = I2PRouterTask*;
    59 
    60 std::vector<std::string> buildClassPath(std::string basePath);
    61 
    62 extern JvmListSharedPtr gRawJvmList;
    63 
    64 // DO NOT ACCESS THIS GLOBAL VARIABLE DIRECTLY.
    65 static std::mutex globalRouterStatusMutex;
    66 static maybeAnRouterRunner globalRouterStatus = maybeAnRouterRunner{};
    67 static bool isRuterRunning = false;
    68 
    69 maybeAnRouterRunner getGlobalRouterObject();
    70 void setGlobalRouterObject(I2PRouterTask* newRouter);
    71 bool getGlobalRouterIsRunning();
    72 void setGlobalRouterIsRunning(bool running);
    73 
    74 #include "SBridge.h"
    75 
    7681#endif
    7782
    78 @class MenuBarCtrl;
    79 
    80 @interface AppDelegate : NSObject <NSUserNotificationCenterDelegate, NSApplicationDelegate> {
    81 @public
    82   //NSImageView *imageCell;
    83 }
     83@interface AppDelegate : NSObject <NSUserNotificationCenterDelegate, NSApplicationDelegate>
    8484@property BOOL enableLogging;
    8585@property BOOL enableVerboseLogging;
     
    9494- (void) applicationWillTerminate:(NSNotification *)aNotification;
    9595- (void) setApplicationDefaultPreferences;
    96 - (void) userChooseJavaHome;
    9796- (AppDelegate *) initWithArgc:(int)argc argv:(const char **)argv;
    98 #ifdef __cplusplus
    99 - (void) startupI2PRouter;
    100 - (NSString *) userSelectJavaHome:(JvmListPtr)rawJvmList;
    101 #endif
    10297- (BOOL) userNotificationCenter:(NSUserNotificationCenter *)center
    10398                               shouldPresentNotification:(NSUserNotification *)notification;
  • launchers/macosx/I2PLauncher.xcodeproj/project.pbxproj

    r46ac0087 r4369b7d  
    44        classes = {
    55        };
    6         objectVersion = 50;
     6        objectVersion = 47;
    77        objects = {
    88
     
    1515                BF1EFA47215141640014EB07 /* base.zip in Resources */ = {isa = PBXBuildFile; fileRef = BF1EFA44215141630014EB07 /* base.zip */; };
    1616                BF1EFA48215141640014EB07 /* ItoopieTransparent.png in Resources */ = {isa = PBXBuildFile; fileRef = BF1EFA45215141640014EB07 /* ItoopieTransparent.png */; };
    17                 BF1EFA4A215141CD0014EB07 /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BF5061932113C6ED0014EB07 /* NetworkExtension.framework */; };
    1817                BF5061702113C48E0014EB07 /* I2PLauncher.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = BF50616E2113C48E0014EB07 /* I2PLauncher.xcdatamodeld */; };
    1918                BF5061722113C4900014EB07 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BF5061712113C4900014EB07 /* Assets.xcassets */; };
     
    2625                BF5315132150EB510014EB07 /* RouterProcessStatus+ObjectiveC.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF5315122150EB510014EB07 /* RouterProcessStatus+ObjectiveC.swift */; };
    2726                BF531515215105B40014EB07 /* LogViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF531514215105B40014EB07 /* LogViewController.swift */; };
     27                BF650CA92152AC7D0014EB07 /* bumpInfoPlist.sh in Resources */ = {isa = PBXBuildFile; fileRef = BF650CA52152AC7D0014EB07 /* bumpInfoPlist.sh */; };
     28                BF650CAA2152AC7D0014EB07 /* dmgconfig.py in Resources */ = {isa = PBXBuildFile; fileRef = BF650CA62152AC7D0014EB07 /* dmgconfig.py */; };
     29                BF650CAB2152AC7D0014EB07 /* Deployer.m in Sources */ = {isa = PBXBuildFile; fileRef = BF650CA72152AC7D0014EB07 /* Deployer.m */; };
    2830                BF7506CB21509CFD0014EB07 /* RouterProcessStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF7506CA21509CFD0014EB07 /* RouterProcessStatus.swift */; };
     31                BF86541321515CA00014EB07 /* launcher.jar in Resources */ = {isa = PBXBuildFile; fileRef = BF1EFA46215141640014EB07 /* launcher.jar */; };
     32                BF865417215182820014EB07 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BF865416215182820014EB07 /* Foundation.framework */; };
    2933                BFBDCAE9215040670014EB07 /* Subprocess.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBDCAE8215040670014EB07 /* Subprocess.swift */; };
    3034                BFBDCAEB215041630014EB07 /* TaskPipeline.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBDCAEA215041630014EB07 /* TaskPipeline.swift */; };
     
    4044                BFBDCB02215060190014EB07 /* DetectJava.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBDCB01215060190014EB07 /* DetectJava.swift */; };
    4145                BFBDCB04215060970014EB07 /* StatusBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBDCB03215060970014EB07 /* StatusBarController.swift */; };
     46                BFE1CBAD2151908F0014EB07 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BFE1CBAC2151908F0014EB07 /* CoreFoundation.framework */; };
    4247                BFF4581C213C48EA0014EB07 /* EventMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFF4581B213C48EA0014EB07 /* EventMonitor.swift */; };
    4348/* End PBXBuildFile section */
     
    4954                BF1EFA39215140E60014EB07 /* SBridge.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SBridge.mm; sourceTree = SOURCE_ROOT; };
    5055                BF1EFA3B215141100014EB07 /* RouterTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RouterTask.h; sourceTree = SOURCE_ROOT; };
    51                 BF1EFA3C215141100014EB07 /* JavaHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JavaHelper.h; sourceTree = SOURCE_ROOT; };
    5256                BF1EFA3D215141100014EB07 /* main.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = main.mm; sourceTree = SOURCE_ROOT; };
    5357                BF1EFA3E215141100014EB07 /* RouterTask.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RouterTask.mm; sourceTree = SOURCE_ROOT; };
     
    6367                BF5061762113C4900014EB07 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
    6468                BF5061792113C4900014EB07 /* I2PLauncher.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = I2PLauncher.entitlements; sourceTree = "<group>"; };
    65                 BF5061932113C6ED0014EB07 /* NetworkExtension.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NetworkExtension.framework; path = System/Library/Frameworks/NetworkExtension.framework; sourceTree = SDKROOT; };
    6669                BF5061952113C84E0014EB07 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
    6770                BF5315062150C55B0014EB07 /* RouterRunner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RouterRunner.swift; sourceTree = "<group>"; };
     
    7174                BF5315122150EB510014EB07 /* RouterProcessStatus+ObjectiveC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RouterProcessStatus+ObjectiveC.swift"; sourceTree = "<group>"; };
    7275                BF531514215105B40014EB07 /* LogViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogViewController.swift; sourceTree = "<group>"; };
     76                BF650CA52152AC7D0014EB07 /* bumpInfoPlist.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = bumpInfoPlist.sh; sourceTree = SOURCE_ROOT; };
     77                BF650CA62152AC7D0014EB07 /* dmgconfig.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = dmgconfig.py; sourceTree = SOURCE_ROOT; };
     78                BF650CA72152AC7D0014EB07 /* Deployer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Deployer.m; sourceTree = SOURCE_ROOT; };
     79                BF650CA82152AC7D0014EB07 /* Deployer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Deployer.h; sourceTree = SOURCE_ROOT; };
    7380                BF7506CA21509CFD0014EB07 /* RouterProcessStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RouterProcessStatus.swift; sourceTree = "<group>"; };
     81                BF865414215180F60014EB07 /* libswiftDarwin.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libswiftDarwin.tbd; path = System/Library/PrivateFrameworks/Swift/libswiftDarwin.tbd; sourceTree = SDKROOT; };
     82                BF865416215182820014EB07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
    7483                BFBDCAE8215040670014EB07 /* Subprocess.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Subprocess.swift; sourceTree = "<group>"; };
    7584                BFBDCAEA215041630014EB07 /* TaskPipeline.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskPipeline.swift; sourceTree = "<group>"; };
     
    8695                BFBDCB01215060190014EB07 /* DetectJava.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetectJava.swift; sourceTree = "<group>"; };
    8796                BFBDCB03215060970014EB07 /* StatusBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusBarController.swift; sourceTree = "<group>"; };
     97                BFE1CBAC2151908F0014EB07 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
    8898                BFF45818213C428E0014EB07 /* I2PLauncher-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "I2PLauncher-Bridging-Header.h"; sourceTree = "<group>"; };
    8999                BFF4581B213C48EA0014EB07 /* EventMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventMonitor.swift; sourceTree = "<group>"; };
     
    95105                        buildActionMask = 2147483647;
    96106                        files = (
    97                                 BF1EFA4A215141CD0014EB07 /* NetworkExtension.framework in Frameworks */,
     107                                BFE1CBAD2151908F0014EB07 /* CoreFoundation.framework in Frameworks */,
     108                                BF865417215182820014EB07 /* Foundation.framework in Frameworks */,
    98109                                BFBDCB0021505BEE0014EB07 /* AppKit.framework in Frameworks */,
    99110                                BF5061962113C84E0014EB07 /* Cocoa.framework in Frameworks */,
     
    151162                        isa = PBXGroup;
    152163                        children = (
     164                                BF650CA52152AC7D0014EB07 /* bumpInfoPlist.sh */,
     165                                BF650CA82152AC7D0014EB07 /* Deployer.h */,
     166                                BF650CA72152AC7D0014EB07 /* Deployer.m */,
     167                                BF650CA62152AC7D0014EB07 /* dmgconfig.py */,
    153168                                BF1EFA42215141220014EB07 /* include */,
    154169                                BF1EFA3F215141110014EB07 /* AppDelegate.h */,
    155                                 BF1EFA3C215141100014EB07 /* JavaHelper.h */,
    156170                                BF1EFA3D215141100014EB07 /* main.mm */,
    157171                                BF1EFA3B215141100014EB07 /* RouterTask.h */,
     
    178192                        isa = PBXGroup;
    179193                        children = (
     194                                BFE1CBAC2151908F0014EB07 /* CoreFoundation.framework */,
     195                                BF865416215182820014EB07 /* Foundation.framework */,
     196                                BF865414215180F60014EB07 /* libswiftDarwin.tbd */,
    180197                                BFBDCAFF21505BED0014EB07 /* AppKit.framework */,
    181198                                BF5061952113C84E0014EB07 /* Cocoa.framework */,
    182                                 BF5061932113C6ED0014EB07 /* NetworkExtension.framework */,
    183199                        );
    184200                        name = Frameworks;
     
    237253                        isa = PBXProject;
    238254                        attributes = {
    239                                 LastUpgradeCheck = 0940;
     255                                LastUpgradeCheck = 1000;
    240256                                ORGANIZATIONNAME = "The I2P Project";
    241257                                TargetAttributes = {
    242258                                        BF5061672113C48E0014EB07 = {
    243259                                                CreatedOnToolsVersion = 9.4.1;
     260                                                DevelopmentTeam = W3C42P2LA8;
    244261                                                LastSwiftMigration = 0940;
     262                                                ProvisioningStyle = Automatic;
    245263                                                SystemCapabilities = {
     264                                                        com.apple.ApplicationGroups.Mac = {
     265                                                                enabled = 0;
     266                                                        };
    246267                                                        com.apple.NetworkExtensions = {
    247                                                                 enabled = 1;
     268                                                                enabled = 0;
    248269                                                        };
    249270                                                        com.apple.Sandbox = {
     
    255276                        };
    256277                        buildConfigurationList = BF5061632113C48E0014EB07 /* Build configuration list for PBXProject "I2PLauncher" */;
    257                         compatibilityVersion = "Xcode 9.3";
     278                        compatibilityVersion = "Xcode 6.3";
    258279                        developmentRegion = en;
    259280                        hasScannedForEncodings = 0;
     
    277298                        buildActionMask = 2147483647;
    278299                        files = (
     300                                BF86541321515CA00014EB07 /* launcher.jar in Resources */,
     301                                BF650CAA2152AC7D0014EB07 /* dmgconfig.py in Resources */,
     302                                BF650CA92152AC7D0014EB07 /* bumpInfoPlist.sh in Resources */,
    279303                                BF07789721506C810014EB07 /* Storyboard.storyboard in Resources */,
    280304                                BF5061722113C4900014EB07 /* Assets.xcassets in Resources */,
     
    299323                        runOnlyForDeploymentPostprocessing = 0;
    300324                        shellPath = /bin/sh;
    301                         shellScript = "# Run from launchers/macosx\nexport BUILDDIR=$(pwd)\ncd ../..\nant preppkg-osx\ncd pkg-temp\nrm -f ../base.zip\nzip -r7 ../base.zip *\ncp ../base.zip $BUILDDIR\ncd $BUILDDIR\n\n\n\n";
     325                        shellScript = "# Run from launchers/macosx\nexport BUILDDIR=$(pwd)\ncd ..\nsbt macosx:assembly\ncd ..\nant preppkg-osx\ncd pkg-temp\nrm -f ../base.zip\nzip -r -v -9 ../base.zip *\ncp ../base.zip $BUILDDIR/base.zip\ncd $BUILDDIR\ncp $BUILDDIR/target/scala-2.11/routerLauncher-assembly-0.1.0-SNAPSHOT.jar $BUILDDIR/launcher.jar\n\n\n\n";
    302326                };
    303327/* End PBXShellScriptBuildPhase section */
     
    321345                                BFBDCB02215060190014EB07 /* DetectJava.swift in Sources */,
    322346                                BF07789E21506D2B0014EB07 /* PopoverViewController.swift in Sources */,
     347                                BF650CAB2152AC7D0014EB07 /* Deployer.m in Sources */,
    323348                                BF1EFA40215141110014EB07 /* main.mm in Sources */,
    324349                                BFBDCAF4215042670014EB07 /* AppleStuffExceptionHandler.m in Sources */,
     
    359384                                CLANG_CXX_LIBRARY = "libc++";
    360385                                CLANG_ENABLE_MODULES = YES;
    361                                 CLANG_ENABLE_OBJC_ARC = YES;
     386                                CLANG_ENABLE_OBJC_ARC = NO;
    362387                                CLANG_ENABLE_OBJC_WEAK = YES;
    363388                                CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
     
    401426                                GCC_WARN_UNUSED_FUNCTION = YES;
    402427                                GCC_WARN_UNUSED_VARIABLE = YES;
    403                                 MACOSX_DEPLOYMENT_TARGET = 10.13;
     428                                MACOSX_DEPLOYMENT_TARGET = 10.11;
    404429                                MTL_ENABLE_DEBUG_INFO = YES;
    405430                                ONLY_ACTIVE_ARCH = YES;
    406                                 SDKROOT = macosx;
     431                                SDKROOT = macosx10.13;
    407432                        };
    408433                        name = Debug;
     
    417442                                CLANG_CXX_LIBRARY = "libc++";
    418443                                CLANG_ENABLE_MODULES = YES;
    419                                 CLANG_ENABLE_OBJC_ARC = YES;
     444                                CLANG_ENABLE_OBJC_ARC = NO;
    420445                                CLANG_ENABLE_OBJC_WEAK = YES;
    421446                                CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
     
    453478                                GCC_WARN_UNUSED_FUNCTION = YES;
    454479                                GCC_WARN_UNUSED_VARIABLE = YES;
    455                                 MACOSX_DEPLOYMENT_TARGET = 10.13;
     480                                MACOSX_DEPLOYMENT_TARGET = 10.11;
    456481                                MTL_ENABLE_DEBUG_INFO = NO;
    457                                 SDKROOT = macosx;
     482                                SDKROOT = macosx10.13;
     483                                SWIFT_COMPILATION_MODE = wholemodule;
    458484                        };
    459485                        name = Release;
     
    462488                        isa = XCBuildConfiguration;
    463489                        buildSettings = {
    464                                 ALWAYS_SEARCH_USER_PATHS = YES;
    465490                                ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
    466                                 CLANG_CXX_LANGUAGE_STANDARD = "c++14";
    467                                 CLANG_ENABLE_MODULES = YES;
    468                                 CLANG_ENABLE_OBJC_ARC = NO;
    469491                                CODE_SIGN_ENTITLEMENTS = I2PLauncher/I2PLauncher.entitlements;
    470492                                CODE_SIGN_IDENTITY = "Mac Developer";
    471493                                CODE_SIGN_STYLE = Automatic;
    472494                                COMBINE_HIDPI_IMAGES = YES;
     495                                DEAD_CODE_STRIPPING = YES;
     496                                DEFINES_MODULE = YES;
    473497                                DEVELOPMENT_TEAM = W3C42P2LA8;
    474                                 GCC_C_LANGUAGE_STANDARD = gnu11;
     498                                FRAMEWORK_SEARCH_PATHS = (
     499                                        /Library/Frameworks,
     500                                        /System/Library/Frameworks,
     501                                );
    475502                                HEADER_SEARCH_PATHS = (
    476503                                        "$(SRCROOT)/include",
     
    479506                                INCLUDED_RECURSIVE_SEARCH_PATH_SUBDIRECTORIES = include;
    480507                                INFOPLIST_FILE = I2PLauncher/Info.plist;
    481                                 LD_RUNPATH_SEARCH_PATHS = (
    482                                         "$(inherited)",
    483                                         "@executable_path/../Frameworks",
    484                                 );
    485                                 MACOSX_DEPLOYMENT_TARGET = 10.10;
    486                                 PRODUCT_BUNDLE_IDENTIFIER = net.i2p.launcher.I2PLauncher;
     508                                LD_NO_PIE = YES;
     509                                LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @executable_path/Frameworks";
     510                                MACOSX_DEPLOYMENT_TARGET = 10.11;
     511                                PRODUCT_BUNDLE_IDENTIFIER = net.i2p.bootstrap.macosx.I2PLauncher;
    487512                                PRODUCT_NAME = "$(TARGET_NAME)";
     513                                PROVISIONING_PROFILE = "";
    488514                                PROVISIONING_PROFILE_SPECIFIER = "";
     515                                SDKROOT = macosx;
    489516                                SWIFT_OBJC_BRIDGING_HEADER = "I2PLauncher/I2PLauncher-Bridging-Header.h";
    490517                                SWIFT_OPTIMIZATION_LEVEL = "-Onone";
    491518                                SWIFT_VERSION = 3.0;
    492519                                SYSTEM_HEADER_SEARCH_PATHS = "$(SRCROOT)/include/**";
    493                                 USER_HEADER_SEARCH_PATHS = "";
    494520                        };
    495521                        name = Debug;
     
    498524                        isa = XCBuildConfiguration;
    499525                        buildSettings = {
    500                                 ALWAYS_SEARCH_USER_PATHS = YES;
    501526                                ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
    502                                 CLANG_CXX_LANGUAGE_STANDARD = "c++14";
    503                                 CLANG_ENABLE_MODULES = YES;
    504                                 CLANG_ENABLE_OBJC_ARC = NO;
    505527                                CODE_SIGN_ENTITLEMENTS = I2PLauncher/I2PLauncher.entitlements;
    506528                                CODE_SIGN_IDENTITY = "Mac Developer";
    507529                                CODE_SIGN_STYLE = Automatic;
    508530                                COMBINE_HIDPI_IMAGES = YES;
     531                                DEAD_CODE_STRIPPING = YES;
     532                                DEFINES_MODULE = YES;
    509533                                DEVELOPMENT_TEAM = W3C42P2LA8;
    510                                 GCC_C_LANGUAGE_STANDARD = gnu11;
     534                                FRAMEWORK_SEARCH_PATHS = (
     535                                        /Library/Frameworks,
     536                                        /System/Library/Frameworks,
     537                                );
    511538                                HEADER_SEARCH_PATHS = (
    512539                                        "$(SRCROOT)/include",
     
    515542                                INCLUDED_RECURSIVE_SEARCH_PATH_SUBDIRECTORIES = include;
    516543                                INFOPLIST_FILE = I2PLauncher/Info.plist;
    517                                 LD_RUNPATH_SEARCH_PATHS = (
    518                                         "$(inherited)",
    519                                         "@executable_path/../Frameworks",
    520                                 );
    521                                 MACOSX_DEPLOYMENT_TARGET = 10.10;
    522                                 PRODUCT_BUNDLE_IDENTIFIER = net.i2p.launcher.I2PLauncher;
     544                                LD_NO_PIE = YES;
     545                                LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @executable_path/Frameworks";
     546                                MACOSX_DEPLOYMENT_TARGET = 10.11;
     547                                PRODUCT_BUNDLE_IDENTIFIER = net.i2p.bootstrap.macosx.I2PLauncher;
    523548                                PRODUCT_NAME = "$(TARGET_NAME)";
    524549                                PROVISIONING_PROFILE_SPECIFIER = "";
     550                                SDKROOT = macosx;
    525551                                SWIFT_OBJC_BRIDGING_HEADER = "I2PLauncher/I2PLauncher-Bridging-Header.h";
    526552                                SWIFT_VERSION = 3.0;
    527553                                SYSTEM_HEADER_SEARCH_PATHS = "$(SRCROOT)/include/**";
    528                                 USER_HEADER_SEARCH_PATHS = "";
    529554                        };
    530555                        name = Release;
  • launchers/macosx/I2PLauncher.xcworkspace/contents.xcworkspacedata

    r46ac0087 r4369b7d  
    33   version = "1.0">
    44   <FileRef
     5      location = "group:RouterService/RouterService.xcodeproj">
     6   </FileRef>
     7   <FileRef
    58      location = "group:I2PLauncher.xcodeproj">
    69   </FileRef>
  • launchers/macosx/I2PLauncher/Info.plist

    r46ac0087 r4369b7d  
    3535        </array>
    3636        <key>CFBundleVersion</key>
    37         <string>3</string>
     37        <string>4</string>
    3838        <key>LSApplicationCategoryType</key>
    3939        <string>public.app-category.utilities</string>
     
    5454                <dict/>
    5555        </array>
     56        <key>SUFeedURL</key>
     57        <string>http://i2browser.i2p/updates/v1/appcast.xml</string>
    5658</dict>
    5759</plist>
  • launchers/macosx/I2PLauncher/SwiftMainDelegate.swift

    r46ac0087 r4369b7d  
    1414  //let statusItem = NSStatusBar.system().statusItem(withLength: NSSquareStatusItemLength )
    1515  let statusBarController = StatusBarController()
    16   let javaDetector = DetectJava()
     16  static let javaDetector = DetectJava()
    1717  static let objCBridge = SBridge()
    1818 
    1919  override init() {
    2020    super.init()
    21    
    22     self.javaDetector.findIt()
    23     if (!javaDetector.isJavaFound()) {
    24       print("Could not find java....")
    25       terminate("No java..")
     21    if (!SwiftMainDelegate.javaDetector.isJavaFound()) {
     22    SwiftMainDelegate.javaDetector.findIt()
     23      if (!SwiftMainDelegate.javaDetector.isJavaFound()) {
     24        print("Could not find java....")
     25        terminate("No java..")
     26      }
    2627    }
    27     let javaBinPath = self.javaDetector.javaHome
     28    let javaBinPath = SwiftMainDelegate.javaDetector.javaHome
    2829    RouterProcessStatus.knownJavaBinPath = javaBinPath
    2930    print("Found java home = ", javaBinPath)
     
    7879    i2pPath += "/Library/I2P"
    7980   
    80     //let javaBinPath = self.javaDetector.javaHome.replace(target: " ", withString: "\\ ")
    81    
    8281    let fileManager = FileManager()
    8382    var ok = ObjCBool(true)
  • launchers/macosx/I2PLauncher/routermgmt/DetectJava.swift

    r46ac0087 r4369b7d  
    1111@objc class DetectJava : NSObject {
    1212 
    13   var hasJRE : Bool = false
    14   var userWantJRE : Bool = false
    15   var userAcceptOracleEULA : Bool = false
     13  static var hasJRE : Bool = false
     14  static var userWantJRE : Bool = false
     15  static var userAcceptOracleEULA : Bool = false
    1616 
    1717 
     
    3030    //Called after the change
    3131    didSet{
    32       hasJRE = true
    33       print("DetectJava.javaHome did change from "+oldValue+" to "+self.javaHome)
     32      DetectJava.hasJRE = true
     33      self.javaHome = self.javaHome.replace(target: "\n", withString: "").replace(target: "Internet Plug-Ins", withString: "Internet\\ Plug-Ins")
     34      print("DetectJava.javaHome did change to "+self.javaHome)
    3435    }
    3536  };
     
    5152   **/
    5253  @objc func findIt() {
     54    if (DetectJava.hasJRE) {
     55      return
     56    }
    5357    print("Start with checking environment variable")
    5458    self.checkJavaEnvironmentVariable()
    5559    if !(self.javaHome.isEmpty) {
    5660      RouterProcessStatus.knownJavaBinPath = Optional.some(self.javaHome)
    57       hasJRE = true
     61      DetectJava.hasJRE = true
    5862      return
    5963    }
     
    6266    if !(self.javaHome.isEmpty) {
    6367      RouterProcessStatus.knownJavaBinPath = Optional.some(self.javaHome)
    64       hasJRE = true
     68      DetectJava.hasJRE = true
    6569      return
    6670    }
     
    6973    if !(self.javaHome.isEmpty) {
    7074      RouterProcessStatus.knownJavaBinPath = Optional.some(self.javaHome)
    71       hasJRE = true
     75      DetectJava.hasJRE = true
    7276      return
    7377    }
  • launchers/macosx/I2PLauncher/routermgmt/RouterProcessStatus.swift

    r46ac0087 r4369b7d  
    2727 
    2828  @objc func getRouterIsRunning() -> Bool {
    29     if (RouterProcessStatus.isRouterRunning == Optional.none) {
    30       return false;
    31     } else {
    32       let running: Bool = RouterProcessStatus.isRouterRunning
    33       return running
    34     }
     29    return RouterProcessStatus.isRouterRunning
    3530  }
    3631 
    3732  @objc func getJavaHome() -> String {
    3833    return RouterProcessStatus.knownJavaBinPath!
    39   }
    40  
    41   @objc func setJavaHome(_ home: String) {
    42     NSLog("Setting known java to %s", home)
    43     RouterProcessStatus.knownJavaBinPath = home
    4434  }
    4535}
     
    4939  static var isRouterChildProcess : Bool = false
    5040  static var routerVersion : String? = Optional.none
    51   static var routerUptime : String? = Optional.none
     41  static var routerUptime : String? = Optional.none{
     42    //Called before the change
     43    willSet(newValue){
     44      print("RouterProcessStatus.routerUptime will change from ", (self.routerUptime ?? "nil"), " to "+(newValue ?? "nil"))
     45    }
     46   
     47    //Called after the change
     48    didSet{
     49      print("RouterProcessStatus.routerUptime did change to "+self.routerUptime!)
     50    }
     51  }
    5252  static var routerStartedAt : Date? = Optional.none
    5353  static var knownJavaBinPath : String? = Optional.none
  • launchers/macosx/I2PLauncher/userinterface/PopoverViewController.swift

    r46ac0087 r4369b7d  
    6161  override func viewWillDraw() {
    6262    super.viewWillDraw()
    63     if (RouterStatusView.instance == Optional.none) {
     63    if (RouterStatusView.instance != nil) {
    6464      RouterStatusView.instance = self
    6565    }
     
    7979    quickControlView?.needsDisplay = true
    8080   
    81     if (RouterProcessStatus.routerVersion == Optional.none) {
     81    if let version = RouterProcessStatus.routerVersion {
     82      routerVersionLabel?.cell?.stringValue = "Router version: " + version
     83    } else {
    8284      routerVersionLabel?.cell?.stringValue = "Router version: Still unknown"
    83       // trigger a read to ensure values
    84       let tmp = SwiftMainDelegate()
    85       tmp.findInstalledI2PVersion()
    86     } else {
    87       routerVersionLabel?.cell?.stringValue = "Router version: " + RouterProcessStatus.routerVersion!
    8885    }
    89     if (RouterProcessStatus.routerStartedAt != Optional.none) {
    90       routerUptimeLabel?.cell?.stringValue = "Router has runned for " + DateTimeUtils.timeAgoSinceDate(date: NSDate(date: RouterProcessStatus.routerStartedAt!), numericDates: false)
     86    if let routerStartTime = RouterProcessStatus.routerStartedAt {
     87      routerUptimeLabel?.cell?.stringValue = "Router has runned for " + DateTimeUtils.timeAgoSinceDate(date: NSDate(date: routerStartTime), numericDates: false)
    9188    }
    9289  }
  • launchers/macosx/Info.plist

    r46ac0087 r4369b7d  
    1010        <string>Public Domain</string>
    1111        <key>CFBundleGetInfoString</key>
    12         <string>0.9.35-experimental</string>
     12        <string>0.9.36-experimental</string>
    1313        <key>CFBundleIconFile</key>
    1414        <string>images/AppIcon.icns</string>
  • launchers/macosx/README.md

    r46ac0087 r4369b7d  
    11# The Mac OS X Launcher
     2
     3## Misc
    24
    35**Note** this project is WIP, cause Meeh has yet to merge in Obj-C/Swift code for GUI stuff in OSX.
     
    79More code will be merged in, it's just a f* mess which Meeh needs to clean up and move into repo.
    810
    9 `./fullBuild.sh` triggers Ant jobs and prepare the base.zip, as well as starting the ninja build.
     11## Howto build
     12
     13You can both build the project from the Xcode UI or you can build it from command line.
     14
     15An example build command:
     16`xcodebuild -target I2PLauncher -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk`
     17
     18
  • launchers/macosx/RouterTask.h

    r46ac0087 r4369b7d  
    33#include <dispatch/dispatch.h>
    44#include <memory.h>
    5 #include <string.h>
    65
    76#include <Cocoa/Cocoa.h>
     
    98
    109#ifdef __cplusplus
    11 #include "include/subprocess.hpp"
     10#include <vector>
     11#include <string>
    1212
    13 using namespace subprocess;
    14 class JavaRunner;
     13const std::vector<NSString*> defaultStartupFlags {
     14  @"-Xmx512M",
     15  @"-Xms128m",
     16  @"-Djava.awt.headless=true",
     17  @"-Dwrapper.logfile=/tmp/router.log",
     18  @"-Dwrapper.logfile.loglevel=DEBUG",
     19  @"-Dwrapper.java.pidfile=/tmp/routerjvm.pid",
     20  @"-Dwrapper.console.loglevel=DEBUG"
     21};
    1522
    16 typedef std::function<void(void)> fp_t;
    17 typedef std::function<void(JavaRunner *ptr)> fp_proc_t;
    18 
    19 
    20 
    21 /**
    22  *
    23  * class JavaRunner
    24  *
    25  **/
    26 class JavaRunner
    27 {
    28 public:
    29   // copy fn
    30   JavaRunner(std::string& javaBin, std::string& arguments, std::string& i2pBaseDir, const fp_proc_t& executingFn, const fp_t& cb);
    31   ~JavaRunner() = default;
    32  
    33   static const std::vector<NSString*> defaultStartupFlags;
    34   static const std::vector<std::string> defaultFlagsForExtractorJob;
    35  
    36   void requestRouterShutdown();
    37  
    38   std::future<int> execute();
    39   std::shared_ptr<subprocess::Popen> javaProcess;
    40   std::string javaBinaryPath;
    41   std::string javaRouterArgs;
    42   std::string execLine;
    43   std::string _i2pBaseDir;
    44 private:
    45   const fp_proc_t& executingFn;
    46   const fp_t& exitCallbackFn;
     23const std::vector<std::string> defaultFlagsForExtractorJob {
     24  "-Xmx512M",
     25  "-Xms128m",
     26  "-Djava.awt.headless=true"
    4727};
    4828
  • launchers/macosx/RouterTask.mm

    r46ac0087 r4369b7d  
    1010#include "AppDelegate.h"
    1111#endif
     12
    1213#include "include/PidWatcher.h"
    1314
     
    5051        object:stdoutFileHandle];
    5152
    52     [stdoutFileHandle waitForDataInBackgroundAndNotify];
     53  [stdoutFileHandle waitForDataInBackgroundAndNotify];
    5354
    54     [self.routerTask setTerminationHandler:^(NSTask* task) {
    55       NSLog(@"termHandler triggered!");
    56       auto swiftRouterStatus = [[RouterProcessStatus alloc] init];
    57       [swiftRouterStatus setRouterStatus: true];
    58       NSBundle *launcherBundle = [NSBundle mainBundle];
    59       auto iconImage = [launcherBundle pathForResource:@"AppIcon" ofType:@"png"];
    60       sendUserNotification(APP_IDSTR, @"I2P Router has stopped");
    61       // Cleanup
    62       self.isRouterRunning = NO;
    63     }];
    64 /*
    65     self.readLogHandle = [self.processPipe fileHandleForReading];
    66     NSData *inData = nil;
    67     self.totalLogData = [[[NSMutableData alloc] init] autorelease];
    68 
    69     while ((inData = [self.readLogHandle availableData]) &&
    70         [inData length]) {
    71         [self.totalLogData appendData:inData];
    72     }
    73 */
     55  [self.routerTask setTerminationHandler:^(NSTask* task) {
     56    // Cleanup
     57    NSLog(@"termHandler triggered!");
     58    auto swiftRouterStatus = [[RouterProcessStatus alloc] init];
     59    [swiftRouterStatus setRouterStatus: false];
     60    [swiftRouterStatus setRouterRanByUs: false];
     61    sendUserNotification(APP_IDSTR, @"I2P Router has stopped");
     62  }];
    7463    return self;
    7564}
     
    9483{
    9584    @try {
    96         [self.routerTask launch];
    97         watchPid([self.routerTask processIdentifier]);
    98         self.isRouterRunning = YES;
    99         return 1;
     85      [self.routerTask launch];
     86      watchPid([self.routerTask processIdentifier]);
     87      self.isRouterRunning = YES;
     88      return 1;
    10089    }
    10190    @catch (NSException *e)
    10291        {
    10392                NSLog(@"Expection occurred %@", [e reason]);
    104         return 0;
     93    auto swiftRouterStatus = [[RouterProcessStatus alloc] init];
     94    [swiftRouterStatus setRouterStatus: false];
     95    [swiftRouterStatus setRouterRanByUs: false];
     96    sendUserNotification(@"An error occured, can't start the I2P Router", [e reason]);
     97    return 0;
    10598        }
    10699}
     
    108101- (int) getPID
    109102{
    110     return [self.routerTask processIdentifier];
     103  return [self.routerTask processIdentifier];
    111104}
    112105
    113106@end
    114 
    115 #ifdef __cplusplus
    116 
    117 
    118 const std::vector<NSString*> JavaRunner::defaultStartupFlags {
    119     @"-Xmx512M",
    120     @"-Xms128m",
    121     @"-Djava.awt.headless=true",
    122     @"-Dwrapper.logfile=/tmp/router.log",
    123     @"-Dwrapper.logfile.loglevel=DEBUG",
    124     @"-Dwrapper.java.pidfile=/tmp/routerjvm.pid",
    125     @"-Dwrapper.console.loglevel=DEBUG"
    126 };
    127 
    128 const std::vector<std::string> JavaRunner::defaultFlagsForExtractorJob {
    129     "-Xmx512M",
    130     "-Xms128m",
    131     "-Djava.awt.headless=true"
    132 };
    133 
    134 JavaRunner::JavaRunner(std::string& javaBin, std::string& arguments, std::string& i2pBaseDir, const fp_proc_t& execFn, const fp_t& cb)
    135   : javaBinaryPath(javaBin), javaRouterArgs(arguments), _i2pBaseDir(i2pBaseDir), executingFn(execFn), exitCallbackFn(cb)
    136 {
    137   execLine = javaBinaryPath;
    138   execLine += " " + std::string(javaRouterArgs.c_str());
    139   printf("CLI: %s\n",execLine.c_str());
    140   javaProcess = std::shared_ptr<Popen>(new Popen(execLine, environment{{
    141             {"I2PBASE", _i2pBaseDir},
    142             {"JAVA_OPTS", getenv("JAVA_OPTS")}
    143         }}, defer_spawn{true}));
    144 }
    145 
    146 void JavaRunner::requestRouterShutdown()
    147 {
    148     // SIGHUP
    149     javaProcess->kill(1);
    150 }
    151 
    152 std::future<int> JavaRunner::execute()
    153 {
    154   try {
    155     auto executingFn = dispatch_block_create(DISPATCH_BLOCK_INHERIT_QOS_CLASS, ^{
    156       this->executingFn(this);
    157     });
    158     dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), executingFn);
    159     dispatch_block_wait(executingFn, DISPATCH_TIME_FOREVER);
    160 
    161     // Here, the process is done executing.
    162 
    163     printf("Finished executingFn - Runs callbackFn\n");
    164     this->exitCallbackFn();
    165     return std::async(std::launch::async, []{ return 0; });
    166   } catch (std::exception* ex) {
    167     printf("ERROR: %s\n", ex->what());
    168     return std::async(std::launch::async, []{ return 1; });
    169   }
    170 }
    171 
    172 #endif
  • launchers/macosx/include/strutil.hpp

    r46ac0087 r4369b7d  
    5454}
    5555
    56 using std::experimental::optional;
    57 
    58 // Use CFStringRef instead of NSString*, otherwise disable ARC
    59 inline optional<CFStringRef> optionalString(bool val) {
    60     optional<CFStringRef> myOptString;
    61     if(val) {
    62         // Cast to corresponding CoreFoundation object
    63         myOptString = (CFStringRef)@"String";
    64     }
    65     return myOptString;
     56inline bool replace(std::string& str, const std::string& from, const std::string& to) {
     57  size_t start_pos = str.find(from);
     58  if(start_pos == std::string::npos)
     59    return false;
     60  str.replace(start_pos, from.length(), to);
     61  return true;
    6662}
    6763
     
    10399}
    104100
     101#if __cplusplus > 201402L
     102
     103
     104using std::optional;
     105
     106// Use CFStringRef instead of NSString*, otherwise disable ARC
     107inline optional<CFStringRef> optionalString(bool val) {
     108  optional<CFStringRef> myOptString;
     109  if(val) {
     110    // Cast to corresponding CoreFoundation object
     111    myOptString = (CFStringRef)@"String";
     112  }
     113  return myOptString;
     114}
     115
    105116#endif
     117
     118
     119#endif
  • launchers/macosx/main.mm

    r46ac0087 r4369b7d  
    1212#import <Foundation/Foundation.h>
    1313#import <Foundation/NSFileManager.h>
    14 
    15 
    16 #include <CoreFoundation/CoreFoundation.h>
    17 #include <CoreFoundation/CFStream.h>
    18 #include <CoreFoundation/CFPropertyList.h>
    19 #include <CoreFoundation/CFDictionary.h>
    20 #include <CoreFoundation/CFArray.h>
    21 #include <CoreFoundation/CFString.h>
    2214#include <CoreFoundation/CFPreferences.h>
    2315
     
    3123#include "AppDelegate.h"
    3224#include "RouterTask.h"
    33 #include "JavaHelper.h"
    3425#include "include/fn.h"
    3526#include "include/portcheck.h"
     27#import "SBridge.h"
     28
     29#ifdef __cplusplus
     30#include <string>
     31
     32#include "include/subprocess.hpp"
     33#include "include/strutil.hpp"
     34
     35using namespace subprocess;
     36
     37#endif
    3638
    3739#define debug(format, ...) CFShow([NSString stringWithFormat:format, ## __VA_ARGS__]);
     
    4042@end
    4143
    42 #ifdef __cplusplus
    43 #import "SBridge.h"
    44 JvmListSharedPtr gRawJvmList = nullptr;
    45 #endif
    46 
    47 
    48 @interface AppDelegate () <NSUserNotificationCenterDelegate, NSApplicationDelegate>
    49 @end
    50 
    51 #ifdef __cplusplus
    52 maybeAnRouterRunner getGlobalRouterObject()
    53 {
    54     std::lock_guard<std::mutex> lock(globalRouterStatusMutex);
    55     return globalRouterStatus; // Remember this might be nullptr now.
    56 }
    57 
    58 void setGlobalRouterObject(I2PRouterTask* newRouter)
    59 {
    60     std::lock_guard<std::mutex> lock(globalRouterStatusMutex);
    61     globalRouterStatus = newRouter;
    62 }
    63 
    64 
    65 pthread_mutex_t mutex;
    66 
    67 bool getGlobalRouterIsRunning()
    68 {
    69     pthread_mutex_lock(&mutex);
    70     bool current = isRuterRunning;
    71     pthread_mutex_unlock(&mutex);
    72     return current;
    73 }
    74 void setGlobalRouterIsRunning(bool running)
    75 {
    76     pthread_mutex_lock(&mutex);
    77     isRuterRunning = running;
    78     pthread_mutex_unlock(&mutex);
    79 }
    80 
    81 #endif
    82 
    8344
    8445@implementation ExtractMetaInfo : NSObject
    8546@end
    8647
     48
     49@implementation AppDelegate
     50
     51- (void) awakeFromNib {
     52}
     53
     54
     55- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
     56     shouldPresentNotification:(NSUserNotification *)notification {
     57  return YES;
     58}
     59
    8760#ifdef __cplusplus
    88 
    89 bool replace(std::string& str, const std::string& from, const std::string& to) {
    90   size_t start_pos = str.find(from);
    91   if(start_pos == std::string::npos)
    92     return false;
    93   str.replace(start_pos, from.length(), to);
    94   return true;
    95 }
    96 
    97 #endif
    98 
    99 @implementation AppDelegate
    100 
    101 - (void) awakeFromNib {
    102 }
    103 
    104 #ifdef __cplusplus
    105 
    106 #include <unistd.h>
    107 #include <sys/types.h>
    108 #include <pwd.h>
    109 #include <assert.h>
    110 
    111 #include "include/subprocess.hpp"
    112 
    113 using namespace subprocess;
    114 
    115 const char* RealHomeDirectory() {
    116   struct passwd *pw = getpwuid(getuid());
    117   assert(pw);
    118   return pw->pw_dir;
    119 }
    12061
    12162- (void)extractI2PBaseDir:(void(^)(BOOL success, NSError *error))completion
     
    15293      mkdir(basePath.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
    15394
    154       auto cli = JavaRunner::defaultFlagsForExtractorJob;
     95      auto cli = defaultFlagsForExtractorJob;
    15596      setenv("I2PBASE", basePath.c_str(), true);
    15697      setenv("ZIPPATH", zippath.c_str(), true);
     
    162103      cli.push_back("net.i2p.launchers.BaseExtractor");
    163104      auto rs = [[RouterProcessStatus alloc] init];
    164       NSString* jh = [rs getJavaHome];
    165       if (jh != nil) {
    166         NSLog(@"jh er %@", jh);
    167       }
    168      
    169       NSString* newString = [NSString stringWithFormat:@"file://%@", rs.getJavaHome];
    170       NSURL *baseURL = [NSURL fileURLWithPath:newString];
    171      
    172       NSLog(@"MEEH URL PATH: %s", [baseURL fileSystemRepresentation]);
    173 
    174       auto charCli = map(cli, [](std::string str){ return str.c_str(); });
     105     
    175106      std::string execStr = std::string([rs.getJavaHome UTF8String]);
    176       // TODO: Cheap hack, make it better.
    177       replace(execStr, "Internet Plug-Ins", "Internet\\ Plug-Ins");
    178       replace(execStr, "\n", "");
    179       NSLog(@"Java path1 = %s", execStr.c_str());
    180       [rs setJavaHome: [NSString stringWithFormat:@"%s", execStr.c_str()]];
    181107      for_each(cli, [&execStr](std::string str){ execStr += std::string(" ") + str; });
    182      
    183       //execStr = replace(execStr, "\\\\ ", "\\ ");
    184       //NSLog(@"Java path2 = %s", execStr.c_str());
    185108
    186109      NSLog(@"Trying cmd: %@", [NSString stringWithUTF8String:execStr.c_str()]);
     
    194117        if (extractStatus == 0)
    195118        {
    196           //success = YES;
    197           NSLog(@"Time to detect I2P version in install directory");
    198           [self.swiftRuntime findInstalledI2PVersion];
     119          NSLog(@"Extraction complete!");
    199120        }
    200121     
     
    208129      // All done. Assume success and error are already set.
    209130      dispatch_async(dispatch_get_main_queue(), ^{
    210         //sendUserNotification(APP_IDSTR, @"Extraction complete!", self.contentImage);
    211131        if (completion) {
    212132          completion(success, error);
     
    220140    }
    221141  });
    222    
    223  
    224 }
    225 
    226 #endif
    227 
    228 - (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
    229                                shouldPresentNotification:(NSUserNotification *)notification {
    230     return YES;
    231 }
    232 
    233 
    234 #ifdef __cplusplus
    235 
    236 inline std::string getDefaultBaseDir()
    237 {
    238   // Figure out base directory
    239   const char* pathFromHome = "/Users/%s/Library/I2P";
    240   auto username = getenv("USER");
    241   char buffer[strlen(pathFromHome)+strlen(username)];
    242   sprintf(buffer, pathFromHome, username);
    243   std::string i2pBaseDir(buffer);
    244   return i2pBaseDir;
    245 }
    246 
    247 - (NSString *)userSelectJavaHome:(JvmListPtr)rawJvmList
    248 {
    249   NSString *appleScriptString = @"set jvmlist to {\"Newest\"";
    250   for (auto item : *rawJvmList) {
    251     auto str = strprintf(",\"%s\"", item->JVMName.c_str()).c_str();
    252     NSString* tmp = [NSString stringWithUTF8String:str];
    253     appleScriptString = [appleScriptString stringByAppendingString:tmp];
    254   }
    255   appleScriptString = [appleScriptString stringByAppendingString:@"}\nchoose from list jvmlist\n"];
    256   NSAppleScript *theScript = [[NSAppleScript alloc] initWithSource:appleScriptString];
    257   NSDictionary *theError = nil;
    258   NSString* userResult = [[theScript executeAndReturnError: &theError] stringValue];
    259   NSLog(@"User choosed %@.\n", userResult);
    260   if (theError != nil)
    261   {
    262     NSLog(@"Error: %@.\n", theError);
    263   }
    264   return userResult;
    265 }
    266 
    267 
    268 - (void)userChooseJavaHome {
    269   listAllJavaInstallsAvailable();
    270   std::shared_ptr<JvmHomeContext> appContext = std::shared_ptr<JvmHomeContext>( new JvmHomeContext() );
    271   for (auto item : *appContext->getJvmList()) {
    272     printf("JVM %s (Version: %s, Directory: %s)\n", item->JVMName.c_str(), item->JVMPlatformVersion.c_str(), item->JVMHomePath.c_str());
    273   }
    274   JvmListPtr rawJvmList = appContext->getJvmList();
    275   NSString * userJavaHome = [self userSelectJavaHome: rawJvmList];
    276   // TODO: Add logic so user can set preferred JVM
    277 }
    278 
    279 #endif
     142}
    280143
    281144- (void)setApplicationDefaultPreferences {
    282   auto defaultJVMHome = check_output({"/usr/libexec/java_home","-v",DEF_MIN_JVM_VER});
    283   auto tmpStdStr = std::string(defaultJVMHome.buf.data());
    284   trim(tmpStdStr);
    285   auto cfDefaultHome  = CFStringCreateWithCString(NULL, const_cast<const char *>(tmpStdStr.c_str()), kCFStringEncodingUTF8);
    286   /*[self.userPreferences registerDefaults:@{
    287     @"javaHome" : (NSString *)cfDefaultHome,
    288     @"lastI2PVersion" : (NSString *)CFSTR(DEF_I2P_VERSION),
     145  [self.userPreferences registerDefaults:@{
    289146    @"enableLogging": @YES,
    290147    @"enableVerboseLogging": @YES,
    291148    @"autoStartRouter": @YES,
    292149    @"i2pBaseDirectory": (NSString *)CFStringCreateWithCString(NULL, const_cast<const char *>(getDefaultBaseDir().c_str()), kCFStringEncodingUTF8)
    293   }];*/
    294   if (self.enableVerboseLogging) NSLog(@"Default JVM home preference set to: %@", cfDefaultHome);
     150  }];
    295151
    296152  auto dict = [self.userPreferences dictionaryRepresentation];
     
    303159}
    304160
     161#endif
     162
    305163
    306164- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
     
    309167  self.swiftRuntime = [[SwiftMainDelegate alloc] init];
    310168 
     169  // This setup allows the application to send notifications
    311170  [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
     171 
     172 
    312173  // Start with user preferences
    313174  self.userPreferences = [NSUserDefaults standardUserDefaults];
     
    315176  self.enableLogging = [self.userPreferences boolForKey:@"enableLogging"];
    316177  self.enableVerboseLogging = [self.userPreferences boolForKey:@"enableVerboseLogging"];
    317 
    318 
    319 #ifdef __cplusplus
    320   gRawJvmList = std::make_shared<std::list<JvmVersionPtr> >(std::list<JvmVersionPtr>());
    321 #endif
    322178  // In case we are unbundled, make us a proper UI application
    323179  [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
    324180  [NSApp activateIgnoringOtherApps:YES];
    325181
    326   // TODO: Also check for new installations from time to time.
    327  
     182
    328183#ifdef __cplusplus
    329   auto javaHomePref = [self.userPreferences stringForKey:@"javaHome"];
    330   if (self.enableVerboseLogging)
    331   {
    332     NSLog(@"Java home from preferences: %@", javaHomePref);
    333   }
    334 
    335   if (self.enableVerboseLogging)
    336   {
    337     NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
    338     NSLog(@"Appdomain is: %@", appDomain);
    339   }
    340 
    341   NSLog(@"We should have started the statusbar object by now...");
     184
    342185  RouterProcessStatus* routerStatus = [[RouterProcessStatus alloc] init];
    343 
    344186  std::string i2pBaseDir(getDefaultBaseDir());
    345 
    346   auto pref = self.userPreferences;
    347  
     187  NSLog(@"i2pBaseDir = %s", i2pBaseDir.c_str());
    348188  bool shouldAutoStartRouter = false;
    349 
     189 
     190  // TODO: Make the port a setting which defaults to 7657
    350191  if (port_check(7657) != 0)
    351192  {
     
    355196    [routerStatus setRouterStatus: true];
    356197    [routerStatus setRouterRanByUs: false];
    357     return;
     198    shouldAutoStartRouter = false;
    358199  } else {
    359200    shouldAutoStartRouter = true;
     
    362203  if (self.enableVerboseLogging) NSLog(@"processinfo %@", [[NSProcessInfo processInfo] arguments]);
    363204
    364   auto getJavaBin = [&pref,&self]() -> std::string {
    365     // Get Java home
    366     /*NSString* val = @"";
    367     val = [pref stringForKey:@"javaHome"];
    368     if (val == NULL) val = @"";
    369     if (self.enableVerboseLogging) NSLog(@"Javahome: %@", val);
    370     auto javaHome = std::string([val UTF8String]);
    371     //trim(javaHome); // Trim to remove endline
    372     auto javaBin = std::string(javaHome);
    373     javaBin += "/bin/java"; // Append java binary to path.
    374     return javaBin;*/
    375     DetectJava *dt = [[DetectJava alloc] init];
    376     [dt findIt];
    377     if ([dt isJavaFound]) {
    378       return [dt.javaHome UTF8String];
    379     } else {
    380       throw new std::runtime_error("Java home fatal error");
    381     }
    382   };
    383 
    384205
    385206  NSBundle *launcherBundle = [NSBundle mainBundle];
    386  
    387   auto jarResPath = [launcherBundle pathForResource:@"launcher" ofType:@"jar"];
    388   NSLog(@"Trying to load launcher.jar from url = %@", jarResPath);
    389    
     207  auto sBridge = [[SBridge alloc] init];
     208 
     209  // Helper object to hold statefull path information
    390210  self.metaInfo = [[ExtractMetaInfo alloc] init];
    391   //self.metaInfo.i2pBase = [NSString stringWithUTF8String:i2pBaseDir.c_str()];
    392   self.metaInfo.javaBinary = [NSString stringWithUTF8String:getJavaBin().c_str()];
     211  self.metaInfo.i2pBase = [NSString stringWithUTF8String:i2pBaseDir.c_str()];
     212  self.metaInfo.javaBinary = [routerStatus getJavaHome];
    393213  self.metaInfo.jarFile = [launcherBundle pathForResource:@"launcher" ofType:@"jar"];
    394214  self.metaInfo.zipFile = [launcherBundle pathForResource:@"base" ofType:@"zip"];
    395215
    396216  std::string basearg("-Di2p.dir.base=");
    397   //basearg += i2pBaseDir;
     217  basearg += i2pBaseDir;
    398218
    399219  std::string jarfile("-cp ");
    400220  jarfile += [self.metaInfo.zipFile UTF8String];
    401221 
     222  // Initialize the Swift environment (the UI components)
     223  [self.swiftRuntime applicationDidFinishLaunching];
    402224
    403225  struct stat sb;
     
    407229    if (self.enableVerboseLogging) NSLog(@"I2P Directory don't exists!");
    408230
     231    // Might be hard to read if you're not used to Objective-C
     232    // But this is a "function call" that contains a "callback function"
    409233    [self extractI2PBaseDir:^(BOOL success, NSError *error) {
    410234      sendUserNotification(@"I2P is done extracting", @"I2P is now installed and ready to run!");
    411       [self.swiftRuntime applicationDidFinishLaunching];
    412235      NSLog(@"Done extracting I2P");
    413       if (shouldAutoStartRouter) [self startupI2PRouter];
     236     
     237      NSLog(@"Time to detect I2P version in install directory");
     238      [self.swiftRuntime findInstalledI2PVersion];
     239      if (shouldAutoStartRouter) {
     240        [sBridge startupI2PRouter:self.metaInfo.i2pBase javaBinPath:self.metaInfo.javaBinary];
     241        [routerStatus setRouterRanByUs: true];
     242      }
    414243    }];
    415244
    416245  } else {
    417     if (self.enableVerboseLogging) NSLog(@"I2P directory found!");
    418     if (shouldAutoStartRouter) [self startupI2PRouter];
    419     [self.swiftRuntime applicationDidFinishLaunching];
     246    // I2P was already found extracted
     247    NSLog(@"Time to detect I2P version in install directory");
     248    [self.swiftRuntime findInstalledI2PVersion];
     249   
     250    if (shouldAutoStartRouter) {
     251      [sBridge startupI2PRouter:self.metaInfo.i2pBase javaBinPath:self.metaInfo.javaBinary];
     252      [routerStatus setRouterRanByUs: true];
     253    }
    420254  }
    421255 
     
    449283{
    450284  NSApplication *app = [NSApplication sharedApplication];
    451   //NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    452285
    453286  AppDelegate *appDelegate = [[AppDelegate alloc] initWithArgc:argc argv:argv];
    454287  app.delegate = appDelegate;
     288  auto mainBundle = [NSBundle mainBundle];
     289  NSString* stringNameBundle = [mainBundle objectForInfoDictionaryKey:(NSString *)kCFBundleNameKey];
     290  if ([[NSRunningApplication runningApplicationsWithBundleIdentifier:[mainBundle bundleIdentifier]] count] > 1) {
     291    [[NSAlert alertWithMessageText:[NSString stringWithFormat:@"Another copy of %@ is already running.",stringNameBundle]
     292                     defaultButton:nil alternateButton:nil otherButton:nil informativeTextWithFormat:@"This copy will now quit."] runModal];
     293   
     294    [NSApp terminate:nil];
     295  }
    455296  [NSBundle loadNibNamed:@"I2Launcher" owner:NSApp];
    456297
    457298  [NSApp run];
    458   // Handle any errors
    459   //[pool drain];
    460299  return 0;
    461300}
Note: See TracChangeset for help on using the changeset viewer.