Skip to content

Commit

Permalink
Dropped some dependencies/upgraded to macOS 12. (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
grigorye authored Dec 2, 2023
2 parents 02bfcc5 + d0dada6 commit 14e3f10
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 713 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/Pods/
*.xcodeproj
9 changes: 0 additions & 9 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
[submodule "Submodules/GETracing"]
path = Submodules/GETracing
url = https://github.com/grigorye/GETracing
[submodule "Submodules/GEFoundation"]
path = Submodules/GEFoundation
url = https://github.com/grigorye/GEFoundation
[submodule "Submodules/Then"]
path = Submodules/Then
url = https://github.com/devxoul/Then
[submodule "Submodules/ReusableWorkflows"]
path = Submodules/ReusableWorkflows
url = https://github.com/grigorye/ReusableWorkflows
5 changes: 5 additions & 0 deletions Commands/GenerateProject
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
#! /bin/bash

set -x
set -euo pipefail

mint run xcodegen
8 changes: 8 additions & 0 deletions GHAShortcuts/MintBootstrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/bash

set -x
set -euo pipefail

brew install mint

mint bootstrap
1 change: 0 additions & 1 deletion Submodules/GEFoundation
Submodule GEFoundation deleted from 195174
1 change: 0 additions & 1 deletion Submodules/GETracing
Submodule GETracing deleted from 86ba1b
1 change: 0 additions & 1 deletion Submodules/Then
Submodule Then deleted from d41ef5
5 changes: 0 additions & 5 deletions URLHelperApp.xcodeproj/.xcodesamplecode.plist

This file was deleted.

415 changes: 0 additions & 415 deletions URLHelperApp.xcodeproj/project.pbxproj

This file was deleted.

This file was deleted.

This file was deleted.

139 changes: 28 additions & 111 deletions URLHelperApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,35 @@
// Copyright © 2018 Grigory Entin. All rights reserved.
//

import GEFoundation
import GETracing
import Cocoa
import os.log

extension TypedUserDefaults {

@NSManaged var openMethod: String?

enum OpenMethod : String {
case openURLsWithAppBundleIdentifier
case openURLsWithApplicationAtURL
}

var openMethodValue: OpenMethod? {
guard let rawValue = defaults.openMethod else {
return nil
}
return OpenMethod(rawValue: rawValue)
}
}

extension TypedUserDefaults.OpenMethod {
static let `default`: TypedUserDefaults.OpenMethod = .openURLsWithApplicationAtURL
}
private let log = Logger(subsystem: "AppDelegate", category: "")

private let urlToAppMapper: URLToAppMapper = ScriptBasedURLToAppMapper()

@NSApplicationMain
class AppDelegate : NSObject, NSApplicationDelegate {

override init() {
_ = initializeDefaults
super.init()
func applicationDidFinishLaunching(_ notification: Notification) {
log.info("Did finish launching.")
}

func application(_ application: NSApplication, open urls: [URL]) {
x$(urls)
log.info("Opening \(urls).")
let task = Task {
let urlsByAppBundleIdentifier = try await resolve(urls)
for (appBundleIdentifier, urls) in urlsByAppBundleIdentifier {
try open(urls, withAppWithBundleIdentifier: appBundleIdentifier)
try await open(urls, withAppWithBundleIdentifier: appBundleIdentifier)
}
}
Task {
let result = await task.result
x$(result)
do {
try await task.result.get()
log.info("Succeeded with opening \(urls).")
} catch {
log.error("Failed to open \(urls): \(error).")
}
}
}
}
Expand All @@ -71,100 +54,34 @@ private func resolve(_ urls: [URL]) async throws -> [String: [URL]] {
}
}

private func open(_ urls: [URL], withAppWithBundleIdentifier appBundleIdentifier: String) throws {

switch defaults.openMethodValue ?? .default {
case .openURLsWithAppBundleIdentifier:
open(urls: urls, withAppWithBundleIdentifier: appBundleIdentifier)
case .openURLsWithApplicationAtURL:
try open(urls: urls, resolvingAppWithBundleIdentifier: appBundleIdentifier)
}
}

struct OpenURLsWithAppWithBundleIdentifier : Action {
typealias Input = (urls: [URL], appBundleIdentifier: String)
typealias SuccessResult = ()
typealias FailureResult = Error

enum Error: Swift.Error {
case workspaceFailedToOpenApp
}
}

private func open(urls: [URL], withAppWithBundleIdentifier appBundleIdentifier: String) {

let action = OpenURLsWithAppWithBundleIdentifier()
track(will: action, with: (urls: urls, appBundleIdentifier: appBundleIdentifier))
let succeeded = workspace.open(urls, withAppBundleIdentifier: appBundleIdentifier, options: .withErrorPresentation, additionalEventParamDescriptor: nil, launchIdentifiers: nil)
if succeeded {
track(succeeded: action, with: ())
} else {
track(failed: action, due: .workspaceFailedToOpenApp)
}
}

private func open(urls: [URL], resolvingAppWithBundleIdentifier appBundleIdentifier: String) throws {

let appURL = try resolveAppURL(forBundleIdentifier: appBundleIdentifier)
open(urls: urls, withAppAtURL: appURL)
}

struct OpenURLsWithAppAtURL : Action {
typealias Input = (urls: [URL], appURL: URL)
typealias SuccessResult = (NSRunningApplication)
typealias FailureResult = Error
}

private func open(urls: [URL], withAppAtURL appURL: URL) {

let action = OpenURLsWithAppAtURL()
track(will: action, with: (urls: urls, appURL: appURL))
do {
let runningApp = try workspace.open(urls, withApplicationAt: appURL, options: .withErrorPresentation, configuration: [:])
track(succeeded: action, with: (runningApp))
} catch {
track(failed: action, due: error)
private func open(_ urls: [URL], withAppWithBundleIdentifier appBundleIdentifier: String) async throws {
guard let appURL = resolveAppURL(forBundleIdentifier: appBundleIdentifier) else {
return
}
try await open(urls: urls, withAppAtURL: appURL)
}

struct ResolveAppForBundleIdentifier : Action {
typealias Input = String
typealias SuccessResult = URL
typealias FailureResult = Error
}

private func resolveAppURL(forBundleIdentifier bundleIdentifier: String) throws -> URL {

let action = ResolveAppForBundleIdentifier()
track(will: action, with: bundleIdentifier)
private func open(urls: [URL], withAppAtURL appURL: URL) async throws {
log.info("Using \(appURL) to open \(urls).")
let configuration = NSWorkspace.OpenConfiguration()
configuration.promptsUserIfNeeded = true
do {
let appURL = try resolveAppURLWithWorkspace(forBundleIdentifier: bundleIdentifier)
track(succeeded: action, with: appURL)
return appURL
try await workspace.open(urls, withApplicationAt: appURL, configuration: configuration)
log.info("Succeeded with using \(appURL) to open \(urls).")
} catch {
track(failed: action, due: error)
log.error("Failed to use \(appURL) to open \(urls): \(error).")
throw error
}
}

private func resolveAppURLWithWorkspace(forBundleIdentifier bundleIdentifier: String) throws -> URL {

enum Error: Swift.Error {
case couldNotLocateApplication(bundleIdentifier: String)
}

private func resolveAppURL(forBundleIdentifier bundleIdentifier: String) -> URL? {
log.info("Resolving URL for app bundle identifier \(bundleIdentifier).")
guard let appURL = workspace.urlForApplication(withBundleIdentifier: bundleIdentifier) else {
throw Error.couldNotLocateApplication(bundleIdentifier: bundleIdentifier)
log.error("Could not get URL for app with bundle identifier \(bundleIdentifier).")
return nil
}
log.info("Resolved app bundle identifier \(bundleIdentifier) into \(appURL).")
return appURL
}

private let workspace = NSWorkspace()

private let initializeDefaults: Void = {
#if false
traceEnabledEnforced = true
sourceLabelsEnabledEnforced = true
#endif
x$(())
}()
8 changes: 5 additions & 3 deletions URLHelperApp/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="22155" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.18"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22155"/>
</dependencies>
<scenes>
<!--Application-->
Expand Down Expand Up @@ -618,7 +619,7 @@
<menuItem title="Show Sidebar" keyEquivalent="s" id="kIP-vf-haE">
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
<connections>
<action selector="toggleSourceList:" target="Ady-hI-5gd" id="iwa-gc-5KM"/>
<action selector="toggleSidebar:" target="Ady-hI-5gd" id="iwa-gc-5KM"/>
</connections>
</menuItem>
<menuItem title="Enter Full Screen" keyEquivalent="f" id="4J7-dP-txa">
Expand All @@ -640,6 +641,7 @@
</connections>
</menuItem>
<menuItem title="Zoom" keyEquivalent="/" id="R4o-n2-Eq4">
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
<connections>
<action selector="performZoom:" target="Ady-hI-5gd" id="DIl-cC-cCs"/>
</connections>
Expand Down
39 changes: 0 additions & 39 deletions URLHelperApp/EventTracking.swift

This file was deleted.

Loading

0 comments on commit 14e3f10

Please sign in to comment.