Skip to content

Commit

Permalink
Can change adb path
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasBernard03 committed May 11, 2024
1 parent b418374 commit 4ea4110
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 13 deletions.
4 changes: 4 additions & 0 deletions AndroidTools/AndroidTools.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
817854852BC59F6500B5B2EE /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 817854842BC59F6500B5B2EE /* Preview Assets.xcassets */; };
817EE8592BC81D4100740D4A /* FileExplorerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 817EE8582BC81D4100740D4A /* FileExplorerViewModel.swift */; };
817EE85D2BC8247F00740D4A /* FileItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 817EE85C2BC8247F00740D4A /* FileItem.swift */; };
81A067C72BEEBA0100E83DEF /* GetAdbVersionUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A067C62BEEBA0100E83DEF /* GetAdbVersionUseCase.swift */; };
81B7900D2BEBA7E5008E7359 /* LogcatViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81B7900C2BEBA7E5008E7359 /* LogcatViewModel.swift */; };
81B7900F2BEBA7F3008E7359 /* LogcatView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81B7900E2BEBA7F3008E7359 /* LogcatView.swift */; };
81B790112BEBA9E8008E7359 /* LogEntryModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81B790102BEBA9E8008E7359 /* LogEntryModel.swift */; };
Expand Down Expand Up @@ -108,6 +109,7 @@
817854862BC59F6500B5B2EE /* AndroidTools.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = AndroidTools.entitlements; sourceTree = "<group>"; };
817EE8582BC81D4100740D4A /* FileExplorerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileExplorerViewModel.swift; sourceTree = "<group>"; };
817EE85C2BC8247F00740D4A /* FileItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileItem.swift; sourceTree = "<group>"; };
81A067C62BEEBA0100E83DEF /* GetAdbVersionUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetAdbVersionUseCase.swift; sourceTree = "<group>"; };
81B7900C2BEBA7E5008E7359 /* LogcatViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogcatViewModel.swift; sourceTree = "<group>"; };
81B7900E2BEBA7F3008E7359 /* LogcatView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogcatView.swift; sourceTree = "<group>"; };
81B790102BEBA9E8008E7359 /* LogEntryModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogEntryModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -389,6 +391,7 @@
81F41C5C2BEA7B3D005F1730 /* CreateFolderUseCase.swift */,
81F41C5E2BEA95FB005F1730 /* DeleteFileItemUseCase.swift */,
81F41C602BEA995D005F1730 /* ImportFileUseCase.swift */,
81A067C62BEEBA0100E83DEF /* GetAdbVersionUseCase.swift */,
);
path = UseCases;
sourceTree = "<group>";
Expand Down Expand Up @@ -485,6 +488,7 @@
81E9822D2BDD06600004B154 /* InstallApplicationUseCase.swift in Sources */,
816A1D3A2BE8CAA300E7DA71 /* ApplicationRepository.swift in Sources */,
812399C82BDC3CC7004219C9 /* ToastView.swift in Sources */,
81A067C72BEEBA0100E83DEF /* GetAdbVersionUseCase.swift in Sources */,
81D04F5A2BCA4B3400B04FAB /* FolderItem.swift in Sources */,
81F41C5B2BEA4DF4005F1730 /* TableView.swift in Sources */,
816A1D402BE8CDE000E7DA71 /* InstallApplicationError.swift in Sources */,
Expand Down
4 changes: 3 additions & 1 deletion AndroidTools/AndroidTools/Commons/AdbHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import Foundation

class AdbHelper {

let adbPath = "/usr/local/bin/adb"
var adbPath: String {
UserDefaults.standard.string(forKey: "adbPath") ?? "/usr/local/bin/adb"
}

func getDevices() -> [DeviceListModel] {
let command = "devices -l | awk 'NR>1 {print $1}'"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// GetAdbVersionUseCase.swift
// AndroidTools
//
// Created by Thomas Bernard on 10/05/2024.
//

import Foundation

class GetAdbVersionUseCase {
private let adbHelper : AdbHelper = AdbHelper()

func execute() -> String {
let result = adbHelper.runAdbCommand("version")
return result
}
}
38 changes: 33 additions & 5 deletions AndroidTools/AndroidTools/Presentation/Logcat/LogcatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,33 @@ struct LogcatView: View {
var body: some View {
VStack {
HStack {
Menu(viewModel.filterPackage ?? "All packages") {
Button("Display all packages") {
viewModel.filterPackage = nil
}

Divider()

ForEach(Array(viewModel.pidToPackageMap.keys), id: \.self) { pid in
// Obtenir le nom du package à partir du dictionnaire en utilisant le PID
if let packageName = viewModel.pidToPackageMap[pid] {
Button("\(packageName) (\(pid))") {
// Mise à jour du filtre pour afficher uniquement les logs de ce package
viewModel.filterPackage = packageName
}
}
}


}


TextField("Package", text: $viewModel.package)



}
.padding()

// Table(viewModel.logEntries){
// TableColumn("Date") { entry in
Expand All @@ -42,12 +67,15 @@ struct LogcatView: View {
// Text(entry.message)
// }
// }

List(viewModel.logEntries){
LogEntryItem(date: $0.datetime, processId: $0.processID, threadId: $0.threadID, tag: $0.tag, packageName: $0.packageName, level: $0.level, message: $0.message)
.listRowSeparator(.hidden)
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
}



List(viewModel.logEntries){
LogEntryItem(date: $0.datetime, processId: $0.processID, threadId: $0.threadID, tag: $0.tag, packageName: $0.packageName, level: $0.level, message: $0.message)
.listRowSeparator(.hidden)
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
}


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ class LogcatViewModel : ObservableObject {
@Published var logLevel: LogLevel? = nil

@Published var logEntries: [LogEntryModel] = []
@Published var filterPackage : String? = nil

private var buffer: String = ""
private var pidToPackageMap: [Int: String] = [:]
@Published var pidToPackageMap: [Int: String] = [:]

func getLogcat(deviceId: String) {
DispatchQueue.global(qos: .userInitiated).async { [self] in
Expand Down
49 changes: 44 additions & 5 deletions AndroidTools/AndroidTools/Presentation/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,40 @@ struct SettingsView: View {
case general, advanced
}

private let viewModel = SettingsViewModel()
@StateObject private var viewModel = SettingsViewModel()

private let appIcons: [String] = ["AppIconDark", "AppIconLight", "AppIconAndroid"]
private let modes : [String] = ["Automatic", "Dark", "Light"]

@AppStorage("mode") private var mode = "Automatic"
@AppStorage("appIconName") private var appIconName = "AppIconDark"

@AppStorage("adbPath") private var adbPath = "/usr/local/bin/adb"


// State to track the currently selected icon
@State private var selectedIcon: String = (NSApplication.shared.applicationIconImage.name() ?? "")


private func openFinderToSelectADB() {
let panel = NSOpenPanel()
panel.canChooseFiles = true
panel.canChooseDirectories = false
panel.allowsMultipleSelection = false
panel.directoryURL = URL(fileURLWithPath: adbPath)

panel.begin { response in
if response == .OK, let url = panel.url {
self.adbPath = url.path
viewModel.getAdbVersion()
}
}
}

var body: some View {
Form {
Group {



Section(header: Text("Apparence").padding(.horizontal)) {
Section(header: Text("Apparence")) {
VStack {
Picker("", selection: $mode) {
ForEach(modes, id: \.self) { mode in
Expand Down Expand Up @@ -70,6 +85,26 @@ struct SettingsView: View {
Text("Check for updates")

}.buttonStyle(LargeButtonStyle())


TextField("", text: $adbPath)
.disabled(true)



HStack {
Button("Change location"){
openFinderToSelectADB()
}

Button("Check installation") {
viewModel.getAdbVersion()
}
}

Text(viewModel.adbVersion)





Expand All @@ -78,11 +113,15 @@ struct SettingsView: View {

Spacer()
}
.onAppear {
viewModel.getAdbVersion()
}




}

}

struct SettingsView_Previews: PreviewProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
import Foundation
import Sparkle

class SettingsViewModel {
@Observable
class SettingsViewModel : ObservableObject {
let updaterController : SPUStandardUpdaterController
private let getAdbVersionUseCase : GetAdbVersionUseCase = GetAdbVersionUseCase()

var adbVersion : String = ""

init(){
updaterController = SPUStandardUpdaterController(startingUpdater: true, updaterDelegate: nil, userDriverDelegate: nil)
Expand All @@ -18,4 +22,9 @@ class SettingsViewModel {
func checkForUpdates(){
updaterController.updater.checkForUpdates()
}

func getAdbVersion(){
adbVersion = ""
adbVersion = getAdbVersionUseCase.execute()
}
}

0 comments on commit 4ea4110

Please sign in to comment.