Skip to content

Commit

Permalink
Merge branch 'feature' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ruittenb committed Oct 3, 2024
2 parents bce733f + 95bc93a commit 4c0f283
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 42 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
1.6.17: Code refactoring
1.6.16: Code refactoring
1.6.15: Fixed crash when error handling after sending applescript command
1.6.14: Bypass osascript. This eliminates the need for forking a child process
Expand Down
16 changes: 8 additions & 8 deletions Spaceman.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
E8C5AFF52580848100614F50 /* AboutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8C5AFF42580848100614F50 /* AboutView.swift */; };
E8CA0CB82775F35B004A3C75 /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = E8CA0CB72775F35B004A3C75 /* Sparkle */; };
E8E2AEF8257CB4D700319BBC /* PreferencesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8E2AEF7257CB4D700319BBC /* PreferencesViewModel.swift */; };
E8E2AEFF257CB5AF00319BBC /* SpacemanStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8E2AEFE257CB5AF00319BBC /* SpacemanStyle.swift */; };
E8E2AEFF257CB5AF00319BBC /* DisplayStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8E2AEFE257CB5AF00319BBC /* DisplayStyle.swift */; };
E8E2AF03257CB5CE00319BBC /* SpaceNameInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8E2AF02257CB5CE00319BBC /* SpaceNameInfo.swift */; };
E8E8D41C2585A80B00671AE9 /* KeyboardShortcuts in Frameworks */ = {isa = PBXBuildFile; productRef = E8E8D41B2585A80B00671AE9 /* KeyboardShortcuts */; };
E8EBF08C2575F8E4001BA74F /* LaunchAtLogin in Frameworks */ = {isa = PBXBuildFile; productRef = E8EBF08B2575F8E4001BA74F /* LaunchAtLogin */; };
Expand Down Expand Up @@ -70,7 +70,7 @@
E8733516256C6F3A0012586E /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
E8C5AFF42580848100614F50 /* AboutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutView.swift; sourceTree = "<group>"; };
E8E2AEF7257CB4D700319BBC /* PreferencesViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesViewModel.swift; sourceTree = "<group>"; };
E8E2AEFE257CB5AF00319BBC /* SpacemanStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpacemanStyle.swift; sourceTree = "<group>"; };
E8E2AEFE257CB5AF00319BBC /* DisplayStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayStyle.swift; sourceTree = "<group>"; };
E8E2AF02257CB5CE00319BBC /* SpaceNameInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpaceNameInfo.swift; sourceTree = "<group>"; };
E8EBF090257739ED001BA74F /* PreferencesWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindow.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -180,12 +180,12 @@
E8E2AEFC257CB51C00319BBC /* Model */ = {
isa = PBXGroup;
children = (
E8E2AEFE257CB5AF00319BBC /* DisplayStyle.swift */,
E7DA73A72CA6E7A700212836 /* GuiSize.swift */,
E73504B32CAD14BE007F62B5 /* IconWidth.swift */,
E7DA73A92CA8C09300212836 /* KeySet.swift */,
E7DA73A52CA6E74D00212836 /* LayoutMode.swift */,
E873350D256B5F0F0012586E /* Space.swift */,
E8E2AEFE257CB5AF00319BBC /* SpacemanStyle.swift */,
E8E2AF02257CB5CE00319BBC /* SpaceNameInfo.swift */,
);
path = Model;
Expand Down Expand Up @@ -314,7 +314,7 @@
E8E2AF03257CB5CE00319BBC /* SpaceNameInfo.swift in Sources */,
E7DA73A62CA6E74D00212836 /* LayoutMode.swift in Sources */,
E8EBF091257739ED001BA74F /* PreferencesWindow.swift in Sources */,
E8E2AEFF257CB5AF00319BBC /* SpacemanStyle.swift in Sources */,
E8E2AEFF257CB5AF00319BBC /* DisplayStyle.swift in Sources */,
E828E6582737D2E4007075E8 /* Constants.swift in Sources */,
E7DA73A82CA6E7A700212836 /* GuiSize.swift in Sources */,
E828E6552737CBA0007075E8 /* VisualEffectView.swift in Sources */,
Expand Down Expand Up @@ -465,7 +465,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.6.16;
CURRENT_PROJECT_VERSION = 1.6.17;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Spaceman/Preview Content\"";
DEVELOPMENT_TEAM = "";
Expand All @@ -480,7 +480,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.6.16;
MARKETING_VERSION = 1.6.17;
PRODUCT_BUNDLE_IDENTIFIER = dev.ruittenb.Spaceman;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -499,7 +499,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.6.16;
CURRENT_PROJECT_VERSION = 1.6.17;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Spaceman/Preview Content\"";
DEVELOPMENT_TEAM = "";
Expand All @@ -514,7 +514,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.6.16;
MARKETING_VERSION = 1.6.17;
PRODUCT_BUNDLE_IDENTIFIER = dev.ruittenb.Spaceman;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
17 changes: 9 additions & 8 deletions Spaceman/Helpers/IconCreator.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// IconBuilder.swift
// IconCreator.swift
// Spaceman
//
// Created by Sasindu Jayasinghe on 23/11/20.
Expand All @@ -11,7 +11,7 @@ import SwiftUI

class IconCreator {
@AppStorage("layoutMode") private var layoutMode = LayoutMode.normal
@AppStorage("displayStyle") private var displayStyle = SpacemanStyle.numbersAndRects
@AppStorage("displayStyle") private var displayStyle = DisplayStyle.numbersAndRects
@AppStorage("hideInactiveSpaces") private var hideInactiveSpaces = false

private let leftMargin = CGFloat(7) /* FIXME determine actual left margin */
Expand All @@ -23,7 +23,7 @@ class IconCreator {
public var sizes: GuiSize!
public var iconWidths: [IconWidth] = []

func getIcon(for spaces: [Space]) -> NSImage {
public func getIcon(for spaces: [Space]) -> NSImage {
sizes = Constants.sizes[layoutMode]
gapWidth = CGFloat(sizes.GAP_WIDTH_SPACES)
displayGapWidth = CGFloat(sizes.GAP_WIDTH_DISPLAYS)
Expand Down Expand Up @@ -56,14 +56,15 @@ class IconCreator {
}

switch displayStyle {
case .rects:
//icons = resizeIcons(spaces, icons, layoutMode)
break
case .numbers:
icons = createNumberedIcons(spaces)
case .numbersAndRects:
icons = createRectWithNumbersIcons(icons, spaces)
case .names, .numbersAndNames:
icons = createNamedIcons(icons, spaces, withNumbers: displayStyle == .numbersAndNames)
default:
break
}

let iconsWithDisplayProperties = getIconsWithDisplayProps(icons: icons, spaces: spaces)
Expand All @@ -90,7 +91,7 @@ class IconCreator {
return newIcons
}

func createRectWithNumberIcon(icons: [NSImage], index: Int, space: Space, fraction: Float = 1.0) -> NSImage {
public func createRectWithNumberIcon(icons: [NSImage], index: Int, space: Space, fraction: Float = 1.0) -> NSImage {
iconSize.width = CGFloat(sizes.ICON_WIDTH_SMALL)

let textRect = NSRect(origin: CGPoint.zero, size: iconSize)
Expand Down Expand Up @@ -178,7 +179,7 @@ class IconCreator {
return newIcons
}

func getIconsWithDisplayProps(icons: [NSImage], spaces: [Space]) -> [(NSImage, Bool, Bool)] {
private func getIconsWithDisplayProps(icons: [NSImage], spaces: [Space]) -> [(NSImage, Bool, Bool)] {
var iconsWithDisplayProperties = [(NSImage, Bool, Bool)]()
var currentDisplayID = spaces[0].displayID
displayCount = 1
Expand All @@ -205,7 +206,7 @@ class IconCreator {
return iconsWithDisplayProperties
}

func mergeIcons(_ iconsWithDisplayProperties: [(image: NSImage, nextSpaceOnDifferentDisplay: Bool, isFullScreen: Bool)]) -> NSImage {
private func mergeIcons(_ iconsWithDisplayProperties: [(image: NSImage, nextSpaceOnDifferentDisplay: Bool, isFullScreen: Bool)]) -> NSImage {
let numIcons = iconsWithDisplayProperties.count
let combinedIconWidth = CGFloat(iconsWithDisplayProperties.reduce(0) { (result, icon) in
result + icon.image.size.width
Expand Down
4 changes: 2 additions & 2 deletions Spaceman/Helpers/SpaceObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ class SpaceObserver {
isCurrentSpace: isCurrentSpace,
isFullScreen: isFullScreen)

if let data = defaults.value(forKey:"spaceNames") as? Data,
let dict = try? PropertyListDecoder().decode(Dictionary<String, SpaceNameInfo>.self, from: data),
if let data = defaults.data(forKey: "spaceNames"),
let dict = try? PropertyListDecoder().decode([String: SpaceNameInfo].self, from: data),
let saved = dict[managedSpaceID]
{
space.spaceName = saved.spaceName
Expand Down
33 changes: 17 additions & 16 deletions Spaceman/Helpers/SpaceSwitcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SpaceSwitcher {
shortcutHelper = ShortcutHelper()
}

func switchToSpace(spaceNumber: Int, onError: () -> Void) {
public func switchToSpace(spaceNumber: Int, onError: () -> Void) {
let keyCode = shortcutHelper.getKeyCode(spaceNumber: spaceNumber)
if keyCode < 0 {
return onError()
Expand All @@ -28,13 +28,16 @@ class SpaceSwitcher {
scriptObject.executeAndReturnError(&error)
if error != nil {
let errorBriefMessage: String = error?[NSAppleScript.errorBriefMessage] as! String
self.alert(msg: "Error launching task: \(errorBriefMessage)\n")
let settingsName = self.systemSettingsName()
self.alert(
msg: "Error: \(errorBriefMessage)\n\nPlease grant Accessibility permissions to Spaceman in \(settingsName) → Privacy and Security.",
withSettingsButton: true)
}
}
}
}

func switchUsingLocation(iconWidths: [IconWidth], horizontal: CGFloat, onError: () -> Void) {
public func switchUsingLocation(iconWidths: [IconWidth], horizontal: CGFloat, onError: () -> Void) {
var index: Int = -1
for i in 0 ..< iconWidths.count {
if horizontal >= iconWidths[i].left && horizontal < iconWidths[i].right {
Expand All @@ -45,26 +48,24 @@ class SpaceSwitcher {
switchToSpace(spaceNumber: index, onError: onError)
}

func alert(msg: String) {
var settingsTitle: String
private func systemSettingsName() -> String {
if #available(macOS 13.0, *) {
settingsTitle = "Settings"
return "System Settings"
} else {
settingsTitle = "Preferences"
return "System Preferences"
}
}

private func alert(msg: String, withSettingsButton: Bool) {
DispatchQueue.main.async {
let alert = NSAlert.init()
var friendlyMsg: String
if let regex = try? NSRegularExpression(pattern: #"\d+:\d+: execution error: "#) {
let range = NSRange(msg.startIndex..., in: msg)
friendlyMsg = regex.stringByReplacingMatches(in: msg, options: [], range: range, withTemplate: "")
} else {
friendlyMsg = msg
}
alert.messageText = "Spaceman"
alert.informativeText = "\(friendlyMsg)\nPlease grant Accessibility permissions to Spaceman in System \(settingsTitle) → Privacy and Security."
alert.informativeText = "\(msg)"
alert.addButton(withTitle: "Dismiss")
alert.addButton(withTitle: "System \(settingsTitle)...")
if withSettingsButton {
let settingsName = self.systemSettingsName()
alert.addButton(withTitle: "\(settingsName)...")
}
let response = alert.runModal()
if (response == .alertSecondButtonReturn) {
let task = Process()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//
// SpacemanStyle.swift
// DisplayStyle.swift
// Spaceman
//
// Created by Sasindu Jayasinghe on 6/12/20.
//

import Foundation

enum SpacemanStyle: Int {
enum DisplayStyle: Int {
case rects, numbers, numbersAndRects, names, numbersAndNames
}
12 changes: 6 additions & 6 deletions Spaceman/View/PreferencesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct PreferencesView: View {

weak var parentWindow: PreferencesWindow!

@AppStorage("displayStyle") private var displayStyle = SpacemanStyle.numbersAndRects
@AppStorage("displayStyle") private var displayStyle = DisplayStyle.numbersAndRects
@AppStorage("spaceNames") private var data = Data()
@AppStorage("autoRefreshSpaces") private var autoRefreshSpaces = false
@AppStorage("layoutMode") private var layoutMode = LayoutMode.normal
Expand Down Expand Up @@ -189,11 +189,11 @@ struct PreferencesView: View {
// MARK: - Style Picker
private var spacesStylePicker: some View {
Picker(selection: $displayStyle, label: Text("Icon style")) {
Text("Rectangles").tag(SpacemanStyle.rects)
Text("Numbers").tag(SpacemanStyle.numbers)
Text("Rectangles with numbers").tag(SpacemanStyle.numbersAndRects)
Text("Names").tag(SpacemanStyle.names)
Text("Names with numbers").tag(SpacemanStyle.numbersAndNames)
Text("Rectangles").tag(DisplayStyle.rects)
Text("Numbers").tag(DisplayStyle.numbers)
Text("Rectangles with numbers").tag(DisplayStyle.numbersAndRects)
Text("Names").tag(DisplayStyle.names)
Text("Names with numbers").tag(DisplayStyle.numbersAndNames)
}
.onChange(of: displayStyle) { val in
if val == .rects {
Expand Down

0 comments on commit 4c0f283

Please sign in to comment.