-
-
Notifications
You must be signed in to change notification settings - Fork 591
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #912
- Loading branch information
Showing
35 changed files
with
196 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import SwiftUI | ||
|
||
class ApplicationImage { | ||
fileprivate static let fallbackImage = NSImage( | ||
systemSymbolName: "questionmark.app.dashed", | ||
accessibilityDescription: nil | ||
)! | ||
private static let retryInterval: TimeInterval = 60 * 60 | ||
|
||
let bundleIdentifier: String? | ||
private var image: NSImage? | ||
private var lastChecked: Date? | ||
private var eventSource: (any DispatchSourceFileSystemObject)? | ||
|
||
init(bundleIdentifier: String?, image: NSImage? = nil) { | ||
self.bundleIdentifier = bundleIdentifier | ||
self.image = image | ||
} | ||
|
||
var nsImage: NSImage { | ||
guard let bundleIdentifier else { | ||
return Self.fallbackImage | ||
} | ||
|
||
if let image { | ||
return image | ||
} | ||
|
||
// The image has been queried before but since the application has been deleted. | ||
// Check from time to time if the application has returned. | ||
if let lastChecked, | ||
Date().timeIntervalSince(lastChecked) < Self.retryInterval { | ||
return Self.fallbackImage | ||
} | ||
lastChecked = .now | ||
|
||
if let appURL = NSWorkspace.shared.urlForApplication( | ||
withBundleIdentifier: bundleIdentifier | ||
) { | ||
let img = NSWorkspace.shared.icon(forFile: appURL.path) | ||
image = img | ||
|
||
let descriptor = open(appURL.path, O_EVTONLY) | ||
if descriptor == -1 { | ||
let errorCode = errno | ||
print("Error code: \(errorCode)") | ||
print("Error message: \(String(cString: strerror(errorCode)))") | ||
} else if descriptor > 0 { | ||
let source = DispatchSource.makeFileSystemObjectSource( | ||
fileDescriptor: descriptor, | ||
eventMask: [.write, .delete], | ||
queue: DispatchQueue.global() | ||
) | ||
eventSource = source | ||
source.setEventHandler { | ||
DispatchQueue.main.async { | ||
let event = source.data | ||
if event.contains(.delete) { | ||
// File was deleted. | ||
print("Deleted", appURL.path) | ||
source.cancel() | ||
self.image = nil | ||
} else if event.contains(.write) { | ||
// File was modified. Fetch new icon | ||
print("Modified", appURL.path) | ||
self.image = NSWorkspace.shared.icon(forFile: appURL.path) | ||
} | ||
} | ||
} | ||
source.setCancelHandler { | ||
close(descriptor) | ||
} | ||
source.resume() | ||
} | ||
|
||
return img | ||
} | ||
|
||
return Self.fallbackImage | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class ApplicationImageCache { | ||
static let shared = ApplicationImageCache() | ||
|
||
private let universalClipboardIdentifier: String = | ||
"com.apple.finder.Open-iCloudDrive" | ||
private let fallback = ApplicationImage(bundleIdentifier: nil) | ||
private var cache: [String: ApplicationImage] = [:] | ||
|
||
func getImage(item: HistoryItem) -> ApplicationImage { | ||
guard let bundleIdentifier = bundleIdentifier(for: item) else { | ||
return fallback | ||
} | ||
|
||
if let image = cache[bundleIdentifier] { | ||
return image | ||
} | ||
|
||
let image = ApplicationImage(bundleIdentifier: bundleIdentifier) | ||
cache[bundleIdentifier] = image | ||
|
||
return image | ||
} | ||
|
||
private func bundleIdentifier(for item: HistoryItem) -> String? { | ||
if item.universalClipboard { | ||
return universalClipboardIdentifier | ||
} | ||
|
||
if let bundleIdentifier = item.application { | ||
return bundleIdentifier | ||
} | ||
|
||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,35 @@ | ||
"Title" = "Išvaizda"; | ||
"PopupAt" = "Iššokančio lango vieta:"; | ||
"PopupAtCursor" = "Pelės žymeklis"; | ||
"PopupAtMenuBarIcon" = "Meniu piktograma"; | ||
"PopupAtWindowCenter" = "Lango centras"; | ||
"PopupAtScreenCenter" = "Ekrano centras"; | ||
"PopupAtLastPosition" = "Paskutinė vieta"; | ||
"PopupAtLastLocationReset" = "Iš naujo nustatyti vietą"; | ||
"PopupAtTooltip" = "Pakeiskite vietą, kurioje rodomas iššokantis langas.\nNumatytoji reikšmė: Pelės žymeklis."; | ||
"SearchVisibilityAlways" = "Visada"; | ||
"SearchVisibilityDuringSearch" = "Paieškos metu"; | ||
"ActiveScreen" = "Aktyvus ekranas"; | ||
"PinTo" = "Prisegti:"; | ||
"PinToTop" = "Viršuje"; | ||
"PinToBottom" = "Apačioje"; | ||
"PinToTooltip" = "Pakeiskite prisegtų elementų vietą.\nNumatytoji reikšmė: Viršuje."; | ||
"ImageHeight" = "Paveikslėlio aukštis:"; | ||
"ImageHeightTooltip" = "Didžiausias paveikslėlio peržiūros aukštis.\nNumatytoji reikšmė: 40.\nPatarimas: Nustatykite 16, kad atrodytų kaip teksto elementai."; | ||
"PreviewDelay" = "Peržiūros vėlavimas:"; | ||
"PreviewDelayTooltip" = "Vėlavimas milisekundėmis, kol bus parodytas iškylantysis peržiūros langas.\nNumatytoji reikšmė: 1500."; | ||
"HighlightMatches" = "Paryškinti atitikimus:"; | ||
"HighlightMatchColor" = "Spalva"; | ||
"HighlightMatchBold" = "Paryškintu šriftu"; | ||
"HighlightMatchItalic" = "Kursyvu"; | ||
"HighlightMatchUnderline" = "Pabraukimu"; | ||
"HighlightMatchesTooltip" = "Pakeiskite paieškos atitikmenų paryškinimo stilių.\nNumatytoji reikšmė: Paryškintu šriftu."; | ||
"ShowSpecialSymbols" = "Rodyti specialiuosius simbolius"; | ||
"PinTo" = "Prisegti:"; | ||
"ShowSpecialSymbolsTooltip" = "Rodyti naujas eilutes, skirtukus, pradinius ir galinius tarpus naudojant specialius simbolius."; | ||
"ShowMenuIcon" = "Rodyti meniu piktogramą"; | ||
"ShowRecentCopyInMenuBar" = "Rodyti naujausią kopiją šalia meniu piktogramos"; | ||
"ShowSearchField" = "Rodyti paieškos laukelį"; | ||
"ShowTitleBeforeSearchField" = "Rodyti pavadinimą prieš paieškos laukelį"; | ||
"ShowFooter" = "Rodyti paraštę"; | ||
"ShowApplicationIcons" = "Rodyti programų piktogramas"; | ||
"OpenPreferencesWarning" = "⚠️ Paspauskite ⌘ ir , norėdami atidaryti nustatymus, kai paraštė yra paslėpta."; | ||
"PopupAtMenuBarIcon" = "Meniu piktograma"; | ||
"SearchVisibilityDuringSearch" = "Paieškos metu"; | ||
"PinToTooltip" = "Pakeiskite prisegtų elementų vietą.\nNumatytoji reikšmė: Viršuje."; | ||
"PreviewDelay" = "Peržiūros vėlavimas:"; | ||
"HighlightMatchesTooltip" = "Pakeiskite paieškos atitikmenų paryškinimo stilių.\nNumatytoji reikšmė: Paryškintu šriftu."; | ||
"ShowSpecialSymbolsTooltip" = "Rodyti naujas eilutes, skirtukus, pradinius ir galinius tarpus naudojant specialius simbolius."; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.