Meta tweaks

This commit is contained in:
Sindre Sorhus 2018-07-21 04:40:05 +07:00
parent 238da87dab
commit 6765d6df97
4 changed files with 92 additions and 80 deletions

View file

@ -14,6 +14,7 @@
E34F2FFC1E89A77400217535 /* DVTDeviceFoundation.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = E34F2FFA1E89A77400217535 /* DVTDeviceFoundation.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
E34F31CD1E89AD7300217535 /* DFRSupportKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E34F31CC1E89AD7300217535 /* DFRSupportKit.framework */; };
E34F31CE1E89AD7300217535 /* DFRSupportKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = E34F31CC1E89AD7300217535 /* DFRSupportKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
E356A16321028D81000148AD /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = E356A16221028D81000148AD /* main.swift */; };
E35831A41F4D7EE0003BE371 /* util.swift in Sources */ = {isa = PBXBuildFile; fileRef = E35831A31F4D7EE0003BE371 /* util.swift */; };
E3FA3A8B1E784C4900A7F2EA /* DVTFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E3FA3A8A1E784C4900A7F2EA /* DVTFoundation.framework */; };
E3FA3A8D1E784C5F00A7F2EA /* DVTFoundation.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = E3FA3A8A1E784C4900A7F2EA /* DVTFoundation.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
@ -33,7 +34,7 @@
E3FA3AAC1E784EA500A7F2EA /* kperfdataDT.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = E3FA3AA91E784EA300A7F2EA /* kperfdataDT.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
E3FA3AAE1E784ECA00A7F2EA /* DVTInstrumentsUtilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E3FA3AAD1E784ECA00A7F2EA /* DVTInstrumentsUtilities.framework */; };
E3FA3AB01E784ECC00A7F2EA /* DVTInstrumentsUtilities.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = E3FA3AAD1E784ECA00A7F2EA /* DVTInstrumentsUtilities.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
E3FE2CC31E726CE800C6713A /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3FE2CC21E726CE800C6713A /* main.swift */; };
E3FE2CC31E726CE800C6713A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3FE2CC21E726CE800C6713A /* AppDelegate.swift */; };
E3FE2CC51E726CE800C6713A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E3FE2CC41E726CE800C6713A /* Assets.xcassets */; };
/* End PBXBuildFile section */
@ -67,6 +68,7 @@
E30988DE1E88DD060078CA9E /* Sparkle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Sparkle.framework; path = Carthage/Build/Mac/Sparkle.framework; sourceTree = "<group>"; };
E34F2FFA1E89A77400217535 /* DVTDeviceFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DVTDeviceFoundation.framework; path = /Applications/Xcode.app/Contents/SharedFrameworks/DVTDeviceFoundation.framework; sourceTree = "<absolute>"; };
E34F31CC1E89AD7300217535 /* DFRSupportKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = DFRSupportKit.framework; sourceTree = "<group>"; };
E356A16221028D81000148AD /* main.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = main.swift; sourceTree = "<group>"; usesTabs = 1; };
E35831A31F4D7EE0003BE371 /* util.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = util.swift; sourceTree = "<group>"; usesTabs = 1; };
E3FA3A8A1E784C4900A7F2EA /* DVTFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DVTFoundation.framework; path = /Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework; sourceTree = "<absolute>"; };
E3FA3A911E784C7D00A7F2EA /* DVTKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DVTKit.framework; path = /Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework; sourceTree = "<absolute>"; };
@ -78,7 +80,7 @@
E3FA3AA91E784EA300A7F2EA /* kperfdataDT.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = kperfdataDT.framework; path = /Applications/Xcode.app/Contents/SharedFrameworks/kperfdataDT.framework; sourceTree = "<absolute>"; };
E3FA3AAD1E784ECA00A7F2EA /* DVTInstrumentsUtilities.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DVTInstrumentsUtilities.framework; path = /Applications/Xcode.app/Contents/SharedFrameworks/DVTInstrumentsUtilities.framework; sourceTree = "<absolute>"; };
E3FE2CBF1E726CE800C6713A /* Touch Bar Simulator.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Touch Bar Simulator.app"; sourceTree = BUILT_PRODUCTS_DIR; };
E3FE2CC21E726CE800C6713A /* main.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = main.swift; sourceTree = "<group>"; usesTabs = 1; };
E3FE2CC21E726CE800C6713A /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = AppDelegate.swift; sourceTree = "<group>"; usesTabs = 1; };
E3FE2CC41E726CE800C6713A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
E3FE2CC91E726CE800C6713A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
E3FE2CD21E726EA100C6713A /* Touch Bar Simulator-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = "Touch Bar Simulator-Bridging-Header.h"; sourceTree = "<group>"; usesTabs = 1; };
@ -107,6 +109,16 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
E356A16421028DAB000148AD /* Other */ = {
isa = PBXGroup;
children = (
E356A16221028D81000148AD /* main.swift */,
E3FE2CD21E726EA100C6713A /* Touch Bar Simulator-Bridging-Header.h */,
E3FE2CC91E726CE800C6713A /* Info.plist */,
);
name = Other;
sourceTree = "<group>";
};
E3FE2CB61E726CE800C6713A = {
isa = PBXGroup;
children = (
@ -128,12 +140,11 @@
E3FE2CC11E726CE800C6713A /* Touch Bar Simulator */ = {
isa = PBXGroup;
children = (
E3FE2CC21E726CE800C6713A /* main.swift */,
E3FE2CC21E726CE800C6713A /* AppDelegate.swift */,
AF6C7BC51E7FAF38004A27E0 /* ToolbarSlider.swift */,
E35831A31F4D7EE0003BE371 /* util.swift */,
E3FE2CD21E726EA100C6713A /* Touch Bar Simulator-Bridging-Header.h */,
E3FE2CC41E726CE800C6713A /* Assets.xcassets */,
E3FE2CC91E726CE800C6713A /* Info.plist */,
E356A16421028DAB000148AD /* Other */,
);
path = "Touch Bar Simulator";
sourceTree = "<group>";
@ -201,7 +212,6 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = E3FE2CB61E726CE800C6713A;
@ -232,7 +242,8 @@
files = (
E35831A41F4D7EE0003BE371 /* util.swift in Sources */,
AF6C7BC61E7FAF38004A27E0 /* ToolbarSlider.swift in Sources */,
E3FE2CC31E726CE800C6713A /* main.swift in Sources */,
E356A16321028D81000148AD /* main.swift in Sources */,
E3FE2CC31E726CE800C6713A /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -294,6 +305,7 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_COMPILATION_MODE = singlefile;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
VALID_ARCHS = x86_64;
};
name = Debug;
};
@ -344,6 +356,7 @@
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
VALID_ARCHS = x86_64;
};
name = Release;
};

View file

@ -0,0 +1,72 @@
import Cocoa
import Sparkle
private let defaults = UserDefaults.standard
final class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
let controller = IDETouchBarSimulatorHostWindowController.simulatorHostWindowController()!
lazy var window: NSWindow = self.controller.window!
lazy var toolbarView: NSView = self.window.toolbarView!
func applicationWillFinishLaunching(_ notification: Notification) {
defaults.register(defaults: [
"NSApplicationCrashOnExceptions": true,
"windowTransparency": 0.75
])
}
func applicationDidFinishLaunching(_ notification: Notification) {
NSApp.servicesProvider = self
window.delegate = self
_ = SUUpdater()
toolbarView.addSubviews(
makeScreenshotButton(),
makeTransparencySlider()
)
}
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
}
func makeScreenshotButton() -> NSButton {
let button = NSButton()
button.image = #imageLiteral(resourceName: "ScreenshotButton")
button.imageScaling = .scaleProportionallyDown
button.isBordered = false
button.bezelStyle = .shadowlessSquare
button.frame = CGRect(x: toolbarView.frame.width - 19, y: 4, width: 16, height: 11)
button.action = #selector(captureScreenshot)
return button
}
func makeTransparencySlider() -> ToolbarSlider {
let transparency = defaults.double(forKey: "windowTransparency")
let slider = ToolbarSlider()
slider.frame = CGRect(x: toolbarView.frame.width - 150, y: 4, width: 120, height: 11)
slider.action = #selector(setTransparency)
slider.minValue = 0.5
slider.doubleValue = transparency
window.alphaValue = CGFloat(transparency)
return slider
}
@objc
func captureScreenshot() {
let KEY_6: CGKeyCode = 0x58
pressKey(keyCode: KEY_6, flags: [.maskShift, .maskCommand])
}
@objc
func setTransparency(sender: ToolbarSlider) {
window.alphaValue = CGFloat(sender.doubleValue)
defaults.set(sender.doubleValue, forKey: "windowTransparency")
}
@objc
func toggleView(_ pboard: NSPasteboard, userData: String, error: NSErrorPointer) {
window.setIsVisible(!window.isVisible)
}
}

View file

@ -2,8 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>

View file

@ -1,75 +1,4 @@
import Cocoa
import Sparkle
private let defaults = UserDefaults.standard
final class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
let controller = IDETouchBarSimulatorHostWindowController.simulatorHostWindowController()!
lazy var window: NSWindow = self.controller.window!
lazy var toolbarView: NSView = self.window.toolbarView!
func applicationWillFinishLaunching(_ notification: Notification) {
defaults.register(defaults: [
"NSApplicationCrashOnExceptions": true,
"windowTransparency": 0.75
])
}
func applicationDidFinishLaunching(_ notification: Notification) {
NSApp.servicesProvider = self
window.delegate = self
_ = SUUpdater()
toolbarView.addSubviews(
makeScreenshotButton(),
makeTransparencySlider()
)
}
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
}
func makeScreenshotButton() -> NSButton {
let button = NSButton()
button.image = #imageLiteral(resourceName: "ScreenshotButton")
button.imageScaling = .scaleProportionallyDown
button.isBordered = false
button.bezelStyle = .shadowlessSquare
button.frame = CGRect(x: toolbarView.frame.width - 19, y: 4, width: 16, height: 11)
button.action = #selector(captureScreenshot)
return button
}
func makeTransparencySlider() -> ToolbarSlider {
let transparency = defaults.double(forKey: "windowTransparency")
let slider = ToolbarSlider()
slider.frame = CGRect(x: toolbarView.frame.width - 150, y: 4, width: 120, height: 11)
slider.action = #selector(setTransparency)
slider.minValue = 0.5
slider.doubleValue = transparency
window.alphaValue = CGFloat(transparency)
return slider
}
@objc
func captureScreenshot() {
let KEY_6: CGKeyCode = 0x58
pressKey(keyCode: KEY_6, flags: [.maskShift, .maskCommand])
}
@objc
func setTransparency(sender: ToolbarSlider) {
window.alphaValue = CGFloat(sender.doubleValue)
defaults.set(sender.doubleValue, forKey: "windowTransparency")
}
@objc
func toggleView(_ pboard: NSPasteboard, userData: String, error: NSErrorPointer) {
window.setIsVisible(!window.isVisible)
}
}
private let app = NSApplication.shared
private let delegate = AppDelegate()