Changeset 7a72049
- Timestamp:
- Sep 23, 2018 3:33:29 AM (2 years ago)
- Branches:
- master
- Children:
- e59d7a82
- Parents:
- 3b38f5a
- Location:
- launchers/macosx
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
launchers/macosx/I2PLauncher/Base.lproj/UserInterfaces.xib
r3b38f5a r7a72049 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14 113" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">2 <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> 3 3 <dependencies> 4 <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14113"/> 4 <deployment identifier="macosx"/> 5 <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.18"/> 5 6 </dependencies> 6 7 <objects> … … 37 38 <point key="canvasLocation" x="17" y="167"/> 38 39 </menu> 40 <customObject id="xTS-ll-kWI" customClass="SUUpdater"/> 39 41 </objects> 40 42 </document> -
launchers/macosx/I2PLauncher/I2PLauncher-Bridging-Header.h
r3b38f5a r7a72049 6 6 #import "AppDelegate.h" 7 7 #import "RouterTask.h" 8 #import "Sparkle/SUUpdater.h" 8 9 -
launchers/macosx/I2PLauncher/Info.plist
r3b38f5a r7a72049 18 18 <string>APPL</string> 19 19 <key>CFBundleShortVersionString</key> 20 <string>1.0</string> 21 <key>CFBundleURLTypes</key> 22 <array> 23 <dict> 24 <key>CFBundleTypeRole</key> 25 <string>Editor</string> 26 <key>CFBundleURLIconFile</key> 27 <string>ItoopieTransparent</string> 28 <key>CFBundleURLName</key> 29 <string>http+i2p</string> 30 <key>CFBundleURLSchemes</key> 31 <array> 32 <string>http+i2p</string> 33 </array> 34 </dict> 35 </array> 20 <string>0.1.1</string> 36 21 <key>CFBundleVersion</key> 37 <string> 4</string>22 <string>5</string> 38 23 <key>LSApplicationCategoryType</key> 39 24 <string>public.app-category.utilities</string> … … 55 40 </array> 56 41 <key>SUFeedURL</key> 57 <string>http://i2browser.i2p/updates/v1/appcast.xml</string> 42 <string>https://download.i2p2.de/macosx/sparkle/updates/v1/appcast.xml</string> 43 <key>SUPublicEDKey</key> 44 <string>weKSpHXfJzk+5qy3UVfqsUwTeLnT9WCFVMwd9yW0+DA=</string> 58 45 </dict> 59 46 </plist> -
launchers/macosx/I2PLauncher/Storyboard.storyboard
r3b38f5a r7a72049 155 155 </viewController> 156 156 <customObject id="d8g-wS-Zts" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/> 157 <customObject id="4gn-BI-uSC" userLabel="Updater" customClass="SUUpdater"/> 157 158 </objects> 158 159 <point key="canvasLocation" x="-823" y="166"/> -
launchers/macosx/I2PLauncher/SwiftMainDelegate.swift
r3b38f5a r7a72049 70 70 71 71 @objc func applicationDidFinishLaunching() { 72 print("Hello from swift!")73 72 var i2pPath = NSHomeDirectory() 74 73 i2pPath += "/Library/I2P" 75 74 76 findInstalledI2PVersion() 75 } 76 77 @objc func listenForEvent(eventName: String, callbackActionFn: @escaping ((Any?)->()) ) { 78 RouterManager.shared().eventManager.listenTo(eventName: eventName, action: callbackActionFn ) 79 } 80 81 @objc func triggerEvent(en: String, details: String? = nil) { 82 RouterManager.shared().eventManager.trigger(eventName: en, information: details) 77 83 } 78 84 -
launchers/macosx/I2PLauncher/routermgmt/RouterManager.swift
r3b38f5a r7a72049 39 39 if (packedVersion.compare(currentVersion, options: .numeric) == .orderedDescending) { 40 40 Swift.print("event! - router version: Packed version is newer, gonna re-deploy") 41 RouterManager.shared().eventManager.trigger(eventName: "router_must_upgrade", information: "got new version") 41 42 } else { 42 43 Swift.print("event! - router version: No update needed") -
launchers/macosx/I2PLauncher/routermgmt/RouterProcessStatus.swift
r3b38f5a r7a72049 37 37 RouterManager.shared().eventManager.trigger(eventName: en, information: details) 38 38 } 39 40 @objc func listenForEvent(eventName: String, callbackActionFn: @escaping ((Any?)->()) ) { 41 RouterManager.shared().eventManager.listenTo(eventName: eventName, action: callbackActionFn ) 42 } 39 43 } 40 44 41 45 extension RouterProcessStatus { 42 static var isRouterRunning : Bool = false43 static var isRouterChildProcess : Bool = false46 static var isRouterRunning : Bool = (RouterManager.shared().getRouterTask() != nil) 47 static var isRouterChildProcess : Bool = (RouterManager.shared().getRouterTask() != nil) 44 48 static var routerVersion : String? = Optional.none 45 static var routerUptime : String? = Optional.none{46 //Called before the change47 willSet(newValue){48 print("RouterProcessStatus.routerUptime will change from ", (self.routerUptime ?? "nil"), " to "+(newValue ?? "nil"))49 }50 51 //Called after the change52 didSet{53 print("RouterProcessStatus.routerUptime did change to "+self.routerUptime!)54 }55 }56 49 static var routerStartedAt : Date? = Optional.none 57 50 static var knownJavaBinPath : String? = Optional.none -
launchers/macosx/I2PLauncher/userinterface/RouterStatusView.swift
r3b38f5a r7a72049 29 29 @objc func actionBtnStartRouter(_ sender: Any?) { 30 30 NSLog("START ROUTER") 31 if ( !(RouterManager.shared().getRouterTask()?.isRunning())!) {31 if (RouterManager.shared().getRouterTask() == nil) { 32 32 SBridge.sharedInstance().startupI2PRouter(RouterProcessStatus.i2pDirectoryPath, javaBinPath: RouterProcessStatus.knownJavaBinPath!) 33 33 } … … 37 37 @objc func actionBtnStopRouter(_ sender: Any?) { 38 38 NSLog("STOP ROUTER") 39 if ( (RouterManager.shared().getRouterTask()?.isRunning())!) {39 if (RouterManager.shared().getRouterTask() != nil) { 40 40 NSLog("Found running router") 41 41 RouterManager.shared().getRouterTask()?.requestShutdown() … … 45 45 46 46 @objc func actionBtnRestartRouter(sender: Any?) { 47 if ( (RouterManager.shared().getRouterTask()?.isRunning())!) {47 if (RouterManager.shared().getRouterTask() != nil) { 48 48 RouterManager.shared().getRouterTask()?.requestRestart() 49 49 } else { -
launchers/macosx/I2PLauncher/userinterface/StatusBarController.swift
r3b38f5a r7a72049 10 10 import Cocoa 11 11 12 13 12 @objc class StatusBarController: NSObject, NSMenuDelegate { 14 13 15 14 let popover = NSPopover() 16 15 let statusItem = NSStatusBar.system().statusItem(withLength: NSVariableStatusItemLength) 17 //let storyboard = NSStoryboard(name: "Storyboard", bundle: nil) 16 let storyboard = NSStoryboard(name: "Storyboard", bundle: Bundle.main) 17 18 var updateObjectRef : SUUpdater? 18 19 19 20 @objc func handleOpenConsole(_ sender: Any?) { … … 24 25 let menu = NSMenu() 25 26 27 let updateMenuItem = NSMenuItem(title: "Check for updates", action: #selector(self.updateObjectRef?.checkForUpdates(_:)), keyEquivalent: "U") 28 updateMenuItem.isEnabled = true 29 26 30 menu.addItem(NSMenuItem(title: "Open I2P Console", action: #selector(self.handleOpenConsole(_:)), keyEquivalent: "O")) 31 menu.addItem(NSMenuItem.separator()) 32 menu.addItem(updateMenuItem) 27 33 menu.addItem(NSMenuItem.separator()) 28 34 menu.addItem(NSMenuItem(title: "Quit I2P Launcher", action: #selector(SwiftMainDelegate.terminate(_:)), keyEquivalent: "q")) … … 35 41 super.init() 36 42 popover.contentViewController = PopoverViewController.freshController() 43 updateObjectRef = SUUpdater.shared() 44 updateObjectRef?.checkForUpdatesInBackground() 45 37 46 38 47 if let button = statusItem.button { -
launchers/macosx/RouterTask.h
r3b38f5a r7a72049 40 40 @interface I2PRouterTask : NSObject 41 41 @property (strong) NSTask* routerTask; 42 43 // TODO: Not in use, remove?44 /*45 @property (strong) NSUserDefaults *userPreferences;46 @property (strong) NSFileHandle *readLogHandle;47 @property (strong) NSMutableData *totalLogData;48 @property (strong) NSFileHandle *input;49 */50 51 42 @property (strong) NSPipe *processPipe; 52 43 @property (atomic) BOOL isRouterRunning; -
launchers/macosx/RouterTask.mm
r3b38f5a r7a72049 45 45 [self.routerTask setStandardError:self.processPipe]; 46 46 47 /*48 NSFileHandle *stdoutFileHandle = [self.processPipe fileHandleForReading];49 dup2([[self.processPipe fileHandleForWriting] fileDescriptor], fileno(stdout));50 auto source = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, [stdoutFileHandle fileDescriptor], 0, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));51 dispatch_source_set_event_handler(source, ^{52 void* data = malloc(4096);53 ssize_t readResult = 0;54 do55 {56 errno = 0;57 readResult = read([stdoutFileHandle fileDescriptor], data, 4096);58 } while (readResult == -1 && errno == EINTR);59 if (readResult > 0)60 {61 //AppKit UI should only be updated from the main thread62 dispatch_async(dispatch_get_main_queue(),^{63 NSString* stdOutString = [[NSString alloc] initWithBytesNoCopy:data length:readResult encoding:NSUTF8StringEncoding freeWhenDone:YES];64 NSAttributedString* stdOutAttributedString = [[NSAttributedString alloc] initWithString:stdOutString];65 NSLog(@"Router stdout: %@", stdOutString);66 //auto logForwarder = new LogForwarder();67 //[logForwarder appendLogViewWithLogLine:stdOutAttributedString];68 });69 }70 else{free(data);}71 });72 dispatch_resume(source);73 */74 /*75 [[NSNotificationCenter defaultCenter] addObserver:self76 selector:@selector(routerStdoutData:)77 name:NSFileHandleDataAvailableNotification78 object:stdoutFileHandle];79 80 [stdoutFileHandle waitForDataInBackgroundAndNotify];81 */82 83 47 [self.routerTask setTerminationHandler:^(NSTask* task) { 84 48 // Cleanup … … 113 77 { 114 78 @try { 115 auto swiftRouterStatus = [[RouterProcessStatus alloc] init];116 [swiftRouterStatus triggerEventWithEn:@"router_start" details:@"normal start"];117 79 [self.routerTask launch]; 118 80 self.isRouterRunning = YES; -
launchers/macosx/SBridge.h
r3b38f5a r7a72049 19 19 #include <vector> 20 20 #include "include/fn.h" 21 std::future<int> startupRouter(NSString* javaBin, NSArray<NSString*>* arguments, NSString* i2pBaseDir);21 //std::future<int> startupRouter(NSString* javaBin, NSArray<NSString*>* arguments, NSString* i2pBaseDir, RouterProcessStatus* routerStatus = nil); 22 22 23 23 -
launchers/macosx/SBridge.mm
r3b38f5a r7a72049 27 27 28 28 29 std::future<int> startupRouter(NSString* javaBin, NSArray<NSString*>* arguments, NSString* i2pBaseDir ) {29 std::future<int> startupRouter(NSString* javaBin, NSArray<NSString*>* arguments, NSString* i2pBaseDir, RouterProcessStatus* routerStatus) { 30 30 @try { 31 31 RTaskOptions* options = [RTaskOptions alloc]; … … 37 37 [[SBridge sharedInstance] setCurrentRouterInstance:instance]; 38 38 [instance execute]; 39 if (routerStatus != nil) { 40 [routerStatus setRouterStatus: true]; 41 [routerStatus setRouterRanByUs: true]; 42 [routerStatus triggerEventWithEn:@"router_start" details:@"normal start"]; 43 } 39 44 sendUserNotification(APP_IDSTR, @"The I2P router is starting up."); 40 45 auto pid = [instance getPID]; 41 46 NSLog(@"Got pid: %d", pid); 42 47 43 auto swiftRouterStatus = [[RouterProcessStatus alloc] init]; 44 [swiftRouterStatus triggerEventWithEn:@"router_pid" details:[NSString stringWithFormat:@"%d", pid]]; 48 if (routerStatus != nil) [routerStatus triggerEventWithEn:@"router_pid" details:[NSString stringWithFormat:@"%d", pid]]; 45 49 46 50 return std::async(std::launch::async, [&pid]{ … … 55 59 [[SBridge sharedInstance] setCurrentRouterInstance:nil]; 56 60 57 auto swiftRouterStatus = [[RouterProcessStatus alloc] init]; 58 [swiftRouterStatus setRouterStatus: false]; 59 [swiftRouterStatus setRouterRanByUs: false]; 60 [swiftRouterStatus triggerEventWithEn:@"router_exception" details:errStr]; 61 if (routerStatus != nil) { 62 [routerStatus setRouterStatus: false]; 63 [routerStatus setRouterRanByUs: false]; 64 [routerStatus triggerEventWithEn:@"router_exception" details:errStr]; 65 } 61 66 62 67 return std::async(std::launch::async, [&]{ … … 101 106 std::string basePath([i2pRootPath UTF8String]); 102 107 103 // Get paths104 //NSBundle *launcherBundle = [NSBundle mainBundle];105 108 auto classPathStr = buildClassPathForObjC(basePath); 106 109 … … 138 141 auto nsBasePath = i2pRootPath; 139 142 NSArray* arrArguments = [NSArray arrayWithObjects:&argList[0] count:argList.size()]; 140 // We don't really know yet, but per now a workaround 141 [routerStatus setRouterStatus: true]; 143 142 144 NSLog(@"Trying to run command: %@", javaBinPath); 143 145 NSLog(@"With I2P Base dir: %@", i2pRootPath); 144 146 NSLog(@"And Arguments: %@", arrArguments); 145 startupRouter(nsJavaBin, arrArguments, nsBasePath );147 startupRouter(nsJavaBin, arrArguments, nsBasePath, routerStatus); 146 148 } catch (std::exception &err) { 147 149 auto errMsg = [NSString stringWithUTF8String:err.what()]; -
launchers/macosx/main.mm
r3b38f5a r7a72049 201 201 } 202 202 203 if (self.enableVerboseLogging) NSLog(@"processinfo %@", [[NSProcessInfo processInfo] arguments]);204 205 206 203 NSBundle *launcherBundle = [NSBundle mainBundle]; 207 204 … … 219 216 jarfile += [self.metaInfo.zipFile UTF8String]; 220 217 218 // Might be hard to read if you're not used to Objective-C 219 // But this is a "function call" that contains a "callback function" 220 [routerStatus listenForEventWithEventName:@"router_can_start" callbackActionFn:^(NSString* information) { 221 NSLog(@"Got signal, router can be started"); 222 [[SBridge sharedInstance] startupI2PRouter:self.metaInfo.i2pBase javaBinPath:self.metaInfo.javaBinary]; 223 }]; 224 225 // This will trigger the router start after an upgrade. 226 [routerStatus listenForEventWithEventName:@"router_must_upgrade" callbackActionFn:^(NSString* information) { 227 NSLog(@"Got signal, router must be upgraded"); 228 [self extractI2PBaseDir:^(BOOL success, NSError *error) { 229 sendUserNotification(@"I2P is done extracting", @"I2P is now installed and ready to run!"); 230 NSLog(@"Done extracting I2P"); 231 [routerStatus triggerEventWithEn:@"router_can_start" details:@"upgrade complete"]; 232 }]; 233 }]; 234 221 235 // Initialize the Swift environment (the UI components) 222 236 [self.swiftRuntime applicationDidFinishLaunching]; … … 227 241 // I2P is not extracted. 228 242 if (self.enableVerboseLogging) NSLog(@"I2P Directory don't exists!"); 229 230 // Might be hard to read if you're not used to Objective-C 231 // But this is a "function call" that contains a "callback function" 232 [self extractI2PBaseDir:^(BOOL success, NSError *error) { 233 sendUserNotification(@"I2P is done extracting", @"I2P is now installed and ready to run!"); 234 NSLog(@"Done extracting I2P"); 235 236 NSLog(@"Time to detect I2P version in install directory"); 237 [self.swiftRuntime findInstalledI2PVersion]; 238 if (shouldAutoStartRouter) { 239 [[SBridge sharedInstance] startupI2PRouter:self.metaInfo.i2pBase javaBinPath:self.metaInfo.javaBinary]; 240 [routerStatus setRouterRanByUs: true]; 241 } 242 }]; 243 243 [routerStatus triggerEventWithEn:@"router_must_upgrade" details:@"deploy needed"]; 244 244 } else { 245 245 // I2P was already found extracted 246 246 NSLog(@"Time to detect I2P version in install directory"); 247 247 [self.swiftRuntime findInstalledI2PVersion]; 248 249 if (shouldAutoStartRouter) {250 [[SBridge sharedInstance] startupI2PRouter:self.metaInfo.i2pBase javaBinPath:self.metaInfo.javaBinary];251 [routerStatus setRouterRanByUs: true];252 }253 248 } 254 249 255 250 #endif 256 251 } 257 258 259 252 260 253 /** -
launchers/macosx/src/main/java/net/i2p/launchers/BaseExtractor.java
r3b38f5a r7a72049 14 14 import java.util.zip.ZipEntry; 15 15 import java.util.zip.ZipFile; 16 import java.nio.file.*; 17 import java.nio.file.attribute.BasicFileAttributes; 18 19 import static java.nio.file.Files.*; 16 20 17 21 /** … … 25 29 public boolean printDebug = false; 26 30 27 public void runExtract(String zipFilename) { 28 String destinationPath = this.baseDirPath; 29 try(ZipFile file = new ZipFile(zipFilename)) { 30 FileSystem fileSystem = FileSystems.getDefault(); 31 Enumeration<? extends ZipEntry> entries = file.entries(); 32 33 try { 34 Files.createDirectory(fileSystem.getPath(destinationPath)); 35 } catch (IOException e) { 36 // It's OK to fail here. 31 public void unzip(final Path zipFile) { 32 try { 33 String destinationPath = this.baseDirPath; 34 final Path destDir = Files.createDirectories(FileSystems.getDefault().getPath(destinationPath)); 35 if (notExists(destDir)) { 36 createDirectories(destDir); 37 37 } 38 38 39 while (entries.hasMoreElements()) { 40 ZipEntry entry = entries.nextElement(); 41 if (printDebug) System.out.println("Found entry: "+entry.toString()); 42 if (entry.isDirectory()) { 43 if (printDebug) System.out.println("Creating Directory:" + destinationPath + "/" + entry.getName()); 44 Files.createDirectories(fileSystem.getPath(destinationPath + "/" + entry.getName())); 45 } else { 46 InputStream is = file.getInputStream(entry); 47 BufferedInputStream bis = new BufferedInputStream(is); 48 String uncompressedFileName = destinationPath + "/" + entry.getName(); 49 Path uncompressedFilePath = fileSystem.getPath(uncompressedFileName); 50 Files.createFile(uncompressedFilePath); 51 BufferedOutputStream fileOutput = new BufferedOutputStream(new FileOutputStream(uncompressedFileName)); 52 while (bis.available() > 0) fileOutput.write(bis.read()); 53 fileOutput.close(); 54 if (printDebug) System.out.println("Written :" + entry.getName()); 55 } 39 try (FileSystem zipFileSystem = FileSystems.newFileSystem(zipFile, null)) { 40 final Path root = zipFileSystem.getRootDirectories().iterator().next(); 41 42 walkFileTree(root, new SimpleFileVisitor<Path>() { 43 @Override 44 public FileVisitResult visitFile(Path file, 45 BasicFileAttributes attrs) throws IOException { 46 final Path destFile = Paths.get(destDir.toString(), file.toString()); 47 try { 48 copy(file, destFile, StandardCopyOption.REPLACE_EXISTING); 49 } catch (DirectoryNotEmptyException ignore) { 50 } 51 return FileVisitResult.CONTINUE; 52 } 53 54 @Override 55 public FileVisitResult preVisitDirectory(Path dir, 56 BasicFileAttributes attrs) throws IOException { 57 final Path dirToCreate = Paths.get(destDir.toString(), dir.toString()); 58 if (notExists(dirToCreate)) { 59 createDirectory(dirToCreate); 60 } 61 return FileVisitResult.CONTINUE; 62 } 63 }); 56 64 } 57 65 } catch (IOException e) { … … 73 81 be.printDebug = true; 74 82 } 75 be. runExtract(System.getProperty("i2p.base.zip"));83 be.unzip( FileSystems.getDefault().getPath(System.getProperty("i2p.base.zip")) ); 76 84 } 77 85 }
Note: See TracChangeset
for help on using the changeset viewer.