Skip to content

Commit 66dabe5

Browse files
authored
Merge pull request #26 from SillyLittleTech/copilot/bugfix-macos-window-disappears
Prevent macOS dock miniwindow preview from rendering blank
2 parents 35a6fce + 342c9e3 commit 66dabe5

5 files changed

Lines changed: 30 additions & 5 deletions

File tree

PinStickApp.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
2525
}
2626
}
2727

28+
func windowWillMiniaturize(_ notification: Notification) {
29+
guard
30+
let miniaturizingWindow = notification.object as? NSWindow,
31+
let image = miniaturizingWindow.contentView?.snapshotImage()
32+
else {
33+
return
34+
}
35+
miniaturizingWindow.miniwindowImage = image
36+
}
37+
2838
func windowShouldClose(_ sender: NSWindow) -> Bool {
2939
if sender.isDocumentEdited {
3040
let alert = NSAlert()
@@ -50,6 +60,21 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
5060
}
5161
}
5262

63+
private extension NSView {
64+
func snapshotImage() -> NSImage? {
65+
guard bounds.width > 0, bounds.height > 0 else {
66+
return nil
67+
}
68+
guard let bitmap = bitmapImageRepForCachingDisplay(in: bounds) else {
69+
return nil
70+
}
71+
cacheDisplay(in: bounds, to: bitmap)
72+
let image = NSImage(size: bounds.size)
73+
image.addRepresentation(bitmap)
74+
return image
75+
}
76+
}
77+
5378
struct ContentViewWrapper: NSViewControllerRepresentable {
5479
func makeNSViewController(context: Context) -> NSHostingController<ContentView> {
5580
let view = ContentView()

cross-platform/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cross-platform/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pinstick-cross",
3-
"version": "2.8.1",
3+
"version": "2.8.2",
44
"private": true,
55
"type": "module",
66
"scripts": {

cross-platform/src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pinstick"
3-
version = "2.8.1"
3+
version = "2.8.2"
44
description = "PinStick cross-platform note pinning app"
55
authors = ["SillyLittleTech"]
66
edition = "2021"

cross-platform/src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"package": {
1010
"productName": "PinStick",
11-
"version": "2.8.1"
11+
"version": "2.8.2"
1212
},
1313
"tauri": {
1414
"macOSPrivateApi": true,

0 commit comments

Comments
 (0)