source: launchers/macosx/I2PLauncher/userinterface/LogViewController.swift @ 3b38f5a

Last change on this file since 3b38f5a was 3b38f5a, checked in by meeh <meeh@…>, 2 years ago

Mac OS X Launcher:

  • In general bugfixes
  • Introduced event manager for better control flow
  • Splitted RouterStatusView? to own file
  • Added shell script to setup and produce dmg file
  • Property mode set to 100644
File size: 1.6 KB
Line 
1//
2//  LogViewController.swift
3//  I2PLauncher
4//
5//  Created by Mikal Villa on 18/09/2018.
6//  Copyright © 2018 The I2P Project. All rights reserved.
7//
8
9import Foundation
10import AppKit
11
12class LogViewerViewController : NSTabViewItem {
13 
14  @IBOutlet var scrollView: NSScrollView?
15  @IBOutlet var textFieldView: NSTextView?
16 
17  private var outputPipe : Pipe?
18 
19  override init(identifier: Any?) {
20    super.init(identifier: identifier)
21    self.captureStandardOutputAndRouteToTextView()
22  }
23 
24  required init?(coder aDecoder: NSCoder) {
25    super.init(coder: aDecoder)
26    self.captureStandardOutputAndRouteToTextView()
27  }
28 
29 
30  func captureStandardOutputAndRouteToTextView() {
31    outputPipe = RouterManager.shared().getRouterTask()?.processPipe
32    outputPipe?.fileHandleForReading.waitForDataInBackgroundAndNotify()
33   
34    NotificationCenter.default.addObserver(forName: NSNotification.Name.NSFileHandleDataAvailable, object: outputPipe?.fileHandleForReading , queue: nil) {
35      notification in
36
37      let output = self.outputPipe?.fileHandleForReading.availableData
38      let outputString = String(data: output!, encoding: String.Encoding.utf8) ?? ""
39     
40      DispatchQueue.main.async(execute: {
41        let previousOutput = self.textFieldView?.string ?? ""
42        let nextOutput = previousOutput + "\n" + outputString
43        self.textFieldView?.string = nextOutput
44       
45        let range = NSRange(location:nextOutput.characters.count,length:0)
46        self.textFieldView?.scrollRangeToVisible(range)
47       
48      })
49     
50      self.outputPipe?.fileHandleForReading.waitForDataInBackgroundAndNotify()
51    }
52   
53  }
54}
55
56
Note: See TracBrowser for help on using the repository browser.