This commit is contained in:
Sindre Sorhus 2018-03-02 03:05:19 +07:00
commit 2fd7035c8c
17 changed files with 947 additions and 0 deletions

8
.editorconfig Normal file
View File

@ -0,0 +1,8 @@
root = true
[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
* text=auto
*.swift text eol=lf

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/.build
/Packages
xcuserdata
project.xcworkspace

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>0.0.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>

View File

@ -0,0 +1,454 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 48;
objects = {
/* Begin PBXAggregateTarget section */
"DockProgress::DockProgressPackageTests::ProductTarget" /* DockProgressPackageTests */ = {
isa = PBXAggregateTarget;
buildConfigurationList = OBJ_39 /* Build configuration list for PBXAggregateTarget "DockProgressPackageTests" */;
buildPhases = (
);
dependencies = (
OBJ_42 /* PBXTargetDependency */,
);
name = DockProgressPackageTests;
productName = DockProgressPackageTests;
};
/* End PBXAggregateTarget section */
/* Begin PBXBuildFile section */
E392EC542048876F00AB7097 /* util.swift in Sources */ = {isa = PBXBuildFile; fileRef = E392EC532048876F00AB7097 /* util.swift */; };
OBJ_21 /* Package.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_6 /* Package.swift */; };
OBJ_27 /* DockProgressTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_12 /* DockProgressTests.swift */; };
OBJ_29 /* DockProgress.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "DockProgress::DockProgress::Product" /* DockProgress.framework */; };
OBJ_36 /* DockProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_9 /* DockProgress.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
E392EC512048868200AB7097 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = OBJ_1 /* Project object */;
proxyType = 1;
remoteGlobalIDString = "DockProgress::DockProgress";
remoteInfo = DockProgress;
};
E392EC522048868200AB7097 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = OBJ_1 /* Project object */;
proxyType = 1;
remoteGlobalIDString = "DockProgress::DockProgressTests";
remoteInfo = DockProgressTests;
};
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
"DockProgress::DockProgress::Product" /* DockProgress.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = DockProgress.framework; sourceTree = BUILT_PRODUCTS_DIR; };
"DockProgress::DockProgressTests::Product" /* DockProgressTests.xctest */ = {isa = PBXFileReference; lastKnownFileType = file; path = DockProgressTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
E392EC532048876F00AB7097 /* util.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = util.swift; sourceTree = "<group>"; usesTabs = 1; };
OBJ_12 /* DockProgressTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DockProgressTests.swift; sourceTree = "<group>"; };
OBJ_6 /* Package.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; fileEncoding = 4; lineEnding = 0; path = Package.swift; sourceTree = "<group>"; usesTabs = 1; };
OBJ_9 /* DockProgress.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = DockProgress.swift; sourceTree = "<group>"; usesTabs = 1; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
OBJ_28 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 0;
files = (
OBJ_29 /* DockProgress.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
OBJ_37 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 0;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
OBJ_10 /* Tests */ = {
isa = PBXGroup;
children = (
OBJ_11 /* DockProgressTests */,
);
name = Tests;
sourceTree = SOURCE_ROOT;
};
OBJ_11 /* DockProgressTests */ = {
isa = PBXGroup;
children = (
OBJ_12 /* DockProgressTests.swift */,
);
name = DockProgressTests;
path = Tests/DockProgressTests;
sourceTree = SOURCE_ROOT;
};
OBJ_13 /* Products */ = {
isa = PBXGroup;
children = (
"DockProgress::DockProgressTests::Product" /* DockProgressTests.xctest */,
"DockProgress::DockProgress::Product" /* DockProgress.framework */,
);
name = Products;
sourceTree = BUILT_PRODUCTS_DIR;
};
OBJ_5 = {
isa = PBXGroup;
children = (
OBJ_6 /* Package.swift */,
OBJ_7 /* Sources */,
OBJ_10 /* Tests */,
OBJ_13 /* Products */,
);
sourceTree = "<group>";
usesTabs = 1;
};
OBJ_7 /* Sources */ = {
isa = PBXGroup;
children = (
OBJ_8 /* DockProgress */,
);
name = Sources;
sourceTree = SOURCE_ROOT;
};
OBJ_8 /* DockProgress */ = {
isa = PBXGroup;
children = (
OBJ_9 /* DockProgress.swift */,
E392EC532048876F00AB7097 /* util.swift */,
);
name = DockProgress;
path = Sources/DockProgress;
sourceTree = SOURCE_ROOT;
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
"DockProgress::DockProgress" /* DockProgress */ = {
isa = PBXNativeTarget;
buildConfigurationList = OBJ_32 /* Build configuration list for PBXNativeTarget "DockProgress" */;
buildPhases = (
OBJ_35 /* Sources */,
OBJ_37 /* Frameworks */,
);
buildRules = (
);
dependencies = (
);
name = DockProgress;
productName = DockProgress;
productReference = "DockProgress::DockProgress::Product" /* DockProgress.framework */;
productType = "com.apple.product-type.framework";
};
"DockProgress::DockProgressTests" /* DockProgressTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = OBJ_23 /* Build configuration list for PBXNativeTarget "DockProgressTests" */;
buildPhases = (
OBJ_26 /* Sources */,
OBJ_28 /* Frameworks */,
);
buildRules = (
);
dependencies = (
OBJ_30 /* PBXTargetDependency */,
);
name = DockProgressTests;
productName = DockProgressTests;
productReference = "DockProgress::DockProgressTests::Product" /* DockProgressTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
"DockProgress::SwiftPMPackageDescription" /* DockProgressPackageDescription */ = {
isa = PBXNativeTarget;
buildConfigurationList = OBJ_17 /* Build configuration list for PBXNativeTarget "DockProgressPackageDescription" */;
buildPhases = (
OBJ_20 /* Sources */,
);
buildRules = (
);
dependencies = (
);
name = DockProgressPackageDescription;
productName = DockProgressPackageDescription;
productType = "com.apple.product-type.framework";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
OBJ_1 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 9999;
};
buildConfigurationList = OBJ_2 /* Build configuration list for PBXProject "DockProgress" */;
compatibilityVersion = "Xcode 8.0";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
mainGroup = OBJ_5;
productRefGroup = OBJ_13 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
"DockProgress::SwiftPMPackageDescription" /* DockProgressPackageDescription */,
"DockProgress::DockProgressTests" /* DockProgressTests */,
"DockProgress::DockProgress" /* DockProgress */,
"DockProgress::DockProgressPackageTests::ProductTarget" /* DockProgressPackageTests */,
);
};
/* End PBXProject section */
/* Begin PBXSourcesBuildPhase section */
OBJ_20 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 0;
files = (
OBJ_21 /* Package.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
OBJ_26 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 0;
files = (
OBJ_27 /* DockProgressTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
OBJ_35 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 0;
files = (
OBJ_36 /* DockProgress.swift in Sources */,
E392EC542048876F00AB7097 /* util.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
OBJ_30 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = "DockProgress::DockProgress" /* DockProgress */;
targetProxy = E392EC512048868200AB7097 /* PBXContainerItemProxy */;
};
OBJ_42 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = "DockProgress::DockProgressTests" /* DockProgressTests */;
targetProxy = E392EC522048868200AB7097 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin XCBuildConfiguration section */
OBJ_18 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
LD = /usr/bin/true;
OTHER_SWIFT_FLAGS = "-swift-version 4 -I /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4 -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk";
SWIFT_VERSION = 4.0;
};
name = Debug;
};
OBJ_19 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
LD = /usr/bin/true;
OTHER_SWIFT_FLAGS = "-swift-version 4 -I /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4 -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk";
SWIFT_VERSION = 4.0;
};
name = Release;
};
OBJ_24 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
);
HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = DockProgress.xcodeproj/DockProgressTests_Info.plist;
LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks @loader_path/Frameworks";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
SWIFT_VERSION = 4.0;
TARGET_NAME = DockProgressTests;
};
name = Debug;
};
OBJ_25 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
);
HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = DockProgress.xcodeproj/DockProgressTests_Info.plist;
LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks @loader_path/Frameworks";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
SWIFT_VERSION = 4.0;
TARGET_NAME = DockProgressTests;
};
name = Release;
};
OBJ_3 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_NS_ASSERTIONS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
MACOSX_DEPLOYMENT_TARGET = 10.10;
ONLY_ACTIVE_ARCH = YES;
OTHER_SWIFT_FLAGS = "-DXcode";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SUPPORTED_PLATFORMS = macosx;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
USE_HEADERMAP = NO;
};
name = Debug;
};
OBJ_33 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ENABLE_TESTABILITY = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
);
HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = DockProgress.xcodeproj/DockProgress_Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = DockProgress;
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
TARGET_NAME = DockProgress;
};
name = Debug;
};
OBJ_34 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ENABLE_TESTABILITY = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
);
HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = DockProgress.xcodeproj/DockProgress_Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = DockProgress;
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
TARGET_NAME = DockProgress;
};
name = Release;
};
OBJ_4 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DYLIB_INSTALL_NAME_BASE = "@rpath";
GCC_OPTIMIZATION_LEVEL = s;
MACOSX_DEPLOYMENT_TARGET = 10.10;
OTHER_SWIFT_FLAGS = "-DXcode";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SUPPORTED_PLATFORMS = macosx;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
USE_HEADERMAP = NO;
};
name = Release;
};
OBJ_40 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
};
name = Debug;
};
OBJ_41 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
OBJ_17 /* Build configuration list for PBXNativeTarget "DockProgressPackageDescription" */ = {
isa = XCConfigurationList;
buildConfigurations = (
OBJ_18 /* Debug */,
OBJ_19 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Debug;
};
OBJ_2 /* Build configuration list for PBXProject "DockProgress" */ = {
isa = XCConfigurationList;
buildConfigurations = (
OBJ_3 /* Debug */,
OBJ_4 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Debug;
};
OBJ_23 /* Build configuration list for PBXNativeTarget "DockProgressTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
OBJ_24 /* Debug */,
OBJ_25 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Debug;
};
OBJ_32 /* Build configuration list for PBXNativeTarget "DockProgress" */ = {
isa = XCConfigurationList;
buildConfigurations = (
OBJ_33 /* Debug */,
OBJ_34 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Debug;
};
OBJ_39 /* Build configuration list for PBXAggregateTarget "DockProgressPackageTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
OBJ_40 /* Debug */,
OBJ_41 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Debug;
};
/* End XCConfigurationList section */
};
rootObject = OBJ_1 /* Project object */;
}

View File

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "9999"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DockProgress::DockProgress"
BuildableName = "DockProgress.framework"
BlueprintName = "DockProgress"
ReferencedContainer = "container:DockProgress.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DockProgress::DockProgressTests"
BuildableName = "DockProgressTests.xctest"
BlueprintName = "DockProgressTests"
ReferencedContainer = "container:DockProgress.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DockProgress::DockProgress"
BuildableName = "DockProgress.framework"
BlueprintName = "DockProgress"
ReferencedContainer = "container:DockProgress.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>DockProgress-Package.xcscheme</key>
<dict></dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict></dict>
</dict>
</plist>

18
Package.swift Normal file
View File

@ -0,0 +1,18 @@
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "DockProgress",
products: [
.library(
name: "DockProgress",
targets: ["DockProgress"]),
],
targets: [
.target(
name: "DockProgress"
.testTarget(
name: "DockProgressTests",
dependencies: ["DockProgress"]),
]
)

View File

@ -0,0 +1,102 @@
import Cocoa
public final class DockProgress {
private static let appIcon = NSApp.applicationIconImage!
private static var previousProgressValue: Double = 0
private static var progressObserver: NSKeyValueObservation?
private static var dockImageView = with(NSImageView()) {
NSApp.dockTile.contentView = $0
}
public static var progress: Progress? {
didSet {
if let progress = progress {
progressObserver = progress.observe(\.fractionCompleted) { object, _ in
progressValue = object.fractionCompleted
}
}
}
}
public static var progressValue: Double = 0 {
didSet {
if previousProgressValue == 0 || (progressValue - previousProgressValue).magnitude > 0.001 {
previousProgressValue = progressValue
updateDockIcon()
}
}
}
public enum ProgressStyle {
case bar
/// TODO: Make `color` optional when https://github.com/apple/swift-evolution/blob/master/proposals/0155-normalize-enum-case-representation.md is shipping in Swift
case circle(radius: Double, color: NSColor)
case custom(drawHandler: (_ rect: CGRect) -> Void)
}
public static var style: ProgressStyle = .bar
/// TODO: Make the progress smoother by also animating the steps between each call to `updateDockIcon()`
private static func updateDockIcon() {
DispatchQueue.global(qos: .utility).async {
/// TODO: If the `progressValue` is 1, draw the full circle, then schedule another draw in n milliseconds to hide it
let icon = (0..<1).contains(self.progressValue) ? self.draw() : appIcon
DispatchQueue.main.async {
/// TODO: Make this better by drawing in the `contentView` directly instead of using an image
dockImageView.image = icon
NSApp.dockTile.display()
}
}
}
private static func draw() -> NSImage {
return NSImage(size: appIcon.size, flipped: false) { dstRect in
NSGraphicsContext.current?.imageInterpolation = .high
self.appIcon.draw(in: dstRect)
switch self.style {
case .bar:
self.drawProgressBar(dstRect)
case let .circle(radius, color):
self.drawProgressCircle(dstRect, radius: radius, color: color)
case let .custom(drawingHandler):
drawingHandler(dstRect)
}
return true
}
}
private static func drawProgressBar(_ dstRect: CGRect) {
func roundedRect(_ rect: CGRect) {
NSBezierPath(roundedRect: rect, cornerRadius: rect.height / 2).fill()
}
let bar = CGRect(x: 0, y: 20, width: dstRect.width, height: 10)
NSColor.white.with(alpha: 0.8).set()
roundedRect(bar)
let barInnerBg = bar.insetBy(dx: 0.5, dy: 0.5)
NSColor.black.with(alpha: 0.8).set()
roundedRect(barInnerBg)
var barProgress = bar.insetBy(dx: 1, dy: 1)
barProgress.size.width = barProgress.width * CGFloat(self.progressValue)
NSColor.white.set()
roundedRect(barProgress)
}
private static func drawProgressCircle(_ dstRect: CGRect, radius: Double, color: NSColor) {
guard let cgContext = NSGraphicsContext.current?.cgContext else {
return
}
let progressCircle = ProgressCircleShapeLayer(radius: radius, center: dstRect.center)
progressCircle.strokeColor = color.cgColor
progressCircle.lineWidth = 4
progressCircle.cornerRadius = 3
progressCircle.progress = progressValue
progressCircle.render(in: cgContext)
}
}

View File

@ -0,0 +1,107 @@
import Cocoa
/**
Convenience function for initializing an object and modifying its properties
```
let label = with(NSTextField()) {
$0.stringValue = "Foo"
$0.textColor = .systemBlue
view.addSubview($0)
}
```
*/
@discardableResult
func with<T>(_ item: T, update: (inout T) throws -> Void) rethrows -> T {
var this = item
try update(&this)
return this
}
extension NSBezierPath {
static func progressCircle(radius: Double, center: CGPoint) -> NSBezierPath {
let startAngle: CGFloat = 90
let path = NSBezierPath()
path.appendArc(
withCenter: center,
radius: CGFloat(radius),
startAngle: startAngle,
endAngle: startAngle - 360,
clockwise: true
)
return path
}
}
final class ProgressCircleShapeLayer: CAShapeLayer {
convenience init(radius: Double, center: CGPoint) {
self.init()
fillColor = nil
lineCap = kCALineCapRound
path = NSBezierPath.progressCircle(radius: radius, center: center).cgPath
}
var progress: Double {
get {
return Double(strokeEnd)
}
set {
strokeEnd = CGFloat(newValue)
}
}
}
extension NSColor {
func with(alpha: Double) -> NSColor {
return withAlphaComponent(CGFloat(alpha))
}
}
extension CGRect {
var center: CGPoint {
get {
return CGPoint(x: midX, y: midY)
}
set {
origin = CGPoint(
x: newValue.x - (size.width / 2),
y: newValue.y - (size.height / 2)
)
}
}
}
extension NSBezierPath {
/// UIKit polyfill
var cgPath: CGPath {
let path = CGMutablePath()
var points = [CGPoint](repeating: .zero, count: 3)
for i in 0..<elementCount {
let type = element(at: i, associatedPoints: &points)
switch type {
case .moveToBezierPathElement:
path.move(to: points[0])
case .lineToBezierPathElement:
path.addLine(to: points[0])
case .curveToBezierPathElement:
path.addCurve(to: points[2], control1: points[0], control2: points[1])
case .closePathBezierPathElement:
path.closeSubpath()
}
}
return path
}
/// UIKit polyfill
convenience init(roundedRect rect: CGRect, cornerRadius: CGFloat) {
self.init(roundedRect: rect, xRadius: cornerRadius, yRadius: cornerRadius)
}
}

View File

@ -0,0 +1,6 @@
import XCTest
@testable import DockProgress
final class DockProgressTests: XCTestCase {
func testDockProgress() {}
}

9
license Normal file
View File

@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

96
readme.md Normal file
View File

@ -0,0 +1,96 @@
# DockProgress
> Show progress in your app's Dock icon
<img src="screenshot.gif" width="485">
This package is used in production by the [Gifski app](https://github.com/sindresorhus/gifski-app).
## Requirements
- macOS 10.12+
- Xcode 9+
- Swift 4+
## Install
With [SPM](https://swift.org/package-manager/):
```swift
.package(url: "https://github.com/sindresorhus/DockProgress", from: "1.0.0")
```
With [Carthage](https://swift.org/package-manager/):
```
github "sindresorhus/DockProgress"
```
## Usage
### Manually set the progress
```swift
import Cocoa
import DockProgress
foo.onUpdate = { progress
DockProgress.progressValue = progress
}
```
### Specify a [`Progress`](https://developer.apple.com/documentation/foundation/progress) instance
```swift
import Cocoa
import DockProgress
let progress = Progress(totalUnitCount: 1)
progress?.becomeCurrent(withPendingUnitCount: 1)
DockProgress.progress = progress
```
## Styles
It comes with two styles. PR welcome for more.
You can also draw a custom progress with `.custom(drawHandler: (_ rect: CGRect) -> Void)`.
### Bar
![](screenshot-bar.gif)
```swift
import DockProgress
DockProgress.style = .bar
```
This is the default.
### Circle
![](screenshot-circle.gif)
```swift
import DockProgress
DockProgress.style = .circle(radius: 55, color: .systemBlue)
```
Make sure to set a `radius` that matches your app icon.
## Related
- [LaunchAtLogin](https://github.com/sindresorhus/LaunchAtLogin) - Add "Launch at Login" functionality to your macOS app
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)

BIN
screenshot-bar.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 598 KiB

BIN
screenshot-circle.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 693 KiB

BIN
screenshot.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 617 KiB