Easily display images, animations, badges and alerts to your macOS application's dock icon

Overview

DSFDockTile

Easily display images, animations, badges and alerts to your macOS application's dock icon.

Swift Package Manager

Why?

I was inspired by Neil Sardesai after he posted this on Twitter. And this marvellous follow-up tweet by Norbert M. Doerner.

While the NSDockTile API isn't overly complex, I wanted something that made it easy to change the dock image, and even add basic animations from GIF images etc.

Features

  • Set the badge label
  • Display an image
  • Display an animated image
  • Display the content of an NSView
  • Bounce the docktile

By default a DSFDockTile instance operates on the Application's docktile. You can provide your own NSDockTile for any window (by calling window.dockTile) via the init functions on the badge generators.

DockTile plugins

Did you know that your application can show a custom DockTile image even when it's not running? Apple provides an NSDockTilePlugin prodocol that allows you to do exactly that. Want to provide different application icons for dark and light modes? NSDockTilePlugin allows you to! Want to tweak the dock icon when your application isn't running, but needs attention? NSDockTilePlugin!

There is a demo application in the Demos folder called 'DSFDockTile Plugin Demo' (macOS 11+) that demonstrates using NSDockTilePlugin and DSFDockIcon in SwiftUI.

Integration

Swift package manager

Add https://github.com/dagronf/DSFDockTile to your project.

If you don't want to include the DSFImageFlipbook package, copy all the files in the Sources/ folder EXCEPT for DSFDockTile+Animation.swift.

Demo

There is a demo macOS application available in the Demos subfolder.

Badge Label

It's very easy to add a badge label to a docktile.

// Set the label on the docktile to 1234
DSFDockTile.badgeLabel = "1234"

// Remove the badge label from the docktile
DSFDockTile.badgeLabel = nil

DockTile Generators

AppIcon

Set the docktile to the application's icon.

// Set the dock icon to the application icon
DSFDockTile.AppIcon.display()

Constant Image

This is a DSFDockTile object that displays a single image. Useful for if you have a set of images to display in the docktile that do not change and you want to the constantness.

static let LockedImage   = NSImage(named: NSImage.Name("padlock-locked"))!
static let UnlockedImage = NSImage(named: NSImage.Name("padlock-unlocked"))!

let LockedDockTileImage = DSFDockTile.ConstantImage(LockedImage)
let UnlockedDockTileImage = DSFDockTile.ConstantImage(UnlockedImage)
...

if application.isEditable {
   UnlockedDockTileImage.display()
}
else {
   LockedDockTileImage.display()
}

Image

This is a DSFDockTile object that can display images.

static let LockedImage   = NSImage(named: NSImage.Name("padlock-locked"))!
static let UnlockedImage = NSImage(named: NSImage.Name("padlock-unlocked"))!

let stateDockTile = DSFDockTile.Image()

...

func viewDidLoad() {
   let image = application.isEditable ? UnlockedImage : LockedImage
   stateDockTile.display(image)
}

View

This is a DSFDockTile object that can display the content of a view managed by a view controller

Due to NSDockTile restrictions, the view is not drawn live into the dock as the view is updated. You must call display() to update the dock tile with the view's current content whenever a change occurs in the view.

/// The view controller to display on the docktile
let dockViewController = DockViewController()

/// The docktile instance handling the docktile
lazy var updateDockTile: DSFDockTile.View = {
   dockViewController.loadView()
   return DSFDockTile.View(dockViewController)
}()
...
func doUpdate() {
   // Change the color of the item in the 
   self.dockViewController.foregroundColor = .systemYellow

   // NSDockTile does not update automatically so need to tell it when changes are made
   self.updateDockTile.display()
}

Animation

This is a docktile that can display an animation. It uses DSFImageFlipbook under the seams to handle the animation itself.

let animatedDockTile: DSFDockTile.Animated = {
   let fb = DSFImageFlipbook()
   let da = NSDataAsset(name: NSDataAsset.Name("animated-gif"))!
   _ = fb.loadFrames(from: da.data)
   return DSFDockTile.Animated(fb)
}()

...

@IBAction func startAnimating(_ sender: Any) {
   animatedDockTile.startAnimating()
}

@IBAction func stopAnimating(_ sender: Any) {
   animatedDockTile.stopAnimating()
}

Attention Concepts

You can request user information via the DockTile of an application if your application is not the front-most application.

See Apple's Documentation for more details.

requestInformationalAttention()

Request that the docktile 'bounce' to inform the user of something informational. The function returns an object which you can use to cancel the attention request.

let cancellable = DSFDockTile.requestInformationalAttention()

The cancellable can be used to cancel the information request.

See Apple's Documentation

requestCriticalAttention()

Request that the docktile 'bounce' to inform the user of something informational. The function returns an object which you can use to cancel the attention request.

let cancellable = DSFDockTile.requestCriticalAttention()

The cancellable can be used to cancel the critical request.

See Apple's Documentation

Cancellation protocol (DSFDockTileUserAttentionCancellation)

The user attention methods return an object that conforms to DSFDockTileUserAttentionCancellation that can be used to cancel an attention request.

See Apple's Documentation

Thanks

License

MIT. Use it and abuse it for anything you want, just attribute my work. Let me know if you do use it somewhere, I'd love to hear about it!

MIT License

Copyright (c) 2021 Darren Ford

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.
You might also like...
Image viewer (or Lightbox) with support for local and remote videos and images
Image viewer (or Lightbox) with support for local and remote videos and images

Table of Contents Features Focus Browse Rotation Zoom tvOS Setup Installation License Author Features Focus Select an image to enter into lightbox mod

DTPhotoViewerController - A fully customizable photo viewer ViewController to display single photo or collection of photos, inspired by Facebook photo viewer.
DTPhotoViewerController - A fully customizable photo viewer ViewController to display single photo or collection of photos, inspired by Facebook photo viewer.

DTPhotoViewerController Example Demo video: https://youtu.be/aTLx4M4zsKk DTPhotoViewerController is very simple to use, if you want to display only on

Cordova plugin to display a native color-picker dialog

Color Picker Plugin for Cordova (cordova-plugin-color-picker) Description This plugin allows you to display a color-picker native dialog in iOS and An

Kingfisher is a powerful, pure-Swift library for downloading and caching images from the web
Kingfisher is a powerful, pure-Swift library for downloading and caching images from the web

Kingfisher is a powerful, pure-Swift library for downloading and caching images from the web. It provides you a chance to use a pure-Swift way to work

A high-performance image library for downloading, caching, and processing images in Swift.
A high-performance image library for downloading, caching, and processing images in Swift.

Features Asynchronous image downloader with priority queuing Advanced memory and database caching using YapDatabase (SQLite) Guarantee of only one ima

A Swift library for parsing and drawing SVG images to CoreGraphics contexts.

SwiftDraw A Swift library for parsing and drawing SVG images to CoreGraphics contexts. SwiftDraw can also convert an SVG into Swift source code. Usage

Advanced framework for loading, caching, processing, displaying and preheating images.
Advanced framework for loading, caching, processing, displaying and preheating images.

Advanced framework for loading, caching, processing, displaying and preheating images. This framework is no longer maintained. Programming in Swift? C

Style Art library process images using COREML with a set of pre trained machine learning models and convert them to Art style.
Style Art library process images using COREML with a set of pre trained machine learning models and convert them to Art style.

StyleArt Style Art is a library that process images using COREML with a set of pre trained machine learning models and convert them to Art style. Prev

Detecting Texts and Persons from Images

Detections Detecting Texts and Persons from Images Detections package will help you to get the texts from image and also recognize a person Image whih

Comments
  • Customizations don't persist when app is quit

    Customizations don't persist when app is quit

    One of the nice things about Nova is that when you quit the app, the customised Dock icon remains shown in both the Finder, and the Dock.

    I've just tried doing the same using this project, and the customisations are all reset when the app is quit.

    It would be great if the customizations persisted.

    opened by tonyarnold 4
Owner
Darren Ford
Darren Ford
Media view which subclasses UIImageView, and can display & load images, videos, GIFs, and audio and from the web, and has functionality to minimize from fullscreen, as well as show GIF previews for videos.

I've built out the Swift version of this library! Screenshots Description ABMediaView can display images, videos, as well as now GIFs and Audio! It su

Andrew Boryk 80 Dec 20, 2022
SwiftUI App Icon Generator App for iOS & macOS Catalyst

SwiftUI App Icon Generator App for iOS & macOS Catalyst Generate Asset Icons easily to your iPhone, iPad, Mac, and Apple Watch Features The app has se

Alfian Losari 21 Sep 14, 2022
Jogendra 113 Nov 28, 2022
APNGKit is a high performance framework for loading and displaying APNG images in iOS and macOS.

APNGKit is a high performance framework for loading and displaying APNG images in iOS and macOS. It's built on top of a modified version of libpng wit

Wei Wang 2.1k Dec 30, 2022
Shows your photo library grouped by events, to easily export them to your computer

Groupir Shows your photo library grouped by events, to easily export them to your computer Features Currently supported features: reading your photo l

Stanislas Chevallier 0 Dec 15, 2021
A simple macOS app to read code from images, written purely in Swift using Vision Framework.

CodeReader A simple macOS app to read code from images, written purely in Swift using Vision Framework. Usage Drag an image Click the convert button R

Md Ibrahim Hassan 44 Nov 20, 2022
WhiteAndFluffyTest - Scroll images and add them to your favourites via image page

Image service application Scroll images and add them to your favourites via imag

Ruben Egikian 0 Feb 4, 2022
SwiftGen is a tool to automatically generate Swift code for resources of your projects (like images, localised strings, etc), to make them type-safe to use.

SwiftGen is a tool to automatically generate Swift code for resources of your projects (like images, localised strings, etc), to make them type-safe to use.

null 8.3k Jan 5, 2023
SwiftUI view that download and display image from URL and displaying Activity Indicator while loading .

ViewWithActivityIndicator ViewWithActivityIndicator is a SwiftUI view that download and display image from URL and displaying Activity Indicator while

Ali Adam 28 Feb 3, 2022
Use Swift to pack ambiguous image that display differently on Apple and Other devices

Aibmoe Use Swift to pack ambiguous image that display differently on Apple and O

Lakr Aream 2 Feb 3, 2022