Skip to content

Commit

Permalink
chore: clean up code (#21)
Browse files Browse the repository at this point in the history
* chore: clean up code
  • Loading branch information
clement2026 authored Sep 11, 2024
1 parent 87590eb commit 8fdce26
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: actions/checkout@v4
- name: Set up Xcode
run: |
sudo xcode-select -s "/Applications/Xcode_16_beta_5.app"
sudo xcode-select -s "/Applications/Xcode_16.1_beta.app"
xcodebuild -version
- name: Allow macro
run: |
Expand Down
4 changes: 2 additions & 2 deletions approf.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1087,8 +1087,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/pointfreeco/swift-composable-architecture";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.12.0;
kind = exactVersion;
version = 1.14.0;
};
};
EBD292B12C430D5800FFB285 /* XCRemoteSwiftPackageReference "KeyboardShortcuts" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/combine-schedulers",
"state" : {
"revision" : "487a4d151e795a5e076a7e7aedcd13c2ebff6c31",
"version" : "1.0.1"
"revision" : "9fa31f4403da54855f1e2aeaeff478f4f0e40b13",
"version" : "1.0.2"
}
},
{
Expand Down Expand Up @@ -42,17 +42,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-case-paths",
"state" : {
"revision" : "031704ba0634b45e02fe875b8ddddc7f30a07f49",
"version" : "1.5.3"
"revision" : "642e6aab8e03e5f992d9c83e38c5be98cfad5078",
"version" : "1.5.5"
}
},
{
"identity" : "swift-clocks",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-clocks",
"state" : {
"revision" : "eb64eacfed55635a771e3410f9c91de46cf5c6a0",
"version" : "1.0.3"
"revision" : "b9b24b69e2adda099a1fa381cda1eeec272d5b53",
"version" : "1.0.5"
}
},
{
Expand All @@ -69,8 +69,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-composable-architecture",
"state" : {
"revision" : "d65f3c1b9332255a40002905b6787f765585d7fb",
"version" : "1.12.0"
"revision" : "0d8980f5bcc5fe6941f1788758667ff2b8c10f03",
"version" : "1.14.0"
}
},
{
Expand All @@ -87,17 +87,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-custom-dump",
"state" : {
"revision" : "d237304f42af07f22563aa4cc2d7e2cfb25da82e",
"version" : "1.3.1"
"revision" : "82645ec760917961cfa08c9c0c7104a57a0fa4b1",
"version" : "1.3.3"
}
},
{
"identity" : "swift-dependencies",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-dependencies",
"state" : {
"revision" : "52018827ce21e482a36e3795bea2666b3898164c",
"version" : "1.3.4"
"revision" : "3ef38bb702a1a2f39c7e19fc0578403b8ee52b17",
"version" : "1.3.9"
}
},
{
Expand All @@ -110,30 +110,30 @@
}
},
{
"identity" : "swift-issue-reporting",
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-issue-reporting",
"location" : "https://github.com/apple/swift-log",
"state" : {
"revision" : "357ca1e5dd31f613a1d43320870ebc219386a495",
"version" : "1.2.2"
"revision" : "9cb486020ebf03bfa5b5df985387a14a98744537",
"version" : "1.6.1"
}
},
{
"identity" : "swift-log",
"identity" : "swift-navigation",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log",
"location" : "https://github.com/pointfreeco/swift-navigation",
"state" : {
"revision" : "9cb486020ebf03bfa5b5df985387a14a98744537",
"version" : "1.6.1"
"revision" : "e834b3760731160d7d448509ee6a1408c8582a6b",
"version" : "2.2.0"
}
},
{
"identity" : "swift-perception",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-perception",
"state" : {
"revision" : "2c75ce556a6fc106721b0dadc2c7327244ad3999",
"version" : "1.3.3"
"revision" : "bc67aa8e461351c97282c2419153757a446ae1c9",
"version" : "1.3.5"
}
},
{
Expand All @@ -155,12 +155,12 @@
}
},
{
"identity" : "swiftui-navigation",
"identity" : "xctest-dynamic-overlay",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swiftui-navigation",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "97f854044356ac082e7e698f39264cc035544d77",
"version" : "1.5.2"
"revision" : "bc2a151366f2cd0e347274544933bc2acb00c9fe",
"version" : "1.4.0"
}
}
],
Expand Down
6 changes: 3 additions & 3 deletions approf.xcodeproj/xcshareddata/xcschemes/approf.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Release"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
3 changes: 2 additions & 1 deletion approf/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct MacOS15App: App {
}
.defaultWindowPlacement { _, context in
let displayBounds = context.defaultDisplay.visibleRect
let size = CGSize(width: displayBounds.width * 0.8, height: displayBounds.height * 0.8)
let size = CGSize(width: displayBounds.width * 0.8, height: displayBounds.height)
return WindowPlacement(size: size)
}
.commands {
Expand All @@ -53,6 +53,7 @@ struct MacOS15App: App {
.toolbarBackgroundVisibility(.hidden, for: .windowToolbar)
.containerBackground(.ultraThinMaterial, for: .window)
.windowMinimizeBehavior(.disabled)
.windowResizeBehavior(.disabled)
.preferredColorScheme(asm.computedColorScheme)
}
.windowResizability(.contentSize)
Expand Down
1 change: 0 additions & 1 deletion approf/View/DetailFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ struct DetailFeature {
}
}

enum CancelID { case timer }
@Dependency(\.continuousClock) var clock

var body: some ReducerOf<Self> {
Expand Down
30 changes: 4 additions & 26 deletions approf/View/LaunchingFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct LaunchingFeature {
}
}

enum CancelID { case terminalReader, httpDetector, timer }
enum CancelID { case terminalReader, httpDetector }
@Dependency(\.continuousClock) var clock
@Dependency(\.date) var date

Expand Down Expand Up @@ -90,12 +90,7 @@ struct LaunchingFeature {
}
state.process = nil
}
return .merge(
.cancel(id: CancelID.timer),
.cancel(id: CancelID.httpDetector),
.cancel(id: CancelID.terminalReader),
.send(.delegate(.onTermimated))
)
return .send(.delegate(.onTermimated))
case let .readTerminal(stream):
state.readingTerminal.toggle()
if state.readingTerminal {
Expand Down Expand Up @@ -132,19 +127,13 @@ struct LaunchingFeature {
await send(.httpUpdated(httpResult))
}

// .cancel(id: CancelID.httpDetector) may fail to cancel this task. Limit retry times to 5
var tried = 0
for await _ in self.clock.timer(interval: .seconds(1)) {
let (ok, httpResult) = await detectHttpOk2(httpUrl: httpUrl, bodyShouldContain: "<h1><a href=\"./\">pprof</a></h1>")
if ok {
return await send(.httpReady)
} else {
await send(.httpUpdated(httpResult))
}
tried += 1
// if tried == 5 {
// return
// }
}
}
.cancellable(id: CancelID.httpDetector)
Expand All @@ -163,12 +152,7 @@ struct LaunchingFeature {
return .none
case .httpReady:
if let process = state.process, let port = state.portReady {
return .merge(
.cancel(id: CancelID.timer),
.cancel(id: CancelID.httpDetector),
.cancel(id: CancelID.terminalReader),
.send(.delegate(.onSuccess(process, port, state.goToWebOnSuccess)))
)
return .send(.delegate(.onSuccess(process, port, state.goToWebOnSuccess)))
} else {
return .send(.fail(.process("failed: let process = state.process, let port = state.portReady")))
}
Expand All @@ -178,7 +162,6 @@ struct LaunchingFeature {
try await self.clock.sleep(for: .seconds(timeout))
await send(.launchingTimeout(0))
}
.cancellable(id: CancelID.timer)
}

if state.portReady == nil || !state.httpReady || state.process?.isRunning ?? false {
Expand All @@ -187,12 +170,7 @@ struct LaunchingFeature {
return .none
case let .fail(cause):
state.process?.terminate()
return .merge(
.cancel(id: CancelID.timer),
.cancel(id: CancelID.httpDetector),
.cancel(id: CancelID.terminalReader),
.send(.delegate(.onFailed(cause)))
)
return .send(.delegate(.onFailed(cause)))
}
}
}
Expand Down

0 comments on commit 8fdce26

Please sign in to comment.