Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added: basic bottle process management #68

Merged
merged 1 commit into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Harbor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
AB0D004C2A40B8900019D62F /* DXVKInstallView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB0D004B2A40B8900019D62F /* DXVKInstallView.swift */; };
AB0D004E2A40E3D30019D62F /* EnvironmentVarsEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB0D004D2A40E3D30019D62F /* EnvironmentVarsEditor.swift */; };
AB0F6E242A4AEDDA00F642C7 /* BottleIcon.icns in Resources */ = {isa = PBXBuildFile; fileRef = AB0F6E232A4AEDDA00F642C7 /* BottleIcon.icns */; };
AB157BBE2B41289D00757AE0 /* TaskControllerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB157BBD2B41289C00757AE0 /* TaskControllerView.swift */; };
AB19DA972A358FE400967784 /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = AB19DA962A358FE400967784 /* Localizable.xcstrings */; };
AB3BE5EE2A32248D00358BBC /* LaunchExtDropdown.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB3BE5ED2A32248D00358BBC /* LaunchExtDropdown.swift */; };
AB5CC6C02A308BBB00AEBB2B /* HarborApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB5CC6BF2A308BBB00AEBB2B /* HarborApp.swift */; };
Expand Down Expand Up @@ -55,6 +56,7 @@
AB0D004B2A40B8900019D62F /* DXVKInstallView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXVKInstallView.swift; sourceTree = "<group>"; };
AB0D004D2A40E3D30019D62F /* EnvironmentVarsEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnvironmentVarsEditor.swift; sourceTree = "<group>"; };
AB0F6E232A4AEDDA00F642C7 /* BottleIcon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = BottleIcon.icns; sourceTree = "<group>"; };
AB157BBD2B41289C00757AE0 /* TaskControllerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskControllerView.swift; sourceTree = "<group>"; };
AB19DA962A358FE400967784 /* Localizable.xcstrings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
AB3BE5ED2A32248D00358BBC /* LaunchExtDropdown.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchExtDropdown.swift; sourceTree = "<group>"; };
AB4707BF2A30C2C60019DC5F /* Harbor.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Harbor.entitlements; sourceTree = "<group>"; };
Expand Down Expand Up @@ -252,6 +254,7 @@
AB6254332A3CE30D002A6206 /* BottleCardListView.swift */,
AB0D004D2A40E3D30019D62F /* EnvironmentVarsEditor.swift */,
ABDA74582AD904E700802792 /* BottleDetailsCommonView.swift */,
AB157BBD2B41289C00757AE0 /* TaskControllerView.swift */,
);
path = BottleManagement;
sourceTree = "<group>";
Expand Down Expand Up @@ -395,6 +398,7 @@
AB7A81022A30D2FE00AA71A6 /* HarborUtils.swift in Sources */,
AB95D9FD2A5011C5003402D2 /* GPTKConfigView.swift in Sources */,
ABF5340C2A3F63BE0030677A /* BottleManagementCardView.swift in Sources */,
AB157BBE2B41289D00757AE0 /* TaskControllerView.swift in Sources */,
AB6652C42A3334E600F3FC5D /* XCLIUtils.swift in Sources */,
AB6254342A3CE30D002A6206 /* BottleCardListView.swift in Sources */,
AB6A967F2A31045A003A019E /* SetupView.swift in Sources */,
Expand Down
50 changes: 50 additions & 0 deletions Harbor/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,56 @@
}
}
},
"process.table.executable" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Process Executable"
}
}
}
},
"process.table.kill" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Stop Process"
}
}
}
},
"process.table.loading" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Getting Processes..."
}
}
}
},
"process.table.pid" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Process ID"
}
}
}
},
"process.table.refresh" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Refresh"
}
}
}
},
"setup.btn.installGPK" : {
"localizations" : {
"en" : {
Expand Down
9 changes: 9 additions & 0 deletions Harbor/Models/HarborBottle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ struct HarborBottle: Identifiable, Equatable, Codable {

task.environment = ["WINEPREFIX": path.path]

switch syncPrimitives {
case .none:
break
case .eSync:
task.environment?["WINEESYNC"] = "1"
case .mSync:
task.environment?["WINEMSYNC"] = "1"
}

do {
try task.run()
} catch {
Expand Down
6 changes: 6 additions & 0 deletions Harbor/UIElements/BottleManagement/BottleCardListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ struct BottleCardDetailedView: View {
}
}
.formStyle(.grouped)
Form {
Section {
TaskControllerView(bottle: $bottle)
}
}
.formStyle(.grouped)
Form {
Section {
Toggle("sheet.advConf.hudToggle", isOn: $bottle.enableHUD)
Expand Down
96 changes: 96 additions & 0 deletions Harbor/UIElements/BottleManagement/TaskControllerView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
// TaskControllerView.swift
// Harbor
//
// Created by Venti on 31/12/2023.
//

import SwiftUI

struct BottleProcess: Identifiable {
var id = UUID()
var pid: String
var procName: String
}

struct TaskControllerView: View {
@Binding var bottle: HarborBottle

@State private var processes = [BottleProcess]()
@State private var processSortOrder = [KeyPathComparator(\BottleProcess.pid)]
@State private var selectedProcess: BottleProcess.ID?

var body: some View {
ZStack {
if !processes.isEmpty {
VStack {
ScrollView {
Table(processes, selection: $selectedProcess, sortOrder: $processSortOrder) {
TableColumn("process.table.pid", value: \.pid)
TableColumn("process.table.executable", value: \.procName)
}
.frame(minHeight: 250)
}

HStack {
Spacer()
Button("process.table.refresh") {
Task.detached(priority: .userInitiated) {
processes.removeAll()
fetchProcesses()
}
}
Button("process.table.kill") {
Task.detached(priority: .userInitiated) {
killProcess()
}
}
}
.padding()
}
} else {
HStack(alignment: .center) {
Spacer()
VStack(alignment: .center) {
ProgressView()
.padding()
Text("process.table.loading")
}
Spacer()
}
}
}
.onAppear {
Task.detached(priority: .userInitiated) {
fetchProcesses()
}
}
}

func fetchProcesses() {
let taskList = bottle.directLaunchApplication("tasklist.exe", shouldWait: true)
var newProcessList = [BottleProcess]()

for line in taskList.components(separatedBy: "\n") {
let components = line.components(separatedBy: ",")
if components.count > 1 {
let pid = components[1]
let procName = components[0]
newProcessList.append(BottleProcess(pid: pid, procName: procName))
}
}

processes = newProcessList
}

func killProcess() {
if let thisProcess = processes.first(where: { $0.id == selectedProcess }) {
bottle.directLaunchApplication("taskkill.exe",
arguments: ["/PID", thisProcess.pid, "/F"],
shouldWait: true)
// Sleep a bit before refreshing the list
Thread.sleep(forTimeInterval: 2)
fetchProcesses()
}
}
}