Skip to content
Open
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
12 changes: 6 additions & 6 deletions SwiftBar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
39224DEE25F4344600BABF21 /* PluginRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3962572A256967DC00341A19 /* PluginRepository.swift */; };
39224DEF25F4344600BABF21 /* Plugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39AF776E25461277001D76E5 /* Plugin.swift */; };
39224DF025F4344600BABF21 /* String+Escaped.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39B84A0A257C21D400FA012E /* String+Escaped.swift */; };
39224DF125F4344600BABF21 /* ImageVIew.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39E1549E2569A2D700287D8A /* ImageVIew.swift */; };
39224DF125F4344600BABF21 /* ImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39E1549E2569A2D700287D8A /* ImageView.swift */; };
39224DF225F4344600BABF21 /* URLTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39E1549B25699C8F00287D8A /* URLTextView.swift */; };
39224DF325F4344600BABF21 /* PluginDetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAD1BC9A25D22E9400B761E8 /* PluginDetailsView.swift */; };
39224DF425F4344600BABF21 /* AppDelegate+Menu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39224DCE25F3E6DE00BABF21 /* AppDelegate+Menu.swift */; };
Expand Down Expand Up @@ -100,7 +100,7 @@
39B84A1F257D436200FA012E /* RunScript.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39B84A1E257D436200FA012E /* RunScript.swift */; };
39B84A22257D63F700FA012E /* NSMutableAttributedString+SFSymbols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39B84A21257D63F700FA012E /* NSMutableAttributedString+SFSymbols.swift */; };
39E1549C25699C8F00287D8A /* URLTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39E1549B25699C8F00287D8A /* URLTextView.swift */; };
39E1549F2569A2D700287D8A /* ImageVIew.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39E1549E2569A2D700287D8A /* ImageVIew.swift */; };
39E1549F2569A2D700287D8A /* ImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39E1549E2569A2D700287D8A /* ImageView.swift */; };
ABF91B7D2589C7920020590A /* NSFont+Offset.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABF91B7C2589C7920020590A /* NSFont+Offset.swift */; };
FA06104625F0564400B08B6E /* PluginEntryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA06104525F0564400B08B6E /* PluginEntryView.swift */; };
FA136A542917EE0700A7D712 /* PluginUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA136A532917EE0700A7D712 /* PluginUtilities.swift */; };
Expand Down Expand Up @@ -213,7 +213,7 @@
39B84A1E257D436200FA012E /* RunScript.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunScript.swift; sourceTree = "<group>"; };
39B84A21257D63F700FA012E /* NSMutableAttributedString+SFSymbols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSMutableAttributedString+SFSymbols.swift"; sourceTree = "<group>"; };
39E1549B25699C8F00287D8A /* URLTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLTextView.swift; sourceTree = "<group>"; };
39E1549E2569A2D700287D8A /* ImageVIew.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageVIew.swift; sourceTree = "<group>"; };
39E1549E2569A2D700287D8A /* ImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageView.swift; sourceTree = "<group>"; };
ABF91B7C2589C7920020590A /* NSFont+Offset.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSFont+Offset.swift"; sourceTree = "<group>"; };
FA06104525F0564400B08B6E /* PluginEntryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PluginEntryView.swift; sourceTree = "<group>"; };
FA136A532917EE0700A7D712 /* PluginUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PluginUtilities.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -374,7 +374,7 @@
39641EA8254E0E0B00713DAF /* EnumPicker.swift */,
39641EAC254E0E3400713DAF /* ImageLoader.swift */,
39E1549B25699C8F00287D8A /* URLTextView.swift */,
39E1549E2569A2D700287D8A /* ImageVIew.swift */,
39E1549E2569A2D700287D8A /* ImageView.swift */,
FA8518CB258DAAAB008AD21C /* Binding+Extension.swift */,
FAD1BC9D25D22EEA00B761E8 /* AnimatableWindow.swift */,
);
Expand Down Expand Up @@ -799,7 +799,7 @@
3962572B256967DC00341A19 /* PluginRepository.swift in Sources */,
39AF776F25461277001D76E5 /* Plugin.swift in Sources */,
39B84A0B257C21D400FA012E /* String+Escaped.swift in Sources */,
39E1549F2569A2D700287D8A /* ImageVIew.swift in Sources */,
39E1549F2569A2D700287D8A /* ImageView.swift in Sources */,
3990DCDA2602BB32002CDCD5 /* DebugView.swift in Sources */,
39E1549C25699C8F00287D8A /* URLTextView.swift in Sources */,
FAD1BC9B25D22E9400B761E8 /* PluginDetailsView.swift in Sources */,
Expand Down Expand Up @@ -868,7 +868,7 @@
39224DEF25F4344600BABF21 /* Plugin.swift in Sources */,
39224DF025F4344600BABF21 /* String+Escaped.swift in Sources */,
FA3F26082E2AFE35007CF785 /* LaunchAtLogin.swift in Sources */,
39224DF125F4344600BABF21 /* ImageVIew.swift in Sources */,
39224DF125F4344600BABF21 /* ImageView.swift in Sources */,
3990DCDB2602BB32002CDCD5 /* DebugView.swift in Sources */,
39224DF225F4344600BABF21 /* URLTextView.swift in Sources */,
39224DF325F4344600BABF21 /* PluginDetailsView.swift in Sources */,
Expand Down
5 changes: 3 additions & 2 deletions SwiftBar/UI/Helpers/ImageLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import Combine
import Foundation

class ImageLoader: ObservableObject {
@Published var imageData = NSImage(named: "AppIcon")!.tiffRepresentation
@Published var imageData: Data?

init(url: URL) {
init(url: URL?) {
guard let url else { return }
let cache = URLCache.shared
let request = URLRequest(url: url, cachePolicy: URLRequest.CachePolicy.returnCacheDataElseLoad, timeoutInterval: 60.0)
if let data = cache.cachedResponse(for: request)?.data {
Expand Down
27 changes: 0 additions & 27 deletions SwiftBar/UI/Helpers/ImageVIew.swift

This file was deleted.

32 changes: 32 additions & 0 deletions SwiftBar/UI/Helpers/ImageView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import SwiftUI

struct ImageView: View {
@ObservedObject var imageLoader: ImageLoader
var image: NSImage? {
guard let data = imageLoader.imageData else { return nil }
return NSImage(data: data)
}

let width: CGFloat?
let height: CGFloat?
let fallbackView: AnyView

/// Create an view that shows an image loaded from the URL. The fallbackView will be shown instead when the URL is nil, can't load, or is still loading.
init(withURL url: URL?, width: CGFloat? = nil, height: CGFloat? = nil, fallbackView: AnyView = AnyView(EmptyView())) {
self.width = width
self.height = height
self.fallbackView = fallbackView
imageLoader = ImageLoader(url: url)
}

var body: some View {
if let image {
Image(nsImage: image)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: width, height: height)
} else {
fallbackView
}
}
}
44 changes: 23 additions & 21 deletions SwiftBar/UI/Plugin Repository/PluginEntryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ struct PluginEntryView: View {
}
}
HStack {
if let image = pluginEntry.image {
ImageView(withURL: image, width: 80, height: 60)
} else {
Image(nsImage: NSImage(named: "AppIcon")!)
.resizable()
.aspectRatio(contentMode: .fit)
.opacity(0.6)
.frame(width: 80, height: 60)
}
ImageView(
withURL: pluginEntry.image,
width: 80,
height: 60,
fallbackView: AnyView(
Image(nsImage: NSImage(named: "AppIcon")!)
.resizable()
.aspectRatio(contentMode: .fit)
.opacity(0.6)
.frame(width: 80, height: 60)
)
)

VStack(alignment: .leading) {
if !pluginEntry.desc.isEmpty {
Expand Down Expand Up @@ -107,8 +110,7 @@ struct PluginEntryModalView: View {

var body: some View {
ZStack {
RoundedRectangle(cornerRadius: 15)
.foregroundColor(Color(NSColor.controlColor))
Rectangle().foregroundColor(Color(NSColor.controlColor))
VStack(alignment: .leading) {
HStack {
VStack(alignment: .leading) {
Expand Down Expand Up @@ -143,16 +145,16 @@ struct PluginEntryModalView: View {
VStack(alignment: .leading) {
HStack {
Spacer()
if let image = pluginEntry.image {
ImageView(withURL: image, width: 120, height: 120)
} else {
Image(nsImage: NSImage(named: "AppIcon")!)
.resizable()
.aspectRatio(contentMode: .fit)
.opacity(0.6)
.frame(width: 80, height: 60)
}

ImageView(
withURL: pluginEntry.image,
fallbackView: AnyView(
Image(nsImage: NSImage(named: "AppIcon")!)
.resizable()
.aspectRatio(contentMode: .fit)
.opacity(0.6)
.frame(width: 80, height: 60)
)
)
Spacer()
}

Expand Down