[ADD] LocalConsole showing STDOUT and STDERR

This commit is contained in:
Fabian Thies
2023-02-13 18:56:34 +01:00
parent 2fffa6e122
commit b2f81bf7c6
5 changed files with 87 additions and 0 deletions

View File

@@ -58,6 +58,9 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
{
// Copy STDOUT and STDERR to the logging console
_ = OutputCapturer.shared
// Register default settings before doing anything else.
UserDefaults.registerDefaults()

View File

@@ -0,0 +1,49 @@
//
// OutputCapturer.swift
// SideStore
//
// Created by Fabian Thies on 12.02.23.
// Copyright © 2023 SideStore. All rights reserved.
//
import Foundation
import LocalConsole
class OutputCapturer {
public static let shared = OutputCapturer()
private let consoleManager = LCManager.shared
private var inputPipe = Pipe()
private var errorPipe = Pipe()
private init() {
// Setup pipe file handlers
self.inputPipe.fileHandleForReading.readabilityHandler = { [weak self] fileHandle in
self?.handle(data: fileHandle.availableData)
}
self.errorPipe.fileHandleForReading.readabilityHandler = { [weak self] fileHandle in
self?.handle(data: fileHandle.availableData, isError: true)
}
// Intercept STDOUT and STDERR
dup2(self.inputPipe.fileHandleForWriting.fileDescriptor, STDOUT_FILENO)
dup2(self.errorPipe.fileHandleForWriting.fileDescriptor, STDERR_FILENO)
}
deinit {
try? self.inputPipe.fileHandleForReading.close()
try? self.errorPipe.fileHandleForReading.close()
}
private func handle(data: Data, isError: Bool = false) {
guard let string = String(data: data, encoding: .utf8) else {
return
}
DispatchQueue.main.async {
self.consoleManager.print(string)
}
}
}

View File

@@ -9,6 +9,7 @@
import SwiftUI
import AsyncImage
import SFSafeSymbols
import LocalConsole
import AltStoreCore
import Intents
@@ -157,6 +158,10 @@ struct SettingsView: View {
RefreshAttemptsView()
}
SwiftUI.Button("Toggle Console") {
LCManager.shared.isVisible.toggle()
}
if MailComposeView.canSendMail {
SwiftUI.Button("Send Feedback") {
self.isShowingFeedbackMailView = true