Skip to content

Commit

Permalink
Fix swiftlint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Nov 5, 2023
1 parent b6ea378 commit 620c34b
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 99 deletions.
2 changes: 1 addition & 1 deletion src/Tinkle/swift/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {

let menu = NSMenu(title: "Tinkle")

let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as! String
let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? ""
menu.addItem(
withTitle: "Tinkle " + version,
action: nil,
Expand Down
29 changes: 16 additions & 13 deletions src/Tinkle/swift/FocusedWindowObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ public final class FocusedWindowObserver {
print("Missing notification info on NSWorkspace.didActivateApplicationNotification")
return
}
let runningApplication = userInfo[NSWorkspace.applicationUserInfoKey] as! NSRunningApplication

self.addObservedApplication(runningApplication)
if let runningApplication = userInfo[NSWorkspace.applicationUserInfoKey]
as? NSRunningApplication
{
self.addObservedApplication(runningApplication)
}
}

//
Expand All @@ -50,9 +53,12 @@ public final class FocusedWindowObserver {
print("Missing notification info on NSWorkspace.didLaunchApplicationNotification")
return
}
let runningApplication = userInfo[NSWorkspace.applicationUserInfoKey] as! NSRunningApplication

self.addObservedApplication(runningApplication)
if let runningApplication = userInfo[NSWorkspace.applicationUserInfoKey]
as? NSRunningApplication
{
self.addObservedApplication(runningApplication)
}
}

//
Expand All @@ -68,13 +74,16 @@ public final class FocusedWindowObserver {
print("Missing notification info on NSWorkspace.didTerminateApplicationNotification")
return
}
let runningApplication = userInfo[NSWorkspace.applicationUserInfoKey] as! NSRunningApplication

//
// Update observedApplications
//

self.observedApplications.removeValue(forKey: runningApplication.processIdentifier)
if let runningApplication = userInfo[NSWorkspace.applicationUserInfoKey]
as? NSRunningApplication
{
self.observedApplications.removeValue(forKey: runningApplication.processIdentifier)
}
}
}

Expand Down Expand Up @@ -111,13 +120,7 @@ private final class ObservedApplication {
self.callback = callback

application = Application(runningApplication)
observer = application?.createObserver {
(
_: Observer,
_: UIElement,
event: AXNotification,
_: [String: AnyObject]?
) in
observer = application?.createObserver { (_, _, event: AXNotification, _) in
if event == .focusedWindowChanged {
DispatchQueue.main.async {
self.emit()
Expand Down
17 changes: 9 additions & 8 deletions src/Tinkle/swift/MetalViewRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public final class MetalViewRenderer: NSObject, MTKViewDelegate {
private let callback: Callback
private let commandQueue: MTLCommandQueue!
private let device: MTLDevice!
private let nopCps: MTLComputePipelineState!
private let shockwaveCps: MTLComputePipelineState!
private let neonCps: MTLComputePipelineState!
private let nopCps: MTLComputePipelineState?
private let shockwaveCps: MTLComputePipelineState?
private let neonCps: MTLComputePipelineState?
private var startDate = Date()
private var shader: Shader = .nop
private var color = vector_float3(0.0, 0.0, 0.0)
Expand All @@ -29,13 +29,13 @@ public final class MetalViewRenderer: NSObject, MTKViewDelegate {
let library = device.makeDefaultLibrary()!

let nopFunction = library.makeFunction(name: "nopEffect")!
nopCps = try! device.makeComputePipelineState(function: nopFunction)
nopCps = try? device.makeComputePipelineState(function: nopFunction)

let shockwaveFunction = library.makeFunction(name: "shockwaveEffect")!
shockwaveCps = try! device.makeComputePipelineState(function: shockwaveFunction)
shockwaveCps = try? device.makeComputePipelineState(function: shockwaveFunction)

let neonFunction = library.makeFunction(name: "neonEffect")!
neonCps = try! device.makeComputePipelineState(function: neonFunction)
neonCps = try? device.makeComputePipelineState(function: neonFunction)

super.init()
view.delegate = self
Expand All @@ -60,7 +60,7 @@ public final class MetalViewRenderer: NSObject, MTKViewDelegate {
}
}

var cps: MTLComputePipelineState = nopCps
var cps: MTLComputePipelineState? = nopCps
switch shader {
case .nop:
cps = nopCps
Expand All @@ -70,7 +70,8 @@ public final class MetalViewRenderer: NSObject, MTKViewDelegate {
cps = shockwaveCps
}

if let drawable = view.currentDrawable,
if let cps = cps,
let drawable = view.currentDrawable,
let commandBuffer = commandQueue.makeCommandBuffer(),
let commandEncoder = commandBuffer.makeComputeCommandEncoder()
{
Expand Down
10 changes: 5 additions & 5 deletions src/Tinkle/swift/NSWindowExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import AppKit
extension NSWindow {
public func centerToOtherWindow(_ other: NSWindow) {
setFrame(
NSMakeRect(
other.frame.origin.x + (other.frame.size.width / 2) - (frame.size.width / 2),
other.frame.origin.y + (other.frame.size.height / 2) - (frame.size.height / 2),
frame.size.width,
frame.size.height
NSRect(
x: other.frame.origin.x + (other.frame.size.width / 2) - (frame.size.width / 2),
y: other.frame.origin.y + (other.frame.size.height / 2) - (frame.size.height / 2),
width: frame.size.width,
height: frame.size.height
),
display: false
)
Expand Down
4 changes: 2 additions & 2 deletions src/Tinkle/swift/UserDefaults-propertyWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ struct UserDefault<T> {
get: {
self.wrappedValue
},
set: {
newValue in self.wrappedValue = newValue
set: { newValue in
self.wrappedValue = newValue
}
)
}
Expand Down
35 changes: 23 additions & 12 deletions src/Tinkle/swift/Views/AccessibilityAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,37 @@ struct AccessibilityAlertView: View {
Text("Open System Settings > Privacy & Security > Accessibility, then turn on Tinkle.")
.padding(
.top, 20.0)
Button(action: {
NSWorkspace.shared.open(
URL(
string:
"x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility")!)
}) {
Label(
"Open System Settings > Privacy & Security > Accessibility...",
systemImage: "arrow.forward.circle.fill")
}
Button(
action: {
NSWorkspace.shared.open(
URL(
string:
"x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility")!)
},
label: {
Label(
"Open System Settings > Privacy & Security > Accessibility...",
systemImage: "arrow.forward.circle.fill")
})

Text("Restart Tinkle after you approve the feature.").padding(.top, 20.0)
RestartButton()

Button(
action: { Relauncher.relaunch() },
label: {
Label("Restart Tinkle", systemImage: "arrow.clockwise")
})

Spacer()
.frame(height: 50.0)

Divider()

QuitButton()
Button(
action: { NSApplication.shared.terminate(self) },
label: {
Label("Quit Tinkle", systemImage: "xmark.circle.fill")
})
}.frame(minWidth: 400.0)

Image("accessibility")
Expand Down
9 changes: 0 additions & 9 deletions src/Tinkle/swift/Views/QuitButton.swift

This file was deleted.

9 changes: 0 additions & 9 deletions src/Tinkle/swift/Views/RestartButton.swift

This file was deleted.

24 changes: 14 additions & 10 deletions src/Tinkle/swift/Views/Settings/SettingsActionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@ struct SettingsActionView: View {
GroupBox(label: Text("Action")) {
VStack(alignment: .leading, spacing: 16) {
HStack {
Button(action: {
Relauncher.relaunch()
}) {
Label("Restart Tinkle", systemImage: "arrow.clockwise")
}
Button(
action: {
Relauncher.relaunch()
},
label: {
Label("Restart Tinkle", systemImage: "arrow.clockwise")
})

Spacer()
}

HStack {
Button(action: {
NSApplication.shared.terminate(self)
}) {
Label("Quit Tinkle", systemImage: "xmark.circle.fill")
}
Button(
action: {
NSApplication.shared.terminate(self)
},
label: {
Label("Quit Tinkle", systemImage: "xmark.circle.fill")
})

Spacer()
}
Expand Down
40 changes: 25 additions & 15 deletions src/Tinkle/swift/Views/Settings/SettingsUpdateView.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwiftUI

struct SettingsUpdateView: View {
let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as! String
let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? ""

var body: some View {
VStack(alignment: .leading, spacing: 25.0) {
Expand All @@ -21,14 +21,18 @@ struct SettingsUpdateView: View {

GroupBox(label: Text("Websites")) {
HStack(spacing: 20.0) {
Button(action: { NSWorkspace.shared.open(URL(string: "https://tinkle.pqrs.org")!) }) {
Label("Open official website", systemImage: "house")
}
Button(action: {
NSWorkspace.shared.open(URL(string: "https://github.com/pqrs-org/Tinkle")!)
}) {
Label("Open GitHub (source code)", systemImage: "network")
}
Button(
action: { NSWorkspace.shared.open(URL(string: "https://tinkle.pqrs.org")!) },
label: {
Label("Open official website", systemImage: "house")
})
Button(
action: {
NSWorkspace.shared.open(URL(string: "https://github.com/pqrs-org/Tinkle")!)
},
label: {
Label("Open GitHub (source code)", systemImage: "network")
})
Spacer()
}.padding()
}
Expand All @@ -43,9 +47,12 @@ struct SettingsUpdateView: View {
@ObservedObject private var updater = Updater.shared

var body: some View {
Button(action: { updater.checkForUpdatesStableOnly() }) {
Label("Check for updates...", systemImage: "star")
}
Button(
action: { updater.checkForUpdatesStableOnly() },
label: {
Label("Check for updates...", systemImage: "star")
}
)
.disabled(!updater.canCheckForUpdates)
}
}
Expand All @@ -56,9 +63,12 @@ struct SettingsUpdateView: View {
@ObservedObject private var updater = Updater.shared

var body: some View {
Button(action: { updater.checkForUpdatesWithBetaVersion() }) {
Label("Check for beta updates...", systemImage: "star.circle")
}
Button(
action: { updater.checkForUpdatesWithBetaVersion() },
label: {
Label("Check for beta updates...", systemImage: "star.circle")
}
)
.disabled(!updater.canCheckForUpdates)
}
}
Expand Down
39 changes: 24 additions & 15 deletions src/Tinkle/swift/Views/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,39 @@ struct SettingsView: View {
HStack {
VStack(alignment: .leading, spacing: 0) {
Group {
Button(action: {
selection = .basic
}) {
SidebarLabelView(text: "Basic", systemImage: "gearshape")
}
Button(
action: {
selection = .basic
},
label: {
SidebarLabelView(text: "Basic", systemImage: "gearshape")
}
)
.sidebarButtonStyle(selected: selection == .basic)

Button(action: {
selection = .update
}) {
SidebarLabelView(text: "Update", systemImage: "network")
}
Button(
action: {
selection = .update
},
label: {
SidebarLabelView(text: "Update", systemImage: "network")
}
)
.sidebarButtonStyle(selected: selection == .update)
}

Divider()
.padding(.vertical, 10.0)

Group {
Button(action: {
selection = .action
}) {
SidebarLabelView(text: "Quit, Restart", systemImage: "bolt.circle")
}
Button(
action: {
selection = .action
},
label: {
SidebarLabelView(text: "Quit, Restart", systemImage: "bolt.circle")
}
)
.sidebarButtonStyle(selected: selection == .action)
}

Expand Down

0 comments on commit 620c34b

Please sign in to comment.