Skip to content

Commit

Permalink
⚙️ Add a new settings screen
Browse files Browse the repository at this point in the history
⚙️ Add a new settings screen
  • Loading branch information
ThomasBernard03 authored May 12, 2024
2 parents c2fd2ab + d5d820e commit c7af68e
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 177 deletions.
24 changes: 16 additions & 8 deletions AndroidTools/AndroidTools.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
objects = {

/* Begin PBXBuildFile section */
8109D3602BF12575001A4B5E /* ApplicationSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8109D35F2BF12575001A4B5E /* ApplicationSettingsView.swift */; };
8109D3622BF1263C001A4B5E /* AppearanceSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8109D3612BF1263C001A4B5E /* AppearanceSettingsView.swift */; };
8109D3642BF128A8001A4B5E /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8109D3632BF128A8001A4B5E /* Constants.swift */; };
8109D3662BF141B0001A4B5E /* ApplicationSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8109D3652BF141B0001A4B5E /* ApplicationSettingsViewModel.swift */; };
810E8E1A2BE9196500ED561A /* GetConnectedDeviceListUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 810E8E192BE9196500ED561A /* GetConnectedDeviceListUseCase.swift */; };
810E8E1C2BE92EA800ED561A /* ListFilesUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 810E8E1B2BE92EA800ED561A /* ListFilesUseCase.swift */; };
810E8E1E2BE92EE600ED561A /* FileExplorerResultModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 810E8E1D2BE92EE600ED561A /* FileExplorerResultModel.swift */; };
810E8E202BE9311100ED561A /* FileRepositoryImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 810E8E1F2BE9311100ED561A /* FileRepositoryImpl.swift */; };
810E8E222BE9312B00ED561A /* FileRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 810E8E212BE9312B00ED561A /* FileRepository.swift */; };
811E65042BDE8C16003528B7 /* SideBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 811E65032BDE8C16003528B7 /* SideBarItem.swift */; };
811E65062BDEAAE2003528B7 /* SettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 811E65052BDEAAE2003528B7 /* SettingsViewModel.swift */; };
811E650A2BDEAEBC003528B7 /* LargeButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 811E65092BDEAEBC003528B7 /* LargeButtonStyle.swift */; };
812399C42BDC3C92004219C9 /* Toast.swift in Sources */ = {isa = PBXBuildFile; fileRef = 812399C32BDC3C92004219C9 /* Toast.swift */; };
812399C62BDC3CA9004219C9 /* ToastStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 812399C52BDC3CA9004219C9 /* ToastStyle.swift */; };
812399C82BDC3CC7004219C9 /* ToastView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 812399C72BDC3CC7004219C9 /* ToastView.swift */; };
Expand Down Expand Up @@ -72,14 +74,16 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
8109D35F2BF12575001A4B5E /* ApplicationSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationSettingsView.swift; sourceTree = "<group>"; };
8109D3612BF1263C001A4B5E /* AppearanceSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppearanceSettingsView.swift; sourceTree = "<group>"; };
8109D3632BF128A8001A4B5E /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
8109D3652BF141B0001A4B5E /* ApplicationSettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationSettingsViewModel.swift; sourceTree = "<group>"; };
810E8E192BE9196500ED561A /* GetConnectedDeviceListUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetConnectedDeviceListUseCase.swift; sourceTree = "<group>"; };
810E8E1B2BE92EA800ED561A /* ListFilesUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListFilesUseCase.swift; sourceTree = "<group>"; };
810E8E1D2BE92EE600ED561A /* FileExplorerResultModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileExplorerResultModel.swift; sourceTree = "<group>"; };
810E8E1F2BE9311100ED561A /* FileRepositoryImpl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileRepositoryImpl.swift; sourceTree = "<group>"; };
810E8E212BE9312B00ED561A /* FileRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileRepository.swift; sourceTree = "<group>"; };
811E65032BDE8C16003528B7 /* SideBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideBarItem.swift; sourceTree = "<group>"; };
811E65052BDEAAE2003528B7 /* SettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewModel.swift; sourceTree = "<group>"; };
811E65092BDEAEBC003528B7 /* LargeButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LargeButtonStyle.swift; sourceTree = "<group>"; };
812399C32BDC3C92004219C9 /* Toast.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toast.swift; sourceTree = "<group>"; };
812399C52BDC3CA9004219C9 /* ToastStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToastStyle.swift; sourceTree = "<group>"; };
812399C72BDC3CC7004219C9 /* ToastView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToastView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -155,6 +159,7 @@
children = (
81E6A7642BC5D7020034EBFB /* AdbHelper.swift */,
814319542BC6B3B100044934 /* Extensions */,
8109D3632BF128A8001A4B5E /* Constants.swift */,
);
path = Commons;
sourceTree = "<group>";
Expand Down Expand Up @@ -247,7 +252,9 @@
children = (
816A1D362BE8C7AF00E7DA71 /* Updater */,
81C3FEE02BD2E76000E18035 /* SettingsView.swift */,
811E65052BDEAAE2003528B7 /* SettingsViewModel.swift */,
8109D35F2BF12575001A4B5E /* ApplicationSettingsView.swift */,
8109D3612BF1263C001A4B5E /* AppearanceSettingsView.swift */,
8109D3652BF141B0001A4B5E /* ApplicationSettingsViewModel.swift */,
);
path = Settings;
sourceTree = "<group>";
Expand Down Expand Up @@ -355,7 +362,6 @@
81600C8E2BC98F65008D471C /* FileRow.swift */,
812DC7872BDC047E009B2E87 /* TerminalWindow.swift */,
811E65032BDE8C16003528B7 /* SideBarItem.swift */,
811E65092BDEAEBC003528B7 /* LargeButtonStyle.swift */,
);
path = Components;
sourceTree = "<group>";
Expand Down Expand Up @@ -476,11 +482,13 @@
81E6A7592BC5CD9D0034EBFB /* DeviceInformationView.swift in Sources */,
81B7900D2BEBA7E5008E7359 /* LogcatViewModel.swift in Sources */,
814319522BC6715B00044934 /* InstallApplicationViewModel.swift in Sources */,
8109D3662BF141B0001A4B5E /* ApplicationSettingsViewModel.swift in Sources */,
814319562BC6B3C000044934 /* UTTypeExtensions.swift in Sources */,
81E6A7512BC5CC260034EBFB /* MenuView.swift in Sources */,
816A1D452BE8D3A200E7DA71 /* CircleWavesAnimation.swift in Sources */,
81E6A75B2BC5CDC20034EBFB /* FileExplorerView.swift in Sources */,
81E9822F2BDD09E70004B154 /* GetDeviceInformationUseCase.swift in Sources */,
8109D3642BF128A8001A4B5E /* Constants.swift in Sources */,
81E6A7652BC5D7020034EBFB /* AdbHelper.swift in Sources */,
812DC7882BDC047E009B2E87 /* TerminalWindow.swift in Sources */,
81F41C612BEA995D005F1730 /* ImportFileUseCase.swift in Sources */,
Expand All @@ -492,10 +500,10 @@
81D04F5A2BCA4B3400B04FAB /* FolderItem.swift in Sources */,
81F41C5B2BEA4DF4005F1730 /* TableView.swift in Sources */,
816A1D402BE8CDE000E7DA71 /* InstallApplicationError.swift in Sources */,
8109D3602BF12575001A4B5E /* ApplicationSettingsView.swift in Sources */,
81E982392BDD3B480004B154 /* CheckForUpdateView.swift in Sources */,
810E8E202BE9311100ED561A /* FileRepositoryImpl.swift in Sources */,
81B790112BEBA9E8008E7359 /* LogEntryModel.swift in Sources */,
811E65062BDEAAE2003528B7 /* SettingsViewModel.swift in Sources */,
81C3FEE12BD2E76000E18035 /* SettingsView.swift in Sources */,
81E6A75D2BC5CDFF0034EBFB /* MenuViewModel.swift in Sources */,
81B7900F2BEBA7F3008E7359 /* LogcatView.swift in Sources */,
Expand All @@ -516,7 +524,6 @@
817EE85D2BC8247F00740D4A /* FileItem.swift in Sources */,
811E65042BDE8C16003528B7 /* SideBarItem.swift in Sources */,
816A1D492BE8F67000E7DA71 /* DeviceRepository.swift in Sources */,
811E650A2BDEAEBC003528B7 /* LargeButtonStyle.swift in Sources */,
81E982312BDD0F190004B154 /* RebootDeviceUseCase.swift in Sources */,
817EE8592BC81D4100740D4A /* FileExplorerViewModel.swift in Sources */,
81E982372BDD3A740004B154 /* CheckForUpdateViewModel.swift in Sources */,
Expand All @@ -531,6 +538,7 @@
81F41C5D2BEA7B3D005F1730 /* CreateFolderUseCase.swift in Sources */,
8164F8B02BDE40A70097422C /* UniversalFileDocument.swift in Sources */,
81E6A7682BC5D7200034EBFB /* DeviceListModel.swift in Sources */,
8109D3622BF1263C001A4B5E /* AppearanceSettingsView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
6 changes: 2 additions & 4 deletions AndroidTools/AndroidTools/AndroidToolsApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Sparkle
@main
struct AndroidToolsApp: App {

@AppStorage("mode") private var mode = "Automatic"
@AppStorage("mode") private var mode = Constants.appearanceModes.first!
private let updaterController : SPUStandardUpdaterController

init(){
Expand All @@ -20,9 +20,6 @@ struct AndroidToolsApp: App {

var body: some Scene {




WindowGroup {
SideBarView()
.frame(minWidth: 600, minHeight: 400)
Expand All @@ -36,6 +33,7 @@ struct AndroidToolsApp: App {

Settings {
SettingsView()
.frame(width: 500, height: 200)
.padding()
.preferredColorScheme(determineColorScheme(mode))
}
Expand Down
4 changes: 2 additions & 2 deletions AndroidTools/AndroidTools/Commons/AdbHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class AdbHelper {
}

func runAdbCommand(_ command: String) -> String {
print("Running command:\n adb \(command)")
print("Running command:\nadb \(command)")
let task = Process()
let pipe = Pipe()

Expand All @@ -61,7 +61,7 @@ class AdbHelper {

let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
print("Result:\n \(output)")
print("Result:\n\(output)")
return output
}

Expand Down
12 changes: 12 additions & 0 deletions AndroidTools/AndroidTools/Commons/Constants.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Constants.swift
// AndroidTools
//
// Created by Thomas Bernard on 12/05/2024.
//

import Foundation

class Constants {
static let appearanceModes : [String] = ["Automatic", "Dark", "Light"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ class GetAdbVersionUseCase {

func execute() -> String {
let result = adbHelper.runAdbCommand("version")
return result

let lines = result.split(separator: "\n")

// Find the line that starts with "Version"
if let versionLine = lines.first(where: { $0.starts(with: "Version") }) {

let version = versionLine
.replacingOccurrences(of: "Version ", with: "")
.split(separator: " ")
.first ?? ""
return String(version)
}

return ""
}
}

This file was deleted.

22 changes: 0 additions & 22 deletions AndroidTools/AndroidTools/Presentation/Menu/MenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,6 @@ struct SideBarView: View {
SideBarItem(label:"Files", systemImage: "folder")
}
.disabled(viewModel.devices.isEmpty)

NavigationLink(destination: LogcatView(deviceId: viewModel.selectedDevice?.id ?? "")) {
Label {
Text("Logcat")
} icon: {
Image("logcat")
.resizable()
.scaledToFit()
.frame(width: 16, height: 16)

}
.padding(.vertical, 4)

}
.disabled(viewModel.devices.isEmpty)

NavigationLink {
SettingsView()
} label: {
SideBarItem(label:"Settings", systemImage: "gearshape.circle")
}

}
.listStyle(SidebarListStyle())
.safeAreaInset(edge: .bottom, spacing: 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// AppearanceSettingsView.swift
// AndroidTools
//
// Created by Thomas Bernard on 12/05/2024.
//

import SwiftUI

struct AppearanceSettingsView: View {

@AppStorage("mode") private var mode = Constants.appearanceModes.first!
private let appIcons: [String] = ["AppIconDark", "AppIconLight", "AppIconAndroid"]
@AppStorage("appIconName") private var appIconName = "AppIconDark"

var body: some View {
Form {
Picker("Appearance", selection: $mode) {
ForEach(Constants.appearanceModes, id: \.self) { mode in
Text(mode)
if mode == Constants.appearanceModes.first {
Divider()
}

}
}

Text("Change application icon ")

HStack {
ForEach(appIcons, id: \.self) { name in
VStack {
Image(nsImage: NSImage(named: name)!)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 60, height: 60) // Highlight the selected icon
}

.background(appIconName == name ? Color.accentColor : Color.clear)
.cornerRadius(13)

.onTapGesture {
NSApplication.shared.applicationIconImage = NSImage(named: name)
appIconName = name // Update the selected icon
}
}

Spacer()
}

Spacer()
}
}
}

#Preview {
AppearanceSettingsView()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//
// ApplicationSettingsView.swift
// AndroidTools
//
// Created by Thomas Bernard on 12/05/2024.
//

import SwiftUI

struct ApplicationSettingsView: View {

@StateObject private var viewModel = ApplicationSettingsViewModel()

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


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 {
VStack(alignment:.center) {
HStack {
if !viewModel.adbVersion.isEmpty {
Image(systemName: "checkmark.circle.fill")
.foregroundColor(.green)
}
else {
Image(systemName: "xmark.circle.fill")
.foregroundColor(.red)
}

Text("ADB version \(viewModel.adbVersion)")
Spacer()
Button("Check ADB version"){
viewModel.getAdbVersion()
}
}

HStack {
TextField("", text:$adbPath)
.disabled(true)
.padding(.leading, -10)

Button("Change path"){
openFinderToSelectADB()
}
}



Spacer()

Divider()


HStack {
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
Text("Android Tools v\(appVersion)")

Spacer()

Button("Check for updates"){
viewModel.checkForUpdates()
}
}
.padding(.top, 5)
}
}
.onAppear {
viewModel.getAdbVersion()
}
}
}

#Preview {
ApplicationSettingsView()
}
Loading

0 comments on commit c7af68e

Please sign in to comment.