Skip to content

Commit c406989

Browse files
committed
✨ add custom about window
1 parent 36e17a7 commit c406989

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

SilkScreen.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
961CD236287F733400E4110B /* AboutWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961CD235287F733400E4110B /* AboutWindow.swift */; };
1011
964B527D2847DAF9005FB0CF /* BaseImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 964B527C2847DAF9005FB0CF /* BaseImageView.swift */; };
1112
964B527F2847DB84005FB0CF /* BaseDragDropView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 964B527E2847DB84005FB0CF /* BaseDragDropView.swift */; };
1213
964B52812847DBFC005FB0CF /* GPWelcomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 964B52802847DBFC005FB0CF /* GPWelcomeView.swift */; };
@@ -22,6 +23,7 @@
2223
/* End PBXBuildFile section */
2324

2425
/* Begin PBXFileReference section */
26+
961CD235287F733400E4110B /* AboutWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutWindow.swift; sourceTree = "<group>"; };
2527
964B527C2847DAF9005FB0CF /* BaseImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseImageView.swift; sourceTree = "<group>"; };
2628
964B527E2847DB84005FB0CF /* BaseDragDropView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseDragDropView.swift; sourceTree = "<group>"; };
2729
964B52802847DBFC005FB0CF /* GPWelcomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GPWelcomeView.swift; sourceTree = "<group>"; };
@@ -93,6 +95,7 @@
9395
96B72438283D978E00F149DF /* WindowController.swift */,
9496
96B4DAB9282F2C80005C0792 /* Document.swift */,
9597
96B72436283D976600F149DF /* Window.swift */,
98+
961CD235287F733400E4110B /* AboutWindow.swift */,
9699
965B9EAF2841687B006FBA63 /* Extensions.swift */,
97100
96B4DABD282F2C81005C0792 /* Main.storyboard */,
98101
);
@@ -203,6 +206,7 @@
203206
96B72439283D978E00F149DF /* WindowController.swift in Sources */,
204207
96B4DAB6282F2C80005C0792 /* AppDelegate.swift in Sources */,
205208
96B4DABA282F2C80005C0792 /* Document.swift in Sources */,
209+
961CD236287F733400E4110B /* AboutWindow.swift in Sources */,
206210
964B52832847DC26005FB0CF /* GPImageView.swift in Sources */,
207211
965B9EB02841687B006FBA63 /* Extensions.swift in Sources */,
208212
964B527F2847DB84005FB0CF /* BaseDragDropView.swift in Sources */,

Sources/AboutWindow.swift

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import Cocoa
2+
3+
fileprivate func BasicLink(
4+
text: String,
5+
href: String,
6+
font: NSFont
7+
) -> NSAttributedString {
8+
return NSAttributedString(
9+
string: text,
10+
attributes: [
11+
.font: font,
12+
.link: NSURL(string: href) ?? "",
13+
.toolTip: href,
14+
.underlineColor: NSColor.clear,
15+
]
16+
)
17+
}
18+
19+
fileprivate func join(_ parts: [NSAttributedString]) -> NSMutableAttributedString {
20+
let joinedString = NSMutableAttributedString(string: "")
21+
parts.forEach{ joinedString.append($0) }
22+
return joinedString
23+
}
24+
25+
extension NSApplication.AboutPanelOptionKey {
26+
static let copyright = NSApplication.AboutPanelOptionKey(rawValue: "Copyright")
27+
}
28+
29+
class AboutWindow {
30+
static let shared = AboutWindow()
31+
@objc func show() {
32+
NSApp.orderFrontStandardAboutPanel(options: [
33+
.copyright: "",
34+
.credits: join([
35+
BasicLink(
36+
text: "Source Code",
37+
href: "https://github.com/leonardodino/SilkScreen",
38+
font: NSFont.systemFont(ofSize: 12, weight: .medium)
39+
),
40+
NSAttributedString(
41+
string: "\n\n",
42+
attributes: [.font: NSFont.systemFont(ofSize: 6)]
43+
),
44+
BasicLink(
45+
text: "Leonardo Dino",
46+
href: "https://leonardodino.com/",
47+
font: NSFont.systemFont(ofSize: 10)
48+
),
49+
]),
50+
])
51+
NSApp.activate(ignoringOtherApps: true)
52+
}
53+
}

Sources/AppDelegate.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
3939
return true
4040
}
4141

42+
@IBAction func showAbout(_ sender: Any?) {
43+
AboutWindow.shared.show()
44+
}
4245
@IBAction func showHelp(_ sender: Any?) {
4346
if let url = URL(string: "https://github.com/leonardodino/SilkScreen") {
4447
NSWorkspace.shared.open(url)

Sources/Base.lproj/Main.storyboard

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<menuItem title="About SilkScreen" id="5kV-Vb-QxS">
1919
<modifierMask key="keyEquivalentModifierMask"/>
2020
<connections>
21-
<action selector="orderFrontStandardAboutPanel:" target="Ady-hI-5gd" id="Exp-CZ-Vem"/>
21+
<action selector="showAbout:" target="Voe-Tx-rLC" id="9Ex-pP-za5"/>
2222
</connections>
2323
</menuItem>
2424
<menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>

0 commit comments

Comments
 (0)