2 Commits

Author SHA1 Message Date
cdricms
c675a98309 Better reactivity and functionality 2024-07-09 20:29:20 +02:00
cdricms
bd9c351b7c The app is starting to look good 2024-07-09 15:00:09 +02:00
12 changed files with 508 additions and 614 deletions

View File

@@ -1,69 +0,0 @@
{
"fileScopedDeclarationPrivacy" : {
"accessLevel" : "private"
},
"indentation" : {
"tabs" : 1
},
"indentConditionalCompilationBlocks" : true,
"indentSwitchCaseLabels" : false,
"lineBreakAroundMultilineExpressionChainComponents" : false,
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : false,
"lineBreakBeforeEachGenericRequirement" : false,
"lineLength" : 80,
"maximumBlankLines" : 1,
"multiElementCollectionTrailingCommas" : true,
"noAssignmentInExpressions" : {
"allowedFunctions" : [
"XCTAssertNoThrow"
]
},
"prioritizeKeepingFunctionOutputTogether" : false,
"respectsExistingLineBreaks" : true,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : false,
"AlwaysUseLiteralForEmptyCollectionInit" : false,
"AlwaysUseLowerCamelCase" : true,
"AmbiguousTrailingClosureOverload" : true,
"BeginDocumentationCommentWithOneLineSummary" : false,
"DoNotUseSemicolons" : true,
"DontRepeatTypeInStaticProperties" : true,
"FileScopedDeclarationPrivacy" : true,
"FullyIndirectEnum" : true,
"GroupNumericLiterals" : true,
"IdentifiersMustBeASCII" : true,
"NeverForceUnwrap" : false,
"NeverUseForceTry" : false,
"NeverUseImplicitlyUnwrappedOptionals" : false,
"NoAccessLevelOnExtensionDeclaration" : true,
"NoAssignmentInExpressions" : true,
"NoBlockComments" : true,
"NoCasesWithOnlyFallthrough" : true,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : true,
"NoLeadingUnderscores" : false,
"NoParensAroundConditions" : true,
"NoPlaygroundLiterals" : true,
"NoVoidReturnOnFunctionSignature" : true,
"OmitExplicitReturns" : false,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : true,
"OrderedImports" : true,
"ReplaceForEachWithForLoop" : true,
"ReturnVoidInsteadOfEmptyTuple" : true,
"TypeNamesShouldBeCapitalized" : true,
"UseEarlyExits" : false,
"UseLetInEveryBoundCaseVariable" : true,
"UseShorthandTypeNames" : true,
"UseSingleLinePropertyGetter" : true,
"UseSynthesizedInitializer" : true,
"UseTripleSlashForDocumentationComments" : true,
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : false
},
"spacesAroundRangeFormationOperators" : false,
"tabWidth" : 4,
"version" : 1
}

View File

@@ -12,11 +12,8 @@ struct BrewerApp: App {
@AppStorage("isUpToDate") var isUpToDate: Bool = true
init() {
do {
let res = try shell(
"/opt/homebrew/bin/brew outdated --greedy-latest -g | wc -l")
if let number = Int(
res.trimmingCharacters(in: .whitespacesAndNewlines)), number > 0
{
let res = try shell("/opt/homebrew/bin/brew outdated --greedy-latest -g | wc -l")
if let number = Int(res.trimmingCharacters(in: .whitespacesAndNewlines)), number > 0 {
isUpToDate = false
}
} catch {

View File

@@ -29,8 +29,7 @@ struct CaskDetailView: View {
}
if cask.installed != nil {
ToolbarItem(placement: .primaryAction) {
UninstallButton(
name: cask.fullToken, brewListing: brewListing)
UninstallButton(name: cask.fullToken, brewListing: brewListing)
}
}
}

View File

@@ -19,8 +19,7 @@ struct InstalledView: View {
Section {
ForEach(data.casks, id: \.fullToken) { cask in
NavigationLink {
CaskDetailView(
cask: cask, brewListing: brew)
CaskDetailView(cask: cask, brewListing: brew)
} label: {
HStack {
Text(cask.name.first ?? cask.fullToken)
@@ -29,23 +28,16 @@ struct InstalledView: View {
Button {
} label: {
Label(
"Update",
systemImage:
"arrow.counterclockwise.circle.fill"
)
Label("Update", systemImage: "arrow.counterclockwise.circle.fill")
.symbolRenderingMode(.palette)
.foregroundStyle(
.white, .orange)
.foregroundStyle(.white, .orange)
}
} else {
Text(cask.version)
}
}
.contextMenu {
UninstallButton(
name: cask.fullToken,
brewListing: brew)
UninstallButton(name: cask.fullToken, brewListing: brew)
}
}
}
@@ -68,11 +60,7 @@ struct InstalledView: View {
Button {
} label: {
Label(
"Update",
systemImage:
"arrow.counterclockwise.circle.fill"
)
Label("Update", systemImage: "arrow.counterclockwise.circle.fill")
.symbolRenderingMode(.palette)
.foregroundStyle(.white, .orange)
}
@@ -81,9 +69,7 @@ struct InstalledView: View {
}
}
.contextMenu {
UninstallButton(
name: formulae.fullName,
brewListing: brew)
UninstallButton(name: formulae.fullName, brewListing: brew)
}
}
} header: {
@@ -96,18 +82,13 @@ struct InstalledView: View {
}
}
.listStyle(.inset(alternatesRowBackgrounds: true))
let areOutdated =
data.casks.map(\.outdated).count
+ data.formulae.map(\.outdated).count
let _ = UserDefaults.standard.set(
!(areOutdated > 0), forKey: "isUpToDate")
let areOutdated = data.casks.map(\.outdated).count + data.formulae.map(\.outdated).count
let _ = UserDefaults.standard.set(!(areOutdated > 0), forKey: "isUpToDate")
if areOutdated > 0 {
Button {
} label: {
Label(
"Update all",
systemImage: "arrow.counterclockwise.circle.fill")
Label("Update all", systemImage: "arrow.counterclockwise.circle.fill")
}
.buttonStyle(.borderedProminent)
.tint(.orange)

View File

@@ -111,11 +111,9 @@ class Homebrew {
self.data = nil
Task { [weak self] in
do {
let res = try shell(
"/opt/homebrew/bin/brew info --json=v2 \(query)")
let res = try shell("/opt/homebrew/bin/brew info --json=v2 \(query)")
if let data = res.data(using: .utf8) {
let output = try JSONDecoder().decode(
InfoResponse.self, from: data)
let output = try JSONDecoder().decode(InfoResponse.self, from: data)
self?.data = output
}
} catch {
@@ -131,11 +129,9 @@ class Homebrew {
self.errorMessage = nil
Task { [weak self] in
do {
let res = try shell(
"/opt/homebrew/bin/brew info --json=v2 --installed")
let res = try shell("/opt/homebrew/bin/brew info --json=v2 --installed")
if let data = res.data(using: .utf8) {
let output = try JSONDecoder().decode(
InfoResponse.self, from: data)
let output = try JSONDecoder().decode(InfoResponse.self, from: data)
self?.data = output
}
} catch {
@@ -152,9 +148,7 @@ class Homebrew {
self.data = nil
let task = Task { [weak self] in
do {
let res = try shell(
"/opt/homebrew/bin/brew list -1 \(name) >/dev/null 2>&1; echo $?"
)
let res = try shell("/opt/homebrew/bin/brew list -1 \(name) >/dev/null 2>&1; echo $?")
.trimmingCharacters(in: .whitespacesAndNewlines)
self?.isLoading = false
return res == "0"
@@ -178,9 +172,7 @@ class Homebrew {
self.data = nil
let task = Task { [weak self] in
do {
try shell(
"/opt/homebrew/bin/brew install \(isCask ? "--cask" : "") \(fullToken)"
)
try shell("/opt/homebrew/bin/brew install \(isCask ? "--cask" : "") \(fullToken)")
} catch {
self?.errorMessage = error.localizedDescription
}
@@ -202,9 +194,7 @@ class Homebrew {
let task = Task { [weak self] in
do {
let res =
try shell(
"/opt/homebrew/bin/brew uninstall \(fullToken); echo $?"
)
try shell("/opt/homebrew/bin/brew uninstall \(fullToken); echo $?")
.trimmingCharacters(in: .whitespacesAndNewlines)
} catch {
self?.errorMessage = error.localizedDescription

View File

@@ -30,14 +30,11 @@ struct SearchView: View {
Text(cask.fullToken)
Spacer()
if cask.installed != nil {
Image(
systemName: "checkmark.circle.fill"
)
Image(systemName: "checkmark.circle.fill")
.symbolRenderingMode(.palette)
.foregroundStyle(.white, .green)
} else {
DownloadButton(
name: cask.fullToken, isCask: true)
DownloadButton(name: cask.fullToken, isCask: true)
}
}
}

View File

@@ -6,7 +6,6 @@
//
import XCTest
@testable import Brewer
final class BrewerTests: XCTestCase {