Skip to content

Commit

Permalink
fix: Closes #73 - Add project URL to the about dialogue
Browse files Browse the repository at this point in the history
  • Loading branch information
othyn committed Jul 14, 2023
1 parent 8eead3f commit 03c716f
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 9 deletions.
22 changes: 15 additions & 7 deletions auto-clicker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
B53BDC54264BED95001F8E57 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B53BDC53264BED95001F8E57 /* Assets.xcassets */; };
B53BDC57264BED95001F8E57 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B53BDC56264BED95001F8E57 /* Preview Assets.xcassets */; };
B53BDC60264BF3A8001F8E57 /* NumberField.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53BDC5F264BF3A8001F8E57 /* NumberField.swift */; };
B5462E742A6173D400C5F280 /* AboutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5462E732A6173D400C5F280 /* AboutView.swift */; };
B5462E762A61761000C5F280 /* Bundle+AppInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5462E752A61761000C5F280 /* Bundle+AppInfo.swift */; };
B5B0B2AF2882EE6E00462F11 /* ACWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5B0B2AE2882EE6E00462F11 /* ACWindow.swift */; };
B5B6B46328032D3200C779FD /* PermissionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5B6B46228032D3200C779FD /* PermissionsView.swift */; };
B5B6B46528033A0F00C779FD /* PermissionsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5B6B46428033A0F00C779FD /* PermissionsService.swift */; };
Expand Down Expand Up @@ -103,6 +105,8 @@
B53BDC58264BED95001F8E57 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
B53BDC59264BED95001F8E57 /* auto_clicker.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = auto_clicker.entitlements; sourceTree = "<group>"; };
B53BDC5F264BF3A8001F8E57 /* NumberField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NumberField.swift; sourceTree = "<group>"; };
B5462E732A6173D400C5F280 /* AboutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutView.swift; sourceTree = "<group>"; };
B5462E752A61761000C5F280 /* Bundle+AppInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Bundle+AppInfo.swift"; sourceTree = "<group>"; };
B5B0B2AE2882EE6E00462F11 /* ACWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ACWindow.swift; sourceTree = "<group>"; };
B5B6B46228032D3200C779FD /* PermissionsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PermissionsView.swift; sourceTree = "<group>"; };
B5B6B46428033A0F00C779FD /* PermissionsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PermissionsService.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -182,6 +186,7 @@
isa = PBXGroup;
children = (
B5B0B2AE2882EE6E00462F11 /* ACWindow.swift */,
B5462E732A6173D400C5F280 /* AboutView.swift */,
B5B6B46228032D3200C779FD /* PermissionsView.swift */,
B5F6A00E27F37440003CD730 /* MainView.swift */,
B5E6395127CA62DE008B111A /* Styles */,
Expand Down Expand Up @@ -357,9 +362,9 @@
B5E6394E27CA4CB1008B111A /* Constants */ = {
isa = PBXGroup;
children = (
B510762927F4BD8F00BB1CDA /* Defaults.swift */,
B5E6394F27CA4CDD008B111A /* FieldConstants.swift */,
B510761727F4A58500BB1CDA /* KeyboardShortcuts.swift */,
B510762927F4BD8F00BB1CDA /* Defaults.swift */,
);
path = Constants;
sourceTree = "<group>";
Expand Down Expand Up @@ -388,16 +393,17 @@
B5F6A01027F38666003CD730 /* Extensions */ = {
isa = PBXGroup;
children = (
B5D603F02883035E00655D2C /* ContainerView.swift */,
B5F6A01827F3970A003CD730 /* ThemeColour.swift */,
B5F6A01327F388A8003CD730 /* NSColor+Extensions.swift */,
B5462E752A61761000C5F280 /* Bundle+AppInfo.swift */,
B5BCE810287C38ED00B739AD /* CGVector+DefaultsSerializable.swift */,
B5BCE804287BFB5A00B739AD /* Color+ExpressibleByStringLiteral.swift */,
B5F6A01527F3900E003CD730 /* Color+Extensions.swift */,
B5D603F02883035E00655D2C /* ContainerView.swift */,
B510762C27F4BF0C00BB1CDA /* Defaults+Workaround.swift */,
B5BF094428847346008092D9 /* KeyboardShortcuts+Extensions.swift */,
B5F6A01327F388A8003CD730 /* NSColor+Extensions.swift */,
B510763A2800DDFF00BB1CDA /* NSEvent+Extensions.swift */,
C4345BB42846056000365CF9 /* ProcessInfo+Extensions.swift */,
B5BCE804287BFB5A00B739AD /* Color+ExpressibleByStringLiteral.swift */,
B5BCE810287C38ED00B739AD /* CGVector+DefaultsSerializable.swift */,
B5BF094428847346008092D9 /* KeyboardShortcuts+Extensions.swift */,
B5F6A01827F3970A003CD730 /* ThemeColour.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -601,6 +607,7 @@
B5D603F12883035E00655D2C /* ContainerView.swift in Sources */,
B5BCE805287BFB5A00B739AD /* Color+ExpressibleByStringLiteral.swift in Sources */,
B510761F27F4B6F500BB1CDA /* KeyboardShortcutHint.swift in Sources */,
B5462E742A6173D400C5F280 /* AboutView.swift in Sources */,
B5107640280113DB00BB1CDA /* Input.swift in Sources */,
B510762A27F4BD8F00BB1CDA /* Defaults.swift in Sources */,
B5B6B46528033A0F00C779FD /* PermissionsService.swift in Sources */,
Expand All @@ -616,6 +623,7 @@
B5BCE809287C2F4D00B739AD /* SmallText.swift in Sources */,
B5E4213728057BA900C2CA2D /* LoggerService.swift in Sources */,
B5E92B0E27F1036B00A7FC63 /* DurationModal.swift in Sources */,
B5462E762A61761000C5F280 /* Bundle+AppInfo.swift in Sources */,
B5B0B2AF2882EE6E00462F11 /* ACWindow.swift in Sources */,
B5BCE803287BF59900B739AD /* Colour.swift in Sources */,
B5BF09402883230D008092D9 /* MenuBarService.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions auto-clicker/Build Assets/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>cb79d84</string>
<string>8eead3f</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>
<string>Othyn ~ Ben Tindall</string>
<string>Copyright © 2023, Ben Tindall. All rights reserved.</string>
</dict>
</plist>
23 changes: 23 additions & 0 deletions auto-clicker/Extensions/Bundle+AppInfo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Bundle+AppInfo.swift
// auto-clicker
//
// Created by Ben Tindall on 14/07/2023.
//

import Foundation

extension Bundle {
public var appName: String { getInfo("CFBundleName") }
public var displayName: String { getInfo("CFBundleDisplayName") }
public var identifier: String { getInfo("CFBundleIdentifier") }
public var copyright: String { getInfo("NSHumanReadableCopyright") }

public var appBuild: String { getInfo("CFBundleVersion") }
public var appVersionLong: String { getInfo("CFBundleShortVersionString") }
public var appVersionShort: String { getInfo("CFBundleShortVersion") }

public var language: String { getInfo("CFBundleDevelopmentRegion") }

fileprivate func getInfo(_ str: String) -> String { infoDictionary?[str] as? String ?? "N/A" }
}
29 changes: 29 additions & 0 deletions auto-clicker/Init/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
import Foundation
import Cocoa
import Defaults
import SwiftUI

final class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
private var aboutWindowController: NSWindowController?

func applicationWillFinishLaunching(_ notification: Notification) {
WindowStateService.refreshDockIconState()
}
Expand Down Expand Up @@ -60,4 +63,30 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {

return true
}

func showAboutWindow() {
if aboutWindowController == nil {
let window = NSWindow()

window.contentView = NSHostingView(rootView: AboutView())

window.styleMask.insert(.titled)
window.styleMask.insert(.closable)
window.styleMask.insert(.fullSizeContentView)

window.titlebarAppearsTransparent = true

window.standardWindowButton(.miniaturizeButton)?.isHidden = true
window.standardWindowButton(.closeButton)?.isHidden = false
window.standardWindowButton(.zoomButton)?.isHidden = true

window.isMovableByWindowBackground = true

window.center()

aboutWindowController = NSWindowController(window: window)
}

aboutWindowController?.showWindow(aboutWindowController?.window)
}
}
4 changes: 4 additions & 0 deletions auto-clicker/Init/AutoClickerApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ struct AutoClickerApp: App {
.windowResizability(.contentSize)
.commands {
HelpCommands()

CommandGroup(replacing: CommandGroupPlacement.appInfo) {
Button(NSLocalizedString("about_about", comment: "About") + " \(Bundle.main.appName)...") { delegate.showAboutWindow() }
}
}
}
}
4 changes: 4 additions & 0 deletions auto-clicker/Localisation/en-GB.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"permissions_help_open_sys_pref_btn" = "Open System Preferences";
"permissions_help_unlock_note" = "The app will automatically unlock within a few seconds of the permission being granted.";

"about_about" = "About";
"about_url" = "https://github.com/othyn/macos-auto-clicker";
"about_url_short" = "github.com/othyn/macos-auto-clicker";

"main_window_comma" = ",";
"main_window_full_stop" = ".";
"main_window_every" = "Every";
Expand Down
65 changes: 65 additions & 0 deletions auto-clicker/Views/Main/AboutView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// AboutView.swift
// auto-clicker
//
// Created by Ben Tindall on 14/07/2023.
//

import Foundation
import SwiftUI

/**
* This is the only way to solve visual effects not working in SwiftUI. Its not documented anywhere, the only place online to find this is:
* https://www.reddit.com/r/SwiftUI/comments/va8ygf/translucent_window_with_transparent_title_bar_in/
*
* If you try to use an NSVisualEffectView in the AppDelegate against the NSWindow or any other method, such as the .background(.ultraThinMaterial)
* on the SwiftUI View, you'll just get a grey background. Finding information on this was near impossible.
*/
struct VisualEffectView: NSViewRepresentable {
func makeNSView(context: Context) -> NSVisualEffectView {
let view = NSVisualEffectView()

view.blendingMode = .behindWindow
view.material = .underWindowBackground
view.state = .active

return view
}

func updateNSView(_ nsView: NSVisualEffectView, context: Context) {
//
}
}

struct AboutView: View {
var body: some View {
VStack(spacing: 10) {
Image(nsImage: NSImage(named: "AppIcon")!)

Text("\(Bundle.main.appName)")
.font(.system(size: 28, weight: .bold))
.multilineTextAlignment(.center)

Text("\(Bundle.main.appVersionLong) (\(Bundle.main.appBuild))")
.font(.system(size: 12, weight: .medium))
.multilineTextAlignment(.center)
.textSelection(.enabled)
.padding(.bottom)

Link("about_url_short", destination: URL(string: String(format: NSLocalizedString("about_url", comment: "About URL")))!)
.font(.system(size: 12, weight: .regular))
.multilineTextAlignment(.center)

Text(Bundle.main.copyright)
.font(.system(size: 10, weight: .regular))
.multilineTextAlignment(.center)
}
.padding(20)
.ignoresSafeArea()
.frame(minWidth: 375, minHeight: 350)
.background(VisualEffectView().ignoresSafeArea())

// .ignoresSafeArea() order matters! Otherwise there is dead space under the rendered View
// https://stackoverflow.com/a/70275484/4494375
}
}

0 comments on commit 03c716f

Please sign in to comment.