Skip to content

Commit

Permalink
run swiftformat
Browse files Browse the repository at this point in the history
swiftformat . --swiftversion 5.0

add lint github action

add build phase in Xcode
  • Loading branch information
ShlomoCode committed Aug 11, 2024
1 parent 2f15a2a commit c50933d
Show file tree
Hide file tree
Showing 38 changed files with 862 additions and 802 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Lint
on: pull_request

jobs:
Lint:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: SwiftFormat
run: swiftformat --lint --swiftversion 5.0 . --reporter github-actions-log
4 changes: 2 additions & 2 deletions .github/workflows/pr-lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Lint PR"
name: "PR Title Convention"

on:
pull_request_target:
Expand All @@ -13,7 +13,7 @@ permissions:

jobs:
main:
name: Validate PR title
name: Validate PR Title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
Expand Down
Empty file added BuildTools/Empty.swift
Empty file.
16 changes: 16 additions & 0 deletions BuildTools/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"object": {
"pins": [
{
"package": "SwiftFormat",
"repositoryURL": "https://github.com/nicklockwood/SwiftFormat",
"state": {
"branch": null,
"revision": "d6309f7440889427426143b4a0b100b959d3f3e6",
"version": "0.54.3"
}
}
]
},
"version": 1
}
11 changes: 11 additions & 0 deletions BuildTools/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// swift-tools-version:5.1
import PackageDescription

let package = Package(
name: "BuildTools",
platforms: [.macOS(.v10_11)],
dependencies: [
.package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.54.3"),
],
targets: [.target(name: "BuildTools", path: "")]
)
25 changes: 25 additions & 0 deletions DockDoor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
isa = PBXNativeTarget;
buildConfigurationList = BB157B742C0E31CF00997315 /* Build configuration list for PBXNativeTarget "DockDoor" */;
buildPhases = (
054B715D2C69264800E662F3 /* Run Script */,
BB157B612C0E31CE00997315 /* Sources */,
BB157B622C0E31CE00997315 /* Frameworks */,
BB157B632C0E31CE00997315 /* Resources */,
Expand Down Expand Up @@ -322,6 +323,28 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
054B715D2C69264800E662F3 /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Run Script";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "cd BuildTools\nSDKROOT=(xcrun --sdk macosx --show-sdk-path)\n#swift package update #Uncomment this line temporarily to update the version used to the latest matching your BuildTools/Package.swift file\nswift run -c release swiftformat \"$SRCROOT\" --swiftversion 5.0\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
BB157B612C0E31CE00997315 /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down Expand Up @@ -503,6 +526,7 @@
DEVELOPMENT_TEAM = 2Q775S63Q3;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = DockDoor/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = DockDoor;
Expand Down Expand Up @@ -535,6 +559,7 @@
DEVELOPMENT_TEAM = 2Q775S63Q3;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = DockDoor/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = DockDoor;
Expand Down
88 changes: 44 additions & 44 deletions DockDoor/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
//

import Cocoa
import SwiftUI
import Defaults
import Settings
import Sparkle
import SwiftUI

class SettingsWindowControllerDelegate: NSObject, NSWindowDelegate {
func windowDidBecomeKey(_ notification: Notification) {
func windowDidBecomeKey(_: Notification) {
NSApp.setActivationPolicy(.regular) // Show dock icon on open settings window
}
func windowWillClose(_ notification: Notification) {

func windowWillClose(_: Notification) {
NSApp.setActivationPolicy(.accessory) // Hide dock icon back
}
}
Expand All @@ -26,9 +26,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
private var appClosureObserver: WindowManipulationObservers?
private var keybindHelper: KeybindHelper?
private var statusBarItem: NSStatusItem?

private var updaterController: SPUStandardUpdaterController

// settings
private var firstTimeWindow: NSWindow?
private lazy var settingsWindowController = SettingsWindowController(
Expand All @@ -37,33 +37,32 @@ class AppDelegate: NSObject, NSApplicationDelegate {
AppearanceSettingsViewController(),
WindowSwitcherSettingsViewController(),
PermissionsSettingsViewController(),
UpdatesSettingsViewController(updater: updaterController.updater)
UpdatesSettingsViewController(updater: updaterController.updater),
]
)
private let settingsWindowControllerDelegate = SettingsWindowControllerDelegate()

override init() {
self.updaterController = SPUStandardUpdaterController(startingUpdater: true, updaterDelegate: nil, userDriverDelegate: nil)
self.updaterController.startUpdater()
updaterController = SPUStandardUpdaterController(startingUpdater: true, updaterDelegate: nil, userDriverDelegate: nil)
updaterController.startUpdater()
super.init()

if let zoomButton = settingsWindowController.window?.standardWindowButton(.zoomButton) {
zoomButton.isEnabled = false
}

settingsWindowController.window?.delegate = settingsWindowControllerDelegate
}


func applicationDidFinishLaunching(_ aNotification: Notification) {

func applicationDidFinishLaunching(_: Notification) {
NSApplication.shared.setActivationPolicy(.accessory) // Hide the menubar and dock icons

if Defaults[.showMenuBarIcon] {
self.setupMenuBar()
setupMenuBar()
} else {
self.removeMenuBar()
removeMenuBar()
}

if !Defaults[.launched] {
handleFirstTimeLaunch()
} else {
Expand All @@ -74,12 +73,12 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}
}
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
self.openSettingsWindow(nil)

func applicationShouldHandleReopen(_: NSApplication, hasVisibleWindows _: Bool) -> Bool {
openSettingsWindow(nil)
return false
}

func setupMenuBar() {
guard statusBarItem == nil else { return }
let icon = NSImage(systemSymbolName: "door.right.hand.open", accessibilityDescription: nil)!
Expand All @@ -88,80 +87,81 @@ class AppDelegate: NSObject, NSApplicationDelegate {
button.image = icon
button.action = #selector(statusBarButtonClicked(_:))
button.target = self

// Create Menu Items
let openSettingsMenuItem = NSMenuItem(title: String(localized: "Open Settings"), action: #selector(openSettingsWindow(_:)), keyEquivalent: "")
openSettingsMenuItem.target = self
let quitMenuItem = NSMenuItem(title: String(localized: "Quit DockDoor"), action: #selector(quitAppWrapper), keyEquivalent: "q")
quitMenuItem.target = self

// Create the Menu
let menu = NSMenu()
menu.addItem(openSettingsMenuItem)
menu.addItem(NSMenuItem.separator())
menu.addItem(quitMenuItem)

button.menu = menu
}
}

func removeMenuBar() {
guard let statusBarItem = statusBarItem else { return }
guard let statusBarItem else { return }
NSStatusBar.system.removeStatusItem(statusBarItem)
self.statusBarItem = nil
}
@objc func statusBarButtonClicked(_ sender: Any?) {

@objc func statusBarButtonClicked(_: Any?) {
// Show the menu
if let button = statusBarItem?.button {
button.menu?.popUp(positioning: nil, at: NSPoint(x: 0, y: button.bounds.maxY), in: button)
}
}

@objc private func quitAppWrapper() {
quitApp()
}
@objc func openSettingsWindow(_ sender: Any?) {

@objc func openSettingsWindow(_: Any?) {
settingsWindowController.show()
}

func quitApp() {
NSApplication.shared.terminate(nil)
}

func restartApp() {
// we use -n to open a new instance, to avoid calling applicationShouldHandleReopen
// we use Bundle.main.bundlePath in case of multiple DockDoor versions on the machine
Process.launchedProcess(launchPath: "/usr/bin/open", arguments: ["-n", Bundle.main.bundlePath])
self.quitApp()
quitApp()
}

private func handleFirstTimeLaunch() {
let contentView = FirstTimeView()

// Save that the app has launched
Defaults[.launched] = true

// Create a hosting controller
let hostingController = NSHostingController(rootView: contentView)

// Create the settings window
firstTimeWindow = NSWindow(
contentRect: NSRect(origin: .zero, size: NSSize(width: 400, height: 400)),
styleMask: [.titled, .closable, .resizable],
backing: .buffered, defer: false)
backing: .buffered, defer: false
)
firstTimeWindow?.center()
firstTimeWindow?.setFrameAutosaveName("DockDoor Permissions")
firstTimeWindow?.contentView = hostingController.view
firstTimeWindow?.title = "DockDoor Permissions"

// Make the window key and order it front
firstTimeWindow?.makeKeyAndOrderFront(nil)

// Calculate the preferred size of the SwiftUI view
let preferredSize = hostingController.view.fittingSize

// Resize the window to fit the content view
firstTimeWindow?.setContentSize(preferredSize)
}
Expand Down
9 changes: 4 additions & 5 deletions DockDoor/Components/BlurView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,26 @@
import SwiftUI

struct BlurView: NSViewRepresentable {
func makeNSView(context: Context) -> NSVisualEffectView {
func makeNSView(context _: Context) -> NSVisualEffectView {
let effectView = NSVisualEffectView()
effectView.state = .active
effectView.material = .popover
return effectView
}

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

struct MaterialBlurView: NSViewRepresentable {
var material: NSVisualEffectView.Material

func makeNSView(context: Context) -> NSVisualEffectView {
func makeNSView(context _: Context) -> NSVisualEffectView {
let view = NSVisualEffectView()
view.material = material
view.blendingMode = .behindWindow
view.state = .active
return view
}

func updateNSView(_ nsView: NSVisualEffectView, context: Context) {}
func updateNSView(_: NSVisualEffectView, context _: Context) {}
}
4 changes: 2 additions & 2 deletions DockDoor/Components/FluidGradient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Created by Ethan Bills on 7/11/24.
//

import SwiftUI
import FluidGradient
import SwiftUI

func fluidGradient() -> some View {
FluidGradient(
Expand All @@ -20,7 +20,7 @@ func fluidGradient() -> some View {
struct FluidGradientBorder: ViewModifier {
let cornerRadius: CGFloat
let lineWidth: CGFloat

func body(content: Content) -> some View {
content
.overlay(
Expand Down
4 changes: 2 additions & 2 deletions DockDoor/Components/HiddenModifier.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ReadModifier.swift
// HiddenModifier.swift
// OpenArtemis
//
// Created by Ethan Bills on 1/1/24.
Expand All @@ -17,6 +17,6 @@ struct HiddenModifier: ViewModifier {

extension View {
func markHidden(isHidden: Bool) -> some View {
self.modifier(HiddenModifier(isHidden: isHidden))
modifier(HiddenModifier(isHidden: isHidden))
}
}
Loading

0 comments on commit c50933d

Please sign in to comment.