在应用的 Dock 图标中显示进度

码头进度

在应用的 Dock 图标中显示进度

此包由 Gifski 应用程序在生产中使用。您可能还喜欢我的其他一些应用程序

要求

  • macOS 10.12+
  • Xcode 12+
  • 斯威夫特 5.3+

安装

Swift Package Manager

Xcode 的“Swift Package Manager”选项卡中添加。https://github.com/sindresorhus/DockProgress

迦太基

github "sindresorhus/DockProgress"

可可豆荚

pod 'DockProgress'

用法

手动设置进度

import Cocoa
import DockProgress

foo.onUpdate = { progress in
	DockProgress.progress = progress
}

Specify a Progress instance

import Cocoa
import DockProgress

let progress = Progress(totalUnitCount: 1)
progress?.becomeCurrent(withPendingUnitCount: 1)

DockProgress.progressInstance = progress

The given instance is weakly stored. It’s up to you to retain it.Progress

Styles

It comes with three styles. PR welcome for more.

Check out the example app in the Xcode project.

You can also draw a custom progress with ..custom(drawHandler: (_ rect: CGRect) -> Void)

Bar

import DockProgress

DockProgress.style = .bar

This is the default.

Squircle

import DockProgress

DockProgress.style = .squircle(color: .white.withAlphaComponent(0.5))

By default, it should perfectly fit a macOS 11 icon, but there’s a parameter if you need to make any adjustments.inset

Circle

import DockProgress

DockProgress.style = .circle(radius: 55, color: .systemBlue)

Make sure to set a that matches your app icon.radius

Badge

import DockProgress

DockProgress.style = .badge(color: .systemBlue, badgeValue: { getDownloadCount() })

Large numbers will be written in kilo short notation, for example, → .badgeValue10121k

Note: The is not meant to be used as a numeric percentage. It’s for things like count of downloads, number of files being converted, etc.badgeValue

Related

  • Defaults – Swifty and modern UserDefaults
  • Preferences – Add a preferences window to your macOS app in minutes
  • KeyboardShortcuts – Add user-customizable global keyboard shortcuts to your macOS app
  • LaunchAtLogin – Add “Launch at Login” functionality to your macOS app
  • Regex – Swifty regular expressions
  • More…

GitHub

https://github.com/sindresorhus/DockProgress