Simplified process startup on macOS and Linux

This commit is contained in:
Conrad Kramer 2024-01-21 16:18:13 -08:00
parent 9e03c9680c
commit 7cc1f3119e
40 changed files with 1343 additions and 1157 deletions

View file

@ -0,0 +1,22 @@
@_implementationOnly import Constants
public enum Constants {
enum Error: Swift.Error {
case invalidAppGroupIdentifier
}
public static let bundleIdentifier = AppBundleIdentifier
public static let appGroupIdentifier = AppGroupIdentifier
public static var groupContainerURL: URL {
get throws { try _groupContainerURL.get() }
}
private static let _groupContainerURL: Result<URL, Error> = {
guard let groupContainerURL = FileManager.default
.containerURL(forSecurityApplicationGroupIdentifier: appGroupIdentifier) else {
return .failure(.invalidAppGroupIdentifier)
}
return .success(groupContainerURL)
}()
}

View file

@ -0,0 +1,11 @@
#import <Foundation/Foundation.h>
#define MACRO_STRING_(m) #m
#define MACRO_STRING(m) @MACRO_STRING_(m)
NS_ASSUME_NONNULL_BEGIN
static NSString * const AppBundleIdentifier = MACRO_STRING(APP_BUNDLE_IDENTIFIER);
static NSString * const AppGroupIdentifier = MACRO_STRING(APP_GROUP_IDENTIFIER);
NS_ASSUME_NONNULL_END

View file

@ -0,0 +1,4 @@
module Constants {
header "Constants.h"
export *
}

View file

@ -0,0 +1,19 @@
import os
@_exported import OSLog
extension Logger {
private static let loggers: OSAllocatedUnfairLock<[String: Logger]> = OSAllocatedUnfairLock(initialState: [:])
public static let subsystem = Constants.bundleIdentifier
public static func logger(for type: Any.Type) -> Logger {
let category = String(describing: type)
let logger = loggers.withLock { loggers in
if let logger = loggers[category] { return logger }
let logger = Logger(subsystem: subsystem, category: category)
loggers[category] = logger
return logger
}
return logger
}
}

View file

@ -0,0 +1,5 @@
PRODUCT_NAME = BurrowShared
MERGEABLE_LIBRARY = YES
SWIFT_INCLUDE_PATHS = $(PROJECT_DIR)/Shared/Constants
GCC_PREPROCESSOR_DEFINITIONS = APP_BUNDLE_IDENTIFIER=$(APP_BUNDLE_IDENTIFIER) APP_GROUP_IDENTIFIER=$(APP_GROUP_IDENTIFIER)