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
14 changed files with 513 additions and 641 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

@@ -469,24 +469,21 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Brewer/Brewer.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = "0.1.1-beta";
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"Brewer/Preview Content\"";
DEVELOPMENT_TEAM = 96S93Z7LTG;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = Brewer;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
INFOPLIST_KEY_LSUIElement = YES;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = "0.1.1-beta";
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = dev.cems.Brewer;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
@@ -500,24 +497,21 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Brewer/Brewer.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = "0.1.1-beta";
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"Brewer/Preview Content\"";
DEVELOPMENT_TEAM = 96S93Z7LTG;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = Brewer;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
INFOPLIST_KEY_LSUIElement = YES;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = "0.1.1-beta";
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = dev.cems.Brewer;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;

View File

@@ -2,6 +2,6 @@
<Workspace
version = "1.0">
<FileRef
location = "self:/Volumes/Data/Projects/Brewer/Brewer.xcodeproj">
location = "self:">
</FileRef>
</Workspace>

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 {
@@ -25,24 +22,11 @@ struct BrewerApp: App {
}
var body: some Scene {
WindowGroup {
EmptyView()
}
MenuBarExtra {
VStack(spacing: 0) {
ContentView()
.padding()
.padding(.bottom, 0)
Button {
NSApplication.shared.terminate(self)
} label: {
Label("Quit", systemImage: "x")
.symbolRenderingMode(.palette)
.symbolVariant(.circle)
.symbolVariant(.fill)
.foregroundStyle(.white, .red)
}
.frame(maxWidth: .infinity, alignment: .trailing)
.padding()
.padding(.top, 0)
}
ContentView().padding()
} label: {
if isUpToDate {
Label("Brewer", systemImage: "sparkle.magnifyingglass")
@@ -53,9 +37,6 @@ struct BrewerApp: App {
}
}
.menuBarExtraStyle(.window)
WindowGroup {
EmptyView()
}
}
}

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 {