GithubHelp home page GithubHelp logo

sindresorhus / dockprogress Goto Github PK

View Code? Open in Web Editor NEW
1.2K 12.0 61.0 3.39 MB

Show progress in your app's Dock icon

Home Page: https://swiftpackageindex.com/sindresorhus/DockProgress/documentation/dockprogress/dockprogress

License: MIT License

Swift 100.00%
dock icon progress-bar progress-circle macos swift swift-package

dockprogress's Introduction

DockProgress

Show progress in your app's Dock icon

Requirements

macOS 10.15+

Install

Add https://github.com/sindresorhus/DockProgress in the “Swift Package Manager” tab in Xcode.

Latest version: 4.3.1

API

See the API docs.

Usage

Manually set the progress

import DockProgress

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

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

DockProgress.progressInstance = progress

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

Styles

It comes with five 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 and later icon, but there is an inset parameter if you need to make any adjustments.

Circle

import DockProgress

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

Badge

import DockProgress

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

Large badgeValue numbers will be written in kilo short notation, for example, 10121k.

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

Pie

import DockProgress

DockProgress.style = .pie(color: .systemBlue)

Related

dockprogress's People

Contributors

hazeycode avatar jonivr avatar sindresorhus avatar yuiseki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dockprogress's Issues

Badge does not get removed from icon after calling DockProgress.resetProgress()

Again, lovely work @sindresorhus !

Trying to implement it into MacWhisper (www.macwhisper.com) but running into an issue. After the progress is complete and I call DockProgress.resetProgress(), the badge remains visible on the icon.

Any idea what could be causing this?

Relevant code:

`func whisper(_ aWhisper: Whisper, didUpdateProgress progress: Float) {
    self.progress = progress
    DockProgress.style = .badge(badgeValue: {
        Int(progress * 100)
    })
    DockProgress.progress = Double(progress)
}

@MainActor
func whisper(_ aWhisper: Whisper, didCompleteWithSegments segments: [Segment]) {
    DockProgress.progress = Double(1)
    DockProgress.resetProgress()`

SwiftUI support

https://developer.apple.com/tutorials/swiftui/

  • Make .custom() accept a SwiftUI View.
  • Example of using the .custom() in the Example app
  • Change the built-in styles to use SwiftUI.Canvas instead for drawing.
  • Docs
  • Tests

Anything other ideas?


This issue requires you to have advanced Swift knowledge.

Dock icon insertion

Hi @sindresorhus , would it be possible to insert an icon that you want or that is part of the sf symbols, as you can see in the video below?

Registrazione.schermo.2022-09-24.alle.11.26.42.mov

Draw directly in the Dock tile contentView

Issuehunt badges

Instead of first drawing the image and then adding it as an image to the Dock tile contentView. I think that would be slightly more efficient.

/// TODO: Make this better by drawing in the `contentView` directly instead of using an image


IssueHunt Summary

hazeycode hazeycode has been rewarded.

Backers (Total: $40.00)

Submitted pull Requests


Tips

Not work in Release Configuration

Hi:
When run in Debug configure, everything works fine, but when set scheme with Release configure, it looks not work. 'DockProgress Example' has same issue.

Environment:
Xcode: Version 14.3.1
OS: 13.5.2 Ventura

Thanks your help.

MacOS 10.14 Icon transparency

Am testing first 10.14 beta and noticed that the dock icon for Gifski during gif conversion resulted in the icon being 100% transparent(Invisible) and did not reset until app restart.

screenshot 2018-06-11 at 04 48 14

screenshot 2018-06-11 at 04 48 32

I know not priority as still beta MacOS version, but still worth reporting.

Make the progress animation smoother

Issuehunt badges

/// TODO: Make the progress smoother by also animating the steps between each call to `updateDockIcon()`

Right now it only updates each time progressValue is updated or the NSProgress instance in progress changes. Let say you use this to update on each processed frame of a video, so the longer the video is, the smoother the progress animation is. That also means it will be pretty choppy on short clips.

Normally you would use a CALayer, which would animate between the progress events. This is however not possible for the Dock icon as we have to call .display() manually each time we want to update it. I tried to use CALayer and just capture an image of the layer 30 times a second, but it seems it's only possible to capture before or after the animation.

I think the solution is to simply implement the animation ourselves with an interval timer. We already have the previous progress and the current progress, so we can animate between them. It's a bit more complicated though as if we receive a new progress change while we're animation, we now need to animate to the new progress.

I'm also happy to consider other ideas.

I think we should also fade-in and fade-out the progress animation so it doesn't just suddenly appear at 0% and disappear at 100%.


IssueHunt Summary

hazeycode hazeycode has been rewarded.

Backers (Total: $100.00)

Submitted pull Requests


Tips

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.