forked from I2P_Developers/i2p.i2p
Mac OSX Launcher: Cancel stream that can cause high cpu load on router stop.
This commit is contained in:
@ -36,17 +36,23 @@ class LogViewerViewController : NSTabViewItem {
|
|||||||
|
|
||||||
let output = self.outputPipe?.fileHandleForReading.availableData
|
let output = self.outputPipe?.fileHandleForReading.availableData
|
||||||
let outputString = String(data: output!, encoding: String.Encoding.utf8) ?? ""
|
let outputString = String(data: output!, encoding: String.Encoding.utf8) ?? ""
|
||||||
|
let workTask = DispatchWorkItem {
|
||||||
DispatchQueue.main.async(execute: {
|
|
||||||
let previousOutput = self.textFieldView?.string ?? ""
|
let previousOutput = self.textFieldView?.string ?? ""
|
||||||
let nextOutput = previousOutput + "\n" + outputString
|
let nextOutput = previousOutput + "\n" + outputString
|
||||||
self.textFieldView?.string = nextOutput
|
self.textFieldView?.string = nextOutput
|
||||||
|
|
||||||
let range = NSRange(location:nextOutput.characters.count,length:0)
|
let range = NSRange(location:nextOutput.characters.count,length:0)
|
||||||
self.textFieldView?.scrollRangeToVisible(range)
|
self.textFieldView?.scrollRangeToVisible(range)
|
||||||
|
}
|
||||||
|
DispatchQueue.main.async(execute: workTask)
|
||||||
|
|
||||||
|
// When router stop, stop the stream as well. If not it will go wild and create high cpu load
|
||||||
|
RouterManager.shared().eventManager.listenTo(eventName: "router_stop", action: {
|
||||||
|
NSLog("Time to cancel stream!")
|
||||||
|
workTask.cancel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
self.outputPipe?.fileHandleForReading.waitForDataInBackgroundAndNotify()
|
self.outputPipe?.fileHandleForReading.waitForDataInBackgroundAndNotify()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user