source: launchers/project/IconHelper.scala

Last change on this file was 4f47fab, checked in by meeh <meeh@…>, 2 years ago

Removed unused resources directory hopefully,
And aslo added an IconHelper? autoplugin which
will generate Mac OS X valid ICNS images.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1package root
2
3import sbt._, Keys._
4import java.io.File
5
6/**
7  *
8  * This is an autoplugin for sbt which makes it possible to
9  * create an correctly made icns file for usage as app icon.
10  *
11  * The task "convertToICNSTask" should become available for us to define
12  * because of this class.
13  *
14  * sips is only a command on Mac OS X afaik so this would probably need to be
15  * built on a mac.
16  *
17  * @since 0.9.35
18  */
19object IconHelper extends AutoPlugin {
20
21  def convertToICNS(inF: File, outF: File) {
22    if (inF.ext == "icns") {
23      IO.copyFile(inF, outF, preserveLastModified = true)
24    } else {
25      import sys.process._
26      val lines       = Seq("sips", "-g", "pixelHeight", "-g", "pixelWidth", inF.getPath).lines
27      val PixelWidth  = "\\s+pixelWidth: (\\d+)".r
28      val PixelHeight = "\\s+pixelHeight: (\\d+)".r
29      val srcWidth    = lines.collect { case PixelWidth (s) => s.toInt } .head
30      val srcHeight   = lines.collect { case PixelHeight(s) => s.toInt } .head
31      val supported   = IndexedSeq(16, 32, 48, 128, 256, 512)
32      val srcSize     = math.min(512, math.max(srcWidth, srcHeight))
33      val tgtSize     = supported(supported.indexWhere(_ >= srcSize))
34      val args0       = Seq(inF.getPath, "--out", outF.getPath)
35      val args1       = if (tgtSize != srcWidth || tgtSize != srcHeight) {
36        Seq("-z", tgtSize.toString, tgtSize.toString)
37      } else {
38        Seq.empty
39      }
40      val args        = Seq("sips", "-s", "format", "icns") ++ args1 ++ args0
41      args.!!
42    }
43  }
44
45  object autoImport {
46    val convertToICNSTask = taskKey[Unit]("Converts an image to Mac OS X's ICNS icon format")
47  }
48
49  import autoImport._
50
51}
52
Note: See TracBrowser for help on using the repository browser.