Skip to content

Commit

Permalink
Merge pull request #13 from v2ex/xcconfig-improvements
Browse files Browse the repository at this point in the history
Add build settings to xcconfig.
  • Loading branch information
kailuo authored Jan 19, 2022
2 parents c551a33 + e72896a commit f971c50
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 25 deletions.
2 changes: 2 additions & 0 deletions Helper-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
<dict>
<key>LSBackgroundOnly</key>
<true/>
<key>ORGANIZATION_IDENTIFIER_PREFIX</key>
<string>$(ORGANIZATION_IDENTIFIER_PREFIX)</string>
</dict>
</plist>
2 changes: 2 additions & 0 deletions Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ORGANIZATION_IDENTIFIER_PREFIX</key>
<string>$(ORGANIZATION_IDENTIFIER_PREFIX)</string>
<key>SUFeedURL</key>
<string>https://opensource.v2ex.pro/codelauncher/appcast.xml</string>
<key>SUPublicEDKey</key>
Expand Down
2 changes: 1 addition & 1 deletion Launcher Helper/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

func applicationDidFinishLaunching(_: Notification) {
let mainAppIdentifier = "com.v2ex.CodeLauncher"
let mainAppIdentifier = CLConfiguration.bundlePrefix + ".CodeLauncher"
let runningApps = NSWorkspace.shared.runningApplications
let isRunning = !runningApps.filter { $0.bundleIdentifier == mainAppIdentifier }.isEmpty

Expand Down
5 changes: 3 additions & 2 deletions Launcher.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
//

DEVELOPMENT_TEAM = 3SCMMGZXY8
CODE_SIGN_STYLE = Automatic
ORGANIZATION_IDENTIFIER = com.v2ex
ORGANIZATION_IDENTIFIER_PREFIX = com.v2ex
CODE_SIGN_IDENTITY = "Developer ID Application"
CODE_SIGN_STYLE = Manual

#include? "local.xcconfig"
46 changes: 26 additions & 20 deletions Launcher.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
2A64E8442746BBD800EB85C8 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A64E8432746BBD800EB85C8 /* Extensions.swift */; };
2A73821F276AF17A00E7ED27 /* CLVisualEffectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A73821E276AF17A00E7ED27 /* CLVisualEffectView.swift */; };
2A9B78162777960A00CA35AA /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = 2A9B78152777960A00CA35AA /* Sparkle */; };
2A9C30082797C195005DD27A /* CLConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A9C30072797C195005DD27A /* CLConfiguration.swift */; };
2A9C30092797C195005DD27A /* CLConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A9C30072797C195005DD27A /* CLConfiguration.swift */; };
2AACCCD027571C5400AC12F5 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AACCCCF27571C5400AC12F5 /* AppDelegate.swift */; };
2AACCCD227571C5400AC12F5 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AACCCD127571C5400AC12F5 /* ViewController.swift */; };
2AACCCD427571C5500AC12F5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2AACCCD327571C5500AC12F5 /* Assets.xcassets */; };
Expand Down Expand Up @@ -151,6 +153,7 @@
2A64E83F2746A96F00EB85C8 /* InfoPlist.strings */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; path = InfoPlist.strings; sourceTree = "<group>"; };
2A64E8432746BBD800EB85C8 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
2A73821E276AF17A00E7ED27 /* CLVisualEffectView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CLVisualEffectView.swift; sourceTree = "<group>"; };
2A9C30072797C195005DD27A /* CLConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CLConfiguration.swift; sourceTree = "<group>"; };
2AACCCCD27571C5400AC12F5 /* CodeLauncher Helper.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "CodeLauncher Helper.app"; sourceTree = BUILT_PRODUCTS_DIR; };
2AACCCCF27571C5400AC12F5 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
2AACCCD127571C5400AC12F5 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -211,6 +214,7 @@
isa = PBXGroup;
children = (
2A64E80027463E6C00EB85C8 /* CLApp.swift */,
2A9C30072797C195005DD27A /* CLConfiguration.swift */,
2A64E82D2746874A00EB85C8 /* Helper */,
2A64E8322746881B00EB85C8 /* Model */,
2A64E8352746901A00EB85C8 /* Views */,
Expand Down Expand Up @@ -449,6 +453,7 @@
2A11EB4A275A507F007E45FF /* CLSidebarOptionMenuView.swift in Sources */,
2A6057BA27493103001A68C7 /* CLProjectView.swift in Sources */,
2A64E83A2746905C00EB85C8 /* CLSidebarView.swift in Sources */,
2A9C30082797C195005DD27A /* CLConfiguration.swift in Sources */,
2A240E63275CCA200003F816 /* CLTaskItemView.swift in Sources */,
2ADEB32627887E6D00C622EF /* CLTaskStatusIndicatorView.swift in Sources */,
2AE29048274E987600619968 /* CLConsoleView.swift in Sources */,
Expand All @@ -475,6 +480,7 @@
2AACCCD227571C5400AC12F5 /* ViewController.swift in Sources */,
2AACCCDD27571ED600AC12F5 /* Extensions.swift in Sources */,
2AACCCD027571C5400AC12F5 /* AppDelegate.swift in Sources */,
2A9C30092797C195005DD27A /* CLConfiguration.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -668,10 +674,10 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Launcher/Launcher.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 104;
CURRENT_PROJECT_VERSION = 106;
DEVELOPMENT_ASSET_PATHS = "\"Launcher/Preview Content\"";
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
Expand All @@ -688,9 +694,9 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.3;
MARKETING_VERSION = 1.0.2;
MARKETING_VERSION = 1.0.3;
OTHER_CODE_SIGN_FLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = "$(ORGANIZATION_IDENTIFIER).CodeLauncher";
PRODUCT_BUNDLE_IDENTIFIER = "$(ORGANIZATION_IDENTIFIER_PREFIX).CodeLauncher";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -704,10 +710,10 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Launcher/Launcher.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 104;
CURRENT_PROJECT_VERSION = 106;
DEVELOPMENT_ASSET_PATHS = "\"Launcher/Preview Content\"";
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
Expand All @@ -724,9 +730,9 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.3;
MARKETING_VERSION = 1.0.2;
MARKETING_VERSION = 1.0.3;
OTHER_CODE_SIGN_FLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = "$(ORGANIZATION_IDENTIFIER).CodeLauncher";
PRODUCT_BUNDLE_IDENTIFIER = "$(ORGANIZATION_IDENTIFIER_PREFIX).CodeLauncher";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -740,10 +746,10 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = "Launcher Helper/Code_Launcher_Helper.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 104;
CURRENT_PROJECT_VERSION = 106;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Helper-Info.plist";
Expand All @@ -756,8 +762,8 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.3;
MARKETING_VERSION = 1.0.2;
PRODUCT_BUNDLE_IDENTIFIER = "$(ORGANIZATION_IDENTIFIER).CodeLauncher.helper";
MARKETING_VERSION = 1.0.3;
PRODUCT_BUNDLE_IDENTIFIER = "$(ORGANIZATION_IDENTIFIER_PREFIX).CodeLauncher.helper";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
Expand All @@ -772,10 +778,10 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = "Launcher Helper/Code_Launcher_Helper.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 104;
CURRENT_PROJECT_VERSION = 106;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Helper-Info.plist";
Expand All @@ -788,8 +794,8 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.3;
MARKETING_VERSION = 1.0.2;
PRODUCT_BUNDLE_IDENTIFIER = "$(ORGANIZATION_IDENTIFIER).CodeLauncher.helper";
MARKETING_VERSION = 1.0.3;
PRODUCT_BUNDLE_IDENTIFIER = "$(ORGANIZATION_IDENTIFIER_PREFIX).CodeLauncher.helper";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
Expand Down
41 changes: 41 additions & 0 deletions Launcher/CLConfiguration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// CLConfiguration.swift
// Launcher
//
// Created by Kai on 1/19/22.
//

import Foundation


enum CLConfiguration {
enum Error: Swift.Error {
case missingKey, invalidValue
}

private static func value<T>(for key: String) throws -> T where T: LosslessStringConvertible {
guard let object = Bundle.main.object(forInfoDictionaryKey:key) else {
throw Error.missingKey
}

switch object {
case let value as T:
return value
case let string as String:
guard let value = T(string) else { fallthrough }
return value
default:
throw Error.invalidValue
}
}

static var bundlePrefix: String {
let prefix: String
do {
prefix = try Self.value(for: "ORGANIZATION_IDENTIFIER_PREFIX")
} catch {
prefix = ""
}
return prefix
}
}
2 changes: 1 addition & 1 deletion Launcher/Helper/CLCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private extension Process {

environment = theEnvironment

let processQueue = DispatchQueue(label: "com.v2ex.codelauncher.async-command-output-queue")
let processQueue = DispatchQueue(label: CLConfiguration.bundlePrefix + ".codelauncher.async-command-output-queue")

var outputData = Data()
var errorData = Data()
Expand Down
2 changes: 1 addition & 1 deletion Launcher/Helper/CLTaskManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ class CLTaskManager: NSObject {
}

func updateLaunchOption() {
let launcherAppID = "com.v2ex.CodeLauncher.helper"
let launcherAppID = CLConfiguration.bundlePrefix + ".CodeLauncher.helper"
let runningApps = NSWorkspace.shared.runningApplications
let isRunning = !runningApps.filter { $0.bundleIdentifier == launcherAppID }.isEmpty
let currentLaunchOption = UserDefaults.standard.bool(forKey: String.settingsLaunchOptionKey)
Expand Down

0 comments on commit f971c50

Please sign in to comment.