Various minor improvements

This commit is contained in:
Sindre Sorhus 2017-03-21 11:38:33 +07:00
parent c2c7b4bd21
commit bdd83ab98f
5 changed files with 29 additions and 33 deletions

View file

@ -136,10 +136,10 @@
isa = PBXGroup;
children = (
E3FE2CC21E726CE800C6713A /* main.swift */,
AF6C7BC51E7FAF38004A27E0 /* ToolbarSlider.swift */,
E3FE2CD21E726EA100C6713A /* Touch Bar Simulator-Bridging-Header.h */,
E3FE2CC41E726CE800C6713A /* Assets.xcassets */,
E3FE2CC91E726CE800C6713A /* Info.plist */,
AF6C7BC51E7FAF38004A27E0 /* ToolbarSlider.swift */,
);
path = "Touch Bar Simulator";
sourceTree = "<group>";

View file

@ -2,56 +2,49 @@
// ToolbarSlider.swift
// Touch Bar Simulator
//
// Created by Wayne Yeh on 2017/3/20.
// Copyright © 2017 Sindre Sorhus. All rights reserved.
// Created by Wayne Yeh on 2017/3/20
// MIT License © Sindre Sorhus
//
import Cocoa
private class ToolbarSliderCell: NSSliderCell {
static var knob: NSImage = {
private final class ToolbarSliderCell: NSSliderCell {
private static let knob: NSImage = {
let frame = NSRect(x: 0, y: 0, width: 32, height: 32)
let image = NSImage(size: frame.size)
image.lockFocus()
// draw a rounded Rectangle
// Circle
let path = NSBezierPath(roundedRect: frame, xRadius: 4, yRadius: 12)
NSColor.lightGray.set()
path.fill()
// draw edge
// Border
NSColor.black.set()
path.lineWidth = 2
path.stroke()
image.unlockFocus()
return image
}()
override func drawKnob(_ knobRect: NSRect) {
ToolbarSliderCell.knob.draw(in: knobRect.insetBy(dx: 0, dy: 6.5))
}
}
class ToolbarSlider: NSSlider {
final class ToolbarSlider: NSSlider {
override init(frame: CGRect) {
super.init(frame: frame)
addBehavior()
cell = ToolbarSliderCell()
}
convenience init() {
self.init(frame: CGRect.zero)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func addBehavior() {
self.cell = ToolbarSliderCell()
}
}

View file

@ -10,9 +10,11 @@ import Cocoa
final class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
let controller = IDETouchBarSimulatorHostWindowController.simulatorHostWindowController()!
var toolbarView: NSView!
func applicationDidFinishLaunching(_ notification: Notification) {
controller.window?.delegate = self
toolbarView = controller.window!.standardWindowButton(.closeButton)!.superview!
addScreenshotButton()
addTransparencySlider()
}
@ -22,7 +24,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
}
func addScreenshotButton() {
let toolbarView = controller.window!.standardWindowButton(.closeButton)!.superview!
let button = NSButton()
button.image = #imageLiteral(resourceName: "ScreenshotButton")
button.imageScaling = .scaleProportionallyDown
@ -43,15 +44,14 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
keyDown?.post(tap: loc)
keyUp?.post(tap: loc)
}
func addTransparencySlider() {
let toolbarView = controller.window!.standardWindowButton(.closeButton)!.superview!
let slider = ToolbarSlider()
slider.frame = CGRect(x: toolbarView.frame.width - 150, y: 4, width: 120, height: 11)
slider.action = #selector(settTransparency)
slider.action = #selector(setTransparency)
toolbarView.addSubview(slider)
var transparency = UserDefaults.standard.double(forKey: "TransparencySlider")
var transparency = UserDefaults.standard.double(forKey: "windowTransparency")
if transparency == 0 {
transparency = 0.75
}
@ -59,10 +59,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
slider.doubleValue = transparency
controller.window!.alphaValue = CGFloat(slider.doubleValue)
}
func settTransparency(sender : NSSlider) {
func setTransparency(sender: NSSlider) {
controller.window!.alphaValue = CGFloat(sender.doubleValue)
UserDefaults.standard.set(sender.doubleValue, forKey: "TransparencySlider")
UserDefaults.standard.set(sender.doubleValue, forKey: "windowTransparency")
}
}

View file

@ -2,7 +2,9 @@
> Launch the Touch Bar simulator from anywhere without needing to have Xcode installed
Whereas Apple requires you to launch it from inside Xcode. This app also comes with a handy screenshot button.
Whereas Apple requires you to launch it from inside Xcode.
This app also comes with a handy transparency slider and screenshot button.
**[Discuss it on Product Hunt](https://www.producthunt.com/posts/touch-bar-simulator)**
@ -33,6 +35,7 @@ You can capture a screenshot of the Touch Bar by either:
- Doesn't require Xcode
- Signed binary
- Transparency slider
- Screenshot button
- Doesn't steal focus when launched
- Doesn't take up space in the Dock or app switcher

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 28 KiB