Skip to content

Commit

Permalink
Make pane position and size configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-pennyworth committed Feb 24, 2024
1 parent ad425bf commit 1a6d6e2
Show file tree
Hide file tree
Showing 8 changed files with 265 additions and 34 deletions.
130 changes: 127 additions & 3 deletions AlfredExtraPane.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
D08B6EE7266F9B520099EB36 /* PanePositionCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = D08B6EE6266F9B520099EB36 /* PanePositionCodable.swift */; };
D08B6EEF26704DE30099EB36 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = D08B6EEE26704DE30099EB36 /* main.swift */; };
D08B6EFB267050900099EB36 /* wflist in CopyFiles */ = {isa = PBXBuildFile; fileRef = D08B6EEC26704DE20099EB36 /* wflist */; };
D0B3E0A42B8A1F3A008EA695 /* AlfredExtraPaneTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0B3E0A32B8A1F3A008EA695 /* AlfredExtraPaneTests.swift */; };
D0CE992A267057CA00DB243A /* Alfred in Frameworks */ = {isa = PBXBuildFile; productRef = D0CE9929267057CA00DB243A /* Alfred */; };
/* End PBXBuildFile section */

Expand All @@ -27,6 +28,13 @@
remoteGlobalIDString = D08B6EEB26704DE20099EB36;
remoteInfo = wflist;
};
D0B3E0A52B8A1F3A008EA695 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = D03EA8C725551E0400D3656E /* Project object */;
proxyType = 1;
remoteGlobalIDString = D03EA8CE25551E0400D3656E;
remoteInfo = AlfredExtraPane;
};
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -72,6 +80,8 @@
D08B6EE6266F9B520099EB36 /* PanePositionCodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PanePositionCodable.swift; sourceTree = "<group>"; };
D08B6EEC26704DE20099EB36 /* wflist */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = wflist; sourceTree = BUILT_PRODUCTS_DIR; };
D08B6EEE26704DE30099EB36 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
D0B3E0A12B8A1F39008EA695 /* AlfredExtraPaneTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AlfredExtraPaneTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
D0B3E0A32B8A1F3A008EA695 /* AlfredExtraPaneTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlfredExtraPaneTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -91,6 +101,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
D0B3E09E2B8A1F39008EA695 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
Expand All @@ -99,6 +116,7 @@
children = (
D03EA8D125551E0400D3656E /* AlfredExtraPane */,
D08B6EED26704DE30099EB36 /* wflist */,
D0B3E0A22B8A1F3A008EA695 /* AlfredExtraPaneTests */,
D03EA8D025551E0400D3656E /* Products */,
D03EA8EE2555664C00D3656E /* Frameworks */,
);
Expand All @@ -111,6 +129,7 @@
children = (
D03EA8CF25551E0400D3656E /* AlfredExtraPane.app */,
D08B6EEC26704DE20099EB36 /* wflist */,
D0B3E0A12B8A1F39008EA695 /* AlfredExtraPaneTests.xctest */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -144,6 +163,14 @@
path = wflist;
sourceTree = "<group>";
};
D0B3E0A22B8A1F3A008EA695 /* AlfredExtraPaneTests */ = {
isa = PBXGroup;
children = (
D0B3E0A32B8A1F3A008EA695 /* AlfredExtraPaneTests.swift */,
);
path = AlfredExtraPaneTests;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -190,13 +217,31 @@
productReference = D08B6EEC26704DE20099EB36 /* wflist */;
productType = "com.apple.product-type.tool";
};
D0B3E0A02B8A1F39008EA695 /* AlfredExtraPaneTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = D0B3E0A72B8A1F3A008EA695 /* Build configuration list for PBXNativeTarget "AlfredExtraPaneTests" */;
buildPhases = (
D0B3E09D2B8A1F39008EA695 /* Sources */,
D0B3E09E2B8A1F39008EA695 /* Frameworks */,
D0B3E09F2B8A1F39008EA695 /* Resources */,
);
buildRules = (
);
dependencies = (
D0B3E0A62B8A1F3A008EA695 /* PBXTargetDependency */,
);
name = AlfredExtraPaneTests;
productName = AlfredExtraPaneTests;
productReference = D0B3E0A12B8A1F39008EA695 /* AlfredExtraPaneTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
D03EA8C725551E0400D3656E /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1240;
LastSwiftUpdateCheck = 1520;
LastUpgradeCheck = 1240;
ORGANIZATIONNAME = "Mr. Pennyworth";
TargetAttributes = {
Expand All @@ -206,6 +251,10 @@
D08B6EEB26704DE20099EB36 = {
CreatedOnToolsVersion = 12.4;
};
D0B3E0A02B8A1F39008EA695 = {
CreatedOnToolsVersion = 15.2;
TestTargetID = D03EA8CE25551E0400D3656E;
};
};
};
buildConfigurationList = D03EA8CA25551E0400D3656E /* Build configuration list for PBXProject "AlfredExtraPane" */;
Expand All @@ -226,6 +275,7 @@
targets = (
D03EA8CE25551E0400D3656E /* AlfredExtraPane */,
D08B6EEB26704DE20099EB36 /* wflist */,
D0B3E0A02B8A1F39008EA695 /* AlfredExtraPaneTests */,
);
};
/* End PBXProject section */
Expand All @@ -239,6 +289,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
D0B3E09F2B8A1F39008EA695 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand All @@ -262,6 +319,14 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
D0B3E09D2B8A1F39008EA695 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D0B3E0A42B8A1F3A008EA695 /* AlfredExtraPaneTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
Expand All @@ -270,6 +335,11 @@
target = D08B6EEB26704DE20099EB36 /* wflist */;
targetProxy = D08B6EF8267050490099EB36 /* PBXContainerItemProxy */;
};
D0B3E0A62B8A1F3A008EA695 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = D03EA8CE25551E0400D3656E /* AlfredExtraPane */;
targetProxy = D0B3E0A52B8A1F3A008EA695 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

/* Begin XCBuildConfiguration section */
Expand Down Expand Up @@ -401,7 +471,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 0.1.2;
MARKETING_VERSION = 0.1.3;
ONLY_ACTIVE_ARCH = NO;
OTHER_CODE_SIGN_FLAGS = "--deep";
PRODUCT_BUNDLE_IDENTIFIER = mr.pennyworth.AlfredExtraPane;
Expand All @@ -422,7 +492,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 0.1.2;
MARKETING_VERSION = 0.1.3;
ONLY_ACTIVE_ARCH = NO;
OTHER_CODE_SIGN_FLAGS = "--deep";
PRODUCT_BUNDLE_IDENTIFIER = mr.pennyworth.AlfredExtraPane;
Expand Down Expand Up @@ -461,6 +531,51 @@
};
name = Release;
};
D0B3E0A82B8A1F3A008EA695 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GENERATE_INFOPLIST_FILE = YES;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MACOSX_DEPLOYMENT_TARGET = 14.2;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = mr.pennyworth.AlfredExtraPaneTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AlfredExtraPane.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/AlfredExtraPane";
};
name = Debug;
};
D0B3E0A92B8A1F3A008EA695 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GENERATE_INFOPLIST_FILE = YES;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MACOSX_DEPLOYMENT_TARGET = 14.2;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = mr.pennyworth.AlfredExtraPaneTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AlfredExtraPane.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/AlfredExtraPane";
};
name = Release;
};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
Expand Down Expand Up @@ -491,6 +606,15 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
D0B3E0A72B8A1F3A008EA695 /* Build configuration list for PBXNativeTarget "AlfredExtraPaneTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
D0B3E0A82B8A1F3A008EA695 /* Debug */,
D0B3E0A92B8A1F3A008EA695 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D0B3E0A02B8A1F39008EA695"
BuildableName = "AlfredExtraPaneTests.xctest"
BlueprintName = "AlfredExtraPaneTests"
ReferencedContainer = "container:AlfredExtraPane.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
12 changes: 6 additions & 6 deletions AlfredExtraPane/Pane.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import Cocoa
import Foundation
import WebKit

enum PanePosition {
enum HorizontalPosition: String, Codable, CodingKey { case left, right }
enum VerticalPosition: String, Codable, CodingKey { case top, bottom }
enum PanePosition: Equatable {
enum HorizontalPlacement: String, Codable, CodingKey { case left, right }
enum VerticalPlacement: String, Codable, CodingKey { case top, bottom }

case horizontal(placement: HorizontalPosition, width: Int, minHeight: Int?)
case vertical(placement: VerticalPosition, height: Int)
case horizontal(placement: HorizontalPlacement, width: Int, minHeight: Int?)
case vertical(placement: VerticalPlacement, height: Int)
}

struct PaneConfig: Codable {
public struct PaneConfig: Codable, Equatable {
let alignment: PanePosition
let workflowUID: String
}
Expand Down
4 changes: 2 additions & 2 deletions AlfredExtraPane/PanePositionCodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension PanePosition: Codable {
forKey: .vertical
)
let placement = try nested.decode(
VerticalPosition.self,
VerticalPlacement.self,
forKey: .placement
)
let height = try nested.decode(Int.self, forKey: .height)
Expand All @@ -25,7 +25,7 @@ extension PanePosition: Codable {
forKey: .horizontal
)
let placement = try nested.decode(
HorizontalPosition.self,
HorizontalPlacement.self,
forKey: .placement
)
let width = try nested.decode(Int.self, forKey: .width)
Expand Down
63 changes: 41 additions & 22 deletions AlfredExtraPane/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@ import Foundation


class AppDelegate: NSObject, NSApplicationDelegate {
let panes: [Pane]
let defaultConfig: PaneConfig = PaneConfig(
var panes: [Pane] = []
private let defaultConfig = PaneConfig(
alignment: .horizontal(placement: .right, width: 300, minHeight: 400),
workflowUID: "*"
)

init(_ configFilePath: URL?) {
var configs: [PaneConfig] = []
if let configFilePath = configFilePath {
configs = read(contentsOf: configFilePath) ?? []
} else {
log("Loading default catchall-config")
configs = [defaultConfig]
}
panes = configs.map { Pane(config: $0) }
override init() {
super.init()
let confs: [PaneConfig] =
(try? read(contentsOf: configFile())) ?? [defaultConfig]
panes = confs.map { Pane(config: $0) }
}

func application(_ application: NSApplication, open urls: [URL]) {
Expand All @@ -27,21 +23,44 @@ class AppDelegate: NSObject, NSApplicationDelegate {
log("\(url.queryParameters)")
}
}
}

autoreleasepool {
let app = NSApplication.shared
let args = CommandLine.arguments.suffix(from: 1)
var configFilePath: URL? = nil
if let configPath: String = args.first {
if FileManager().fileExists(atPath: configPath) {
configFilePath = URL(fileURLWithPath: configPath)
func appSupportDir() throws -> URL {
let fs = FileManager.default
let appSupportURL = try fs.url(
for: .applicationSupportDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: true
)

let bundleID = Bundle.main.bundleIdentifier!
let appDir = appSupportURL.appendingPathComponent(bundleID)

if !fs.fileExists(atPath: appDir.path) {
try fs.createDirectory(
at: appDir,
withIntermediateDirectories: true,
attributes: nil
)
}

return appDir
}
if configFilePath == nil {
log("No config file path provided. args: \(args)")

func configFile() throws -> URL {
let fs = FileManager.default
let conf = try! appSupportDir().appendingPathComponent("config.json")
if !fs.fileExists(atPath: conf.path) {
write([defaultConfig], to: conf)
}
return conf
}
let delegate = AppDelegate(configFilePath)
}

autoreleasepool {
let app = NSApplication.shared
let delegate = AppDelegate()
print("\(delegate.panes)")
app.setActivationPolicy(.accessory)
app.delegate = delegate
app.run()
Expand Down
Loading

0 comments on commit 1a6d6e2

Please sign in to comment.