Skip to content

Commit

Permalink
fix: assert threads to prevent app freezing (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski authored May 30, 2024
1 parent 0dffe44 commit 3bc9af5
Show file tree
Hide file tree
Showing 4 changed files with 454 additions and 423 deletions.
4 changes: 4 additions & 0 deletions MiniSim.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
52B363EE2AEC10B3006F515C /* ParametersTableFormViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B363ED2AEC10B3006F515C /* ParametersTableFormViewModel.swift */; };
551B882A2B1385E900B8D325 /* Terminal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 551B88292B1385E900B8D325 /* Terminal.swift */; };
55CDB0782B1B6D24002418D7 /* TerminalApps.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55CDB0772B1B6D24002418D7 /* TerminalApps.swift */; };
760554A32C085BEA001607FE /* Thread+Asserts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 760554A22C085BEA001607FE /* Thread+Asserts.swift */; };
76059BF52AD4361C0008D38B /* SetupPreferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76059BF42AD4361C0008D38B /* SetupPreferences.swift */; };
76059BF72AD449DC0008D38B /* OnboardingHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76059BF62AD449DC0008D38B /* OnboardingHeader.swift */; };
76059BF92AD558C30008D38B /* SetupItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76059BF82AD558C30008D38B /* SetupItemView.swift */; };
Expand Down Expand Up @@ -104,6 +105,7 @@
52B363ED2AEC10B3006F515C /* ParametersTableFormViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParametersTableFormViewModel.swift; sourceTree = "<group>"; };
551B88292B1385E900B8D325 /* Terminal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Terminal.swift; sourceTree = "<group>"; };
55CDB0772B1B6D24002418D7 /* TerminalApps.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerminalApps.swift; sourceTree = "<group>"; };
760554A22C085BEA001607FE /* Thread+Asserts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Thread+Asserts.swift"; sourceTree = "<group>"; };
76059BF42AD4361C0008D38B /* SetupPreferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetupPreferences.swift; sourceTree = "<group>"; };
76059BF62AD449DC0008D38B /* OnboardingHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingHeader.swift; sourceTree = "<group>"; };
76059BF82AD558C30008D38B /* SetupItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetupItemView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -231,6 +233,7 @@
76E4451329D4403F00039025 /* NSNotificationName.swift */,
767F713129D574EF004159A6 /* UNUserNotificationCenter+showNotification.swift */,
4AFACC752AD73D7900EC369F /* NSMenuItem+ConvenienceInit.swift */,
760554A22C085BEA001607FE /* Thread+Asserts.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -564,6 +567,7 @@
76F2A912299033EA002D4EF6 /* DeviceError.swift in Sources */,
7631218E2A12B3BA00EE7F48 /* CustomCommandsViewModel.swift in Sources */,
4AFACC782AD74E9000EC369F /* DeviceListSection.swift in Sources */,
760554A32C085BEA001607FE /* Thread+Asserts.swift in Sources */,
7677999E29C26264009030F8 /* PermissionsView.swift in Sources */,
76630F2B29C718F500FB64F9 /* AndroidPathInput.swift in Sources */,
767F713229D574EF004159A6 /* UNUserNotificationCenter+showNotification.swift in Sources */,
Expand Down
11 changes: 11 additions & 0 deletions MiniSim/Extensions/Thread+Asserts.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Foundation

extension Thread {
static func assertMainThread() {
precondition(Thread.isMainThread, "Not on main thread")
}

static func assertBackgroundThread() {
precondition(!Thread.isMainThread, "On main thread")
}
}
4 changes: 2 additions & 2 deletions MiniSim/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22689"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication"/>
Expand Down
Loading

0 comments on commit 3bc9af5

Please sign in to comment.