Skip to content

Commit 585df56

Browse files
committed
Support proService clean up
1 parent 8923f39 commit 585df56

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

Core/Sources/Service/ScheduledCleaner.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,9 @@ import Workspace
77
import XcodeInspector
88

99
public final class ScheduledCleaner {
10-
let workspacePool: WorkspacePool
11-
let guiController: GraphicalUserInterfaceController
10+
weak var service: Service?
1211

13-
init(
14-
workspacePool: WorkspacePool,
15-
guiController: GraphicalUserInterfaceController
16-
) {
17-
self.workspacePool = workspacePool
18-
self.guiController = guiController
19-
}
12+
init() {}
2013

2114
func start() {
2215
Task { @ServiceActor in
@@ -38,6 +31,8 @@ public final class ScheduledCleaner {
3831

3932
@ServiceActor
4033
func cleanUp() async {
34+
guard let service else { return }
35+
4136
let workspaceInfos = XcodeInspector.shared.xcodes.reduce(
4237
into: [
4338
XcodeAppInstanceInspector.WorkspaceIdentifier:
@@ -53,18 +48,18 @@ public final class ScheduledCleaner {
5348
}
5449
}
5550
}
56-
for (url, workspace) in workspacePool.workspaces {
51+
for (url, workspace) in service.workspacePool.workspaces {
5752
if workspace.isExpired, workspaceInfos[.url(url)] == nil {
5853
Logger.service.info("Remove idle workspace")
5954
_ = await Task { @MainActor in
60-
guiController.viewStore.send(
55+
service.guiController.viewStore.send(
6156
.promptToCodeGroup(.discardExpiredPromptToCode(documentURLs: Array(
6257
workspace.filespaces.keys
6358
)))
6459
)
6560
}.result
6661
await workspace.cleanUp(availableTabs: [])
67-
workspacePool.removeWorkspace(url: url)
62+
service.workspacePool.removeWorkspace(url: url)
6863
} else {
6964
let tabs = (workspaceInfos[.url(url)]?.tabs ?? [])
7065
.union(workspaceInfos[.unknown]?.tabs ?? [])
@@ -77,7 +72,7 @@ public final class ScheduledCleaner {
7772
) {
7873
Logger.service.info("Remove idle filespace")
7974
_ = await Task { @MainActor in
80-
guiController.viewStore.send(
75+
service.guiController.viewStore.send(
8176
.promptToCodeGroup(.discardExpiredPromptToCode(documentURLs: [url]))
8277
)
8378
}.result
@@ -87,11 +82,16 @@ public final class ScheduledCleaner {
8782
await workspace.cleanUp(availableTabs: tabs)
8883
}
8984
}
85+
86+
#if canImport(ProService)
87+
await service.proService.cleanUp(workspaceInfos: workspaceInfos)
88+
#endif
9089
}
9190

9291
@ServiceActor
9392
public func closeAllChildProcesses() async {
94-
for (_, workspace) in workspacePool.workspaces {
93+
guard let service else { return }
94+
for (_, workspace) in service.workspacePool.workspaces {
9595
await workspace.terminateSuggestionService()
9696
}
9797
}

Core/Sources/Service/Service.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public final class Service {
3838
private init() {
3939
@Dependency(\.workspacePool) var workspacePool
4040

41-
scheduledCleaner = .init(workspacePool: workspacePool, guiController: guiController)
41+
scheduledCleaner = .init()
4242
workspacePool.registerPlugin { SuggestionServiceWorkspacePlugin(workspace: $0) }
4343
self.workspacePool = workspacePool
4444
globalShortcutManager = .init(guiController: guiController)
@@ -52,6 +52,8 @@ public final class Service {
5252
ProService()
5353
}
5454
#endif
55+
56+
scheduledCleaner.service = self
5557
}
5658

5759
@MainActor

Pro

Submodule Pro updated from 970fa1b to b72cf6f

0 commit comments

Comments
 (0)