mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-12-21 11:10:08 +01:00
✨ Add automatic crash reporting
This commit is contained in:
@@ -109,6 +109,11 @@
|
|||||||
03D846262EB6344E006EFE3C /* DomainListVC+Window.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D846242EB6344A006EFE3C /* DomainListVC+Window.swift */; };
|
03D846262EB6344E006EFE3C /* DomainListVC+Window.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D846242EB6344A006EFE3C /* DomainListVC+Window.swift */; };
|
||||||
03D846272EB6344E006EFE3C /* DomainListVC+Window.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D846242EB6344A006EFE3C /* DomainListVC+Window.swift */; };
|
03D846272EB6344E006EFE3C /* DomainListVC+Window.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D846242EB6344A006EFE3C /* DomainListVC+Window.swift */; };
|
||||||
03D846282EB6344E006EFE3C /* DomainListVC+Window.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D846242EB6344A006EFE3C /* DomainListVC+Window.swift */; };
|
03D846282EB6344E006EFE3C /* DomainListVC+Window.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D846242EB6344A006EFE3C /* DomainListVC+Window.swift */; };
|
||||||
|
03D8462B2EB6418F006EFE3C /* CrashReporter in Frameworks */ = {isa = PBXBuildFile; productRef = 03D8462A2EB6418F006EFE3C /* CrashReporter */; };
|
||||||
|
03D846322EB64E39006EFE3C /* CrashReporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D846312EB64E35006EFE3C /* CrashReporter.swift */; };
|
||||||
|
03D846332EB64E39006EFE3C /* CrashReporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D846312EB64E35006EFE3C /* CrashReporter.swift */; };
|
||||||
|
03D846342EB64E39006EFE3C /* CrashReporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D846312EB64E35006EFE3C /* CrashReporter.swift */; };
|
||||||
|
03D846352EB64E39006EFE3C /* CrashReporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D846312EB64E35006EFE3C /* CrashReporter.swift */; };
|
||||||
03DAD3A62EB3B08F003417BD /* DomainListVC+Certs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03DAD3A52EB3B08A003417BD /* DomainListVC+Certs.swift */; };
|
03DAD3A62EB3B08F003417BD /* DomainListVC+Certs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03DAD3A52EB3B08A003417BD /* DomainListVC+Certs.swift */; };
|
||||||
03DAD3A72EB3B08F003417BD /* DomainListVC+Certs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03DAD3A52EB3B08A003417BD /* DomainListVC+Certs.swift */; };
|
03DAD3A72EB3B08F003417BD /* DomainListVC+Certs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03DAD3A52EB3B08A003417BD /* DomainListVC+Certs.swift */; };
|
||||||
03DAD3A82EB3B08F003417BD /* DomainListVC+Certs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03DAD3A52EB3B08A003417BD /* DomainListVC+Certs.swift */; };
|
03DAD3A82EB3B08F003417BD /* DomainListVC+Certs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03DAD3A52EB3B08A003417BD /* DomainListVC+Certs.swift */; };
|
||||||
@@ -1027,6 +1032,7 @@
|
|||||||
03CC1FE42E3D220F0050FC18 /* InstallHomebrew.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstallHomebrew.swift; sourceTree = "<group>"; };
|
03CC1FE42E3D220F0050FC18 /* InstallHomebrew.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstallHomebrew.swift; sourceTree = "<group>"; };
|
||||||
03CC1FF32E3D230B0050FC18 /* ZshRunCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZshRunCommand.swift; sourceTree = "<group>"; };
|
03CC1FF32E3D230B0050FC18 /* ZshRunCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZshRunCommand.swift; sourceTree = "<group>"; };
|
||||||
03D846242EB6344A006EFE3C /* DomainListVC+Window.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DomainListVC+Window.swift"; sourceTree = "<group>"; };
|
03D846242EB6344A006EFE3C /* DomainListVC+Window.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DomainListVC+Window.swift"; sourceTree = "<group>"; };
|
||||||
|
03D846312EB64E35006EFE3C /* CrashReporter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CrashReporter.swift; sourceTree = "<group>"; };
|
||||||
03DAD3A52EB3B08A003417BD /* DomainListVC+Certs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DomainListVC+Certs.swift"; sourceTree = "<group>"; };
|
03DAD3A52EB3B08A003417BD /* DomainListVC+Certs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DomainListVC+Certs.swift"; sourceTree = "<group>"; };
|
||||||
03FE39E52E81682800B7B5AC /* AppIcon.icon */ = {isa = PBXFileReference; lastKnownFileType = folder.iconcomposer.icon; path = AppIcon.icon; sourceTree = "<group>"; };
|
03FE39E52E81682800B7B5AC /* AppIcon.icon */ = {isa = PBXFileReference; lastKnownFileType = folder.iconcomposer.icon; path = AppIcon.icon; sourceTree = "<group>"; };
|
||||||
03FE39E62E81682800B7B5AC /* AppIconEAP.icon */ = {isa = PBXFileReference; lastKnownFileType = folder.iconcomposer.icon; path = AppIconEAP.icon; sourceTree = "<group>"; };
|
03FE39E62E81682800B7B5AC /* AppIconEAP.icon */ = {isa = PBXFileReference; lastKnownFileType = folder.iconcomposer.icon; path = AppIconEAP.icon; sourceTree = "<group>"; };
|
||||||
@@ -1315,6 +1321,7 @@
|
|||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
C47014FF2C46D57C0069AAE7 /* NVAlert in Frameworks */,
|
C47014FF2C46D57C0069AAE7 /* NVAlert in Frameworks */,
|
||||||
|
03D8462B2EB6418F006EFE3C /* CrashReporter in Frameworks */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
@@ -2135,6 +2142,7 @@
|
|||||||
C4B97B74275CF08C003F3378 /* AppDelegate+MenuOutlets.swift */,
|
C4B97B74275CF08C003F3378 /* AppDelegate+MenuOutlets.swift */,
|
||||||
C436039F275E67610028EFC6 /* AppDelegate+Notifications.swift */,
|
C436039F275E67610028EFC6 /* AppDelegate+Notifications.swift */,
|
||||||
C415D3E72770F692005EF286 /* AppDelegate+InterApp.swift */,
|
C415D3E72770F692005EF286 /* AppDelegate+InterApp.swift */,
|
||||||
|
03D846312EB64E35006EFE3C /* CrashReporter.swift */,
|
||||||
C4811D2322D70A4700B5F6B3 /* App.swift */,
|
C4811D2322D70A4700B5F6B3 /* App.swift */,
|
||||||
C4B97B77275CF1B5003F3378 /* App+ActivationPolicy.swift */,
|
C4B97B77275CF1B5003F3378 /* App+ActivationPolicy.swift */,
|
||||||
C4B97B7A275CF20A003F3378 /* App+GlobalHotkey.swift */,
|
C4B97B7A275CF20A003F3378 /* App+GlobalHotkey.swift */,
|
||||||
@@ -2454,6 +2462,7 @@
|
|||||||
name = "PHP Monitor";
|
name = "PHP Monitor";
|
||||||
packageProductDependencies = (
|
packageProductDependencies = (
|
||||||
C47014FE2C46D57C0069AAE7 /* NVAlert */,
|
C47014FE2C46D57C0069AAE7 /* NVAlert */,
|
||||||
|
03D8462A2EB6418F006EFE3C /* CrashReporter */,
|
||||||
);
|
);
|
||||||
productName = phpmon;
|
productName = phpmon;
|
||||||
productReference = C41C1B3322B0097F00E7CF16 /* PHP Monitor.app */;
|
productReference = C41C1B3322B0097F00E7CF16 /* PHP Monitor.app */;
|
||||||
@@ -2571,6 +2580,7 @@
|
|||||||
packageReferences = (
|
packageReferences = (
|
||||||
C47014FA2C46D31B0069AAE7 /* XCRemoteSwiftPackageReference "NVAppUpdater" */,
|
C47014FA2C46D31B0069AAE7 /* XCRemoteSwiftPackageReference "NVAppUpdater" */,
|
||||||
C47014FD2C46D57C0069AAE7 /* XCRemoteSwiftPackageReference "NVAlert" */,
|
C47014FD2C46D57C0069AAE7 /* XCRemoteSwiftPackageReference "NVAlert" */,
|
||||||
|
03D846292EB6418F006EFE3C /* XCRemoteSwiftPackageReference "plcrashreporter" */,
|
||||||
);
|
);
|
||||||
productRefGroup = C41C1B3422B0097F00E7CF16 /* Products */;
|
productRefGroup = C41C1B3422B0097F00E7CF16 /* Products */;
|
||||||
projectDirPath = "";
|
projectDirPath = "";
|
||||||
@@ -2848,6 +2858,7 @@
|
|||||||
C417DC74277614690015E6EE /* Helpers.swift in Sources */,
|
C417DC74277614690015E6EE /* Helpers.swift in Sources */,
|
||||||
C415D3E82770F692005EF286 /* AppDelegate+InterApp.swift in Sources */,
|
C415D3E82770F692005EF286 /* AppDelegate+InterApp.swift in Sources */,
|
||||||
C41C1B3722B0097F00E7CF16 /* AppDelegate.swift in Sources */,
|
C41C1B3722B0097F00E7CF16 /* AppDelegate.swift in Sources */,
|
||||||
|
03D846352EB64E39006EFE3C /* CrashReporter.swift in Sources */,
|
||||||
C42759672627662800093CAE /* NSMenuExtension.swift in Sources */,
|
C42759672627662800093CAE /* NSMenuExtension.swift in Sources */,
|
||||||
C422DDAA28A2C49900CEAC97 /* PhpDoctorView.swift in Sources */,
|
C422DDAA28A2C49900CEAC97 /* PhpDoctorView.swift in Sources */,
|
||||||
C469E6FE294CF7B200A82AB2 /* FakeValetProxy.swift in Sources */,
|
C469E6FE294CF7B200A82AB2 /* FakeValetProxy.swift in Sources */,
|
||||||
@@ -2932,6 +2943,7 @@
|
|||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
03D846322EB64E39006EFE3C /* CrashReporter.swift in Sources */,
|
||||||
036C39122E5C8D42008DAEDF /* PackagistError.swift in Sources */,
|
036C39122E5C8D42008DAEDF /* PackagistError.swift in Sources */,
|
||||||
C471E82D28F9BB650021E251 /* AlertableError.swift in Sources */,
|
C471E82D28F9BB650021E251 /* AlertableError.swift in Sources */,
|
||||||
C471E82E28F9BB650021E251 /* Errors.swift in Sources */,
|
C471E82E28F9BB650021E251 /* Errors.swift in Sources */,
|
||||||
@@ -3336,6 +3348,7 @@
|
|||||||
C43931C829C4BD610069165B /* PhpVersionManagerView.swift in Sources */,
|
C43931C829C4BD610069165B /* PhpVersionManagerView.swift in Sources */,
|
||||||
C471E7F728F9BACB0021E251 /* PhpSwitcher.swift in Sources */,
|
C471E7F728F9BACB0021E251 /* PhpSwitcher.swift in Sources */,
|
||||||
0392CDEE2EB25371009176DA /* SecurePopoverView.swift in Sources */,
|
0392CDEE2EB25371009176DA /* SecurePopoverView.swift in Sources */,
|
||||||
|
03D846342EB64E39006EFE3C /* CrashReporter.swift in Sources */,
|
||||||
C4463FCF29804BCB007B93D5 /* RCFile.swift in Sources */,
|
C4463FCF29804BCB007B93D5 /* RCFile.swift in Sources */,
|
||||||
C471E82C28F9BB340021E251 /* ValetListable.swift in Sources */,
|
C471E82C28F9BB340021E251 /* ValetListable.swift in Sources */,
|
||||||
C471E82828F9BB310021E251 /* BrewDiagnostics.swift in Sources */,
|
C471E82828F9BB310021E251 /* BrewDiagnostics.swift in Sources */,
|
||||||
@@ -3417,6 +3430,7 @@
|
|||||||
C485707528BF454F00539B36 /* StatsView.swift in Sources */,
|
C485707528BF454F00539B36 /* StatsView.swift in Sources */,
|
||||||
C4F780CC25D80B75000DBC97 /* ActivePhpInstallation.swift in Sources */,
|
C4F780CC25D80B75000DBC97 /* ActivePhpInstallation.swift in Sources */,
|
||||||
54D9E0BB27E4F51E003B9AD9 /* ModifierFlagsExtension.swift in Sources */,
|
54D9E0BB27E4F51E003B9AD9 /* ModifierFlagsExtension.swift in Sources */,
|
||||||
|
03D846332EB64E39006EFE3C /* CrashReporter.swift in Sources */,
|
||||||
C485707328BF454300539B36 /* OnboardingView.swift in Sources */,
|
C485707328BF454300539B36 /* OnboardingView.swift in Sources */,
|
||||||
C485707728BF455300539B36 /* HeaderView.swift in Sources */,
|
C485707728BF455300539B36 /* HeaderView.swift in Sources */,
|
||||||
C4F780B125D80B4D000DBC97 /* PhpExtension.swift in Sources */,
|
C4F780B125D80B4D000DBC97 /* PhpExtension.swift in Sources */,
|
||||||
@@ -4542,6 +4556,14 @@
|
|||||||
/* End XCConfigurationList section */
|
/* End XCConfigurationList section */
|
||||||
|
|
||||||
/* Begin XCRemoteSwiftPackageReference section */
|
/* Begin XCRemoteSwiftPackageReference section */
|
||||||
|
03D846292EB6418F006EFE3C /* XCRemoteSwiftPackageReference "plcrashreporter" */ = {
|
||||||
|
isa = XCRemoteSwiftPackageReference;
|
||||||
|
repositoryURL = "https://github.com/microsoft/plcrashreporter.git";
|
||||||
|
requirement = {
|
||||||
|
kind = upToNextMajorVersion;
|
||||||
|
minimumVersion = 1.12.0;
|
||||||
|
};
|
||||||
|
};
|
||||||
C47014FA2C46D31B0069AAE7 /* XCRemoteSwiftPackageReference "NVAppUpdater" */ = {
|
C47014FA2C46D31B0069AAE7 /* XCRemoteSwiftPackageReference "NVAppUpdater" */ = {
|
||||||
isa = XCRemoteSwiftPackageReference;
|
isa = XCRemoteSwiftPackageReference;
|
||||||
repositoryURL = "https://github.com/nicoverbruggen/NVAppUpdater";
|
repositoryURL = "https://github.com/nicoverbruggen/NVAppUpdater";
|
||||||
@@ -4561,6 +4583,11 @@
|
|||||||
/* End XCRemoteSwiftPackageReference section */
|
/* End XCRemoteSwiftPackageReference section */
|
||||||
|
|
||||||
/* Begin XCSwiftPackageProductDependency section */
|
/* Begin XCSwiftPackageProductDependency section */
|
||||||
|
03D8462A2EB6418F006EFE3C /* CrashReporter */ = {
|
||||||
|
isa = XCSwiftPackageProductDependency;
|
||||||
|
package = 03D846292EB6418F006EFE3C /* XCRemoteSwiftPackageReference "plcrashreporter" */;
|
||||||
|
productName = CrashReporter;
|
||||||
|
};
|
||||||
C47014FB2C46D31B0069AAE7 /* NVAppUpdater */ = {
|
C47014FB2C46D31B0069AAE7 /* NVAppUpdater */ = {
|
||||||
isa = XCSwiftPackageProductDependency;
|
isa = XCSwiftPackageProductDependency;
|
||||||
package = C47014FA2C46D31B0069AAE7 /* XCRemoteSwiftPackageReference "NVAppUpdater" */;
|
package = C47014FA2C46D31B0069AAE7 /* XCRemoteSwiftPackageReference "NVAppUpdater" */;
|
||||||
|
|||||||
@@ -67,8 +67,8 @@
|
|||||||
</TestAction>
|
</TestAction>
|
||||||
<LaunchAction
|
<LaunchAction
|
||||||
buildConfiguration = "Debug.EA"
|
buildConfiguration = "Debug.EA"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = ""
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
|
||||||
launchStyle = "0"
|
launchStyle = "0"
|
||||||
useCustomWorkingDirectory = "NO"
|
useCustomWorkingDirectory = "NO"
|
||||||
ignoresPersistentStateOnLaunch = "NO"
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
|||||||
@@ -70,8 +70,8 @@
|
|||||||
</TestAction>
|
</TestAction>
|
||||||
<LaunchAction
|
<LaunchAction
|
||||||
buildConfiguration = "Debug"
|
buildConfiguration = "Debug"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = ""
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
|
||||||
launchStyle = "0"
|
launchStyle = "0"
|
||||||
useCustomWorkingDirectory = "NO"
|
useCustomWorkingDirectory = "NO"
|
||||||
ignoresPersistentStateOnLaunch = "NO"
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
|||||||
@@ -157,8 +157,10 @@ struct Constants {
|
|||||||
// API endpoints
|
// API endpoints
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
static let UpdateCheckEndpoint = url("https://api.phpmon.test/api/v1/update-check")
|
static let UpdateCheckEndpoint = url("https://api.phpmon.test/api/v1/update-check")
|
||||||
|
static let CrashReportingEndpoint = url("https://api.phpmon.test/api/v1/report-crash")
|
||||||
#else
|
#else
|
||||||
static let UpdateCheckEndpoint = url("https://api.phpmon.app/api/v1/update-check")
|
static let UpdateCheckEndpoint = url("https://api.phpmon.app/api/v1/update-check")
|
||||||
|
static let CrashReportingEndpoint = url("https://api.phpmon.app/api/v1/report-crash")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// GitHub URLs (do not alias these)
|
// GitHub URLs (do not alias these)
|
||||||
|
|||||||
@@ -87,6 +87,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
|
|||||||
Log.separator(as: .info)
|
Log.separator(as: .info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize the crash reporter
|
||||||
|
CrashReporter.initialize()
|
||||||
|
|
||||||
|
// Set up final singletons
|
||||||
self.valet = Valet.shared
|
self.valet = Valet.shared
|
||||||
self.brew = Brew.shared
|
self.brew = Brew.shared
|
||||||
super.init()
|
super.init()
|
||||||
|
|||||||
110
phpmon/Domain/App/CrashReporter.swift
Normal file
110
phpmon/Domain/App/CrashReporter.swift
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
//
|
||||||
|
// CrashReporter.swift
|
||||||
|
// PHP Monitor
|
||||||
|
//
|
||||||
|
// Created by Nico Verbruggen on 01/11/2025.
|
||||||
|
// Copyright © 2025 Nico Verbruggen. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import CrashReporter
|
||||||
|
|
||||||
|
class CrashReporter {
|
||||||
|
|
||||||
|
static func initialize() {
|
||||||
|
|
||||||
|
if CrashReporter.isDebuggerAttached() {
|
||||||
|
Log.err("[CrashReporter] The debugger is attached, won't start crash reporting.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let config = PLCrashReporterConfig(signalHandlerType: .mach, symbolicationStrategy: [])
|
||||||
|
|
||||||
|
guard let crashReporter = PLCrashReporter(configuration: config) else {
|
||||||
|
Log.err("[CrashReporter] Could not create an instance of PLCrashReporter.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
try crashReporter.enableAndReturnError()
|
||||||
|
} catch let error {
|
||||||
|
Log.err("[CrashReporter] Could not enable crash reporter: \(error). Crashes will not be reported.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if crashReporter.hasPendingCrashReport() {
|
||||||
|
CrashReporter.requestSendingCrashReport(crashReporter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static func requestSendingCrashReport(_ crashReporter: PLCrashReporter) {
|
||||||
|
do {
|
||||||
|
let data = try crashReporter.loadPendingCrashReportDataAndReturnError()
|
||||||
|
let report = try PLCrashReport(data: data)
|
||||||
|
|
||||||
|
if let text = PLCrashReportTextFormatter.stringValue(for: report, with: PLCrashReportTextFormatiOS) {
|
||||||
|
submitCrashReportToApi(text)
|
||||||
|
} else {
|
||||||
|
Log.err("[CrashReporter] Could not convert report to text.")
|
||||||
|
}
|
||||||
|
} catch let error {
|
||||||
|
Log.err("[CrashReporter] Failed to load and parse with error: \(error)")
|
||||||
|
}
|
||||||
|
|
||||||
|
crashReporter.purgePendingCrashReport()
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func submitCrashReportToApi(_ text: String) {
|
||||||
|
let timeout = TimeInterval.seconds(10)
|
||||||
|
|
||||||
|
var request = URLRequest(url: Constants.Urls.CrashReportingEndpoint)
|
||||||
|
request.httpMethod = "POST"
|
||||||
|
request.setValue("text/crash", forHTTPHeaderField: "Content-Type")
|
||||||
|
request.setValue("phpmon-crashrep/1.0", forHTTPHeaderField: "User-Agent")
|
||||||
|
request.httpBody = text.data(using: .utf8)
|
||||||
|
|
||||||
|
// Send the request synchronously, we want the report to be sent before anything else
|
||||||
|
let config = URLSessionConfiguration.default
|
||||||
|
config.timeoutIntervalForRequest = timeout
|
||||||
|
|
||||||
|
let session = URLSession(configuration: config)
|
||||||
|
let semaphore = DispatchSemaphore(value: 0)
|
||||||
|
|
||||||
|
let task = session.dataTask(with: request) { _, response, error in
|
||||||
|
defer { semaphore.signal() }
|
||||||
|
|
||||||
|
if let error = error {
|
||||||
|
Log.err("[CrashReporter] Failed to send crash report: \(error.localizedDescription)")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if let httpResponse = response as? HTTPURLResponse {
|
||||||
|
switch httpResponse.statusCode {
|
||||||
|
case 200...299:
|
||||||
|
Log.info("[CrashReporter] Crash report sent successfully!")
|
||||||
|
case 400...499:
|
||||||
|
Log.err("[CrashReporter] Client error when sending crash report: \(httpResponse.statusCode)")
|
||||||
|
case 500...599:
|
||||||
|
Log.err("[CrashReporter] Server error when sending crash report: \(httpResponse.statusCode)")
|
||||||
|
default:
|
||||||
|
Log.err("[CrashReporter] Unexpected response code: \(httpResponse.statusCode)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task.resume()
|
||||||
|
_ = semaphore.wait(timeout: .now() + timeout)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Determines whether a debugger is attached.
|
||||||
|
*/
|
||||||
|
private static func isDebuggerAttached() -> Bool {
|
||||||
|
var info = kinfo_proc()
|
||||||
|
var mib: [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
|
||||||
|
var size = MemoryLayout<kinfo_proc>.stride
|
||||||
|
|
||||||
|
let result = sysctl(&mib, UInt32(mib.count), &info, &size, nil, 0)
|
||||||
|
|
||||||
|
return result == 0 && (info.kp_proc.p_flag & P_TRACED) != 0
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user