Start work

This commit is contained in:
Shadowfacts 2019-07-13 15:33:21 -04:00
parent e96c395247
commit 88e8d606b4
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
15 changed files with 380 additions and 63 deletions

77
.gitignore vendored Normal file
View File

@ -0,0 +1,77 @@
.DS_Store
### Swift ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## Build generated
build/
DerivedData/
## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint
## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM
## Playgrounds
timeline.xctimeline
playground.xcworkspace
# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
.build/
# CocoaPods - Refactored to standalone file
# Carthage - Refactored to standalone file
# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
### Xcode ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## Build generated
## Various settings
## Other
### Xcode Patch ###
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
/*.gcno

View File

@ -8,19 +8,31 @@
/* Begin PBXBuildFile section */
D6B35B3922DA1B3C00F262A2 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6B35B3822DA1B3C00F262A2 /* AppDelegate.swift */; };
D6B35B3B22DA1B3C00F262A2 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6B35B3A22DA1B3C00F262A2 /* ViewController.swift */; };
D6B35B3D22DA1B3C00F262A2 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D6B35B3C22DA1B3C00F262A2 /* Assets.xcassets */; };
D6B35B4022DA1B3C00F262A2 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D6B35B3E22DA1B3C00F262A2 /* Main.storyboard */; };
D6B35B4C22DA466600F262A2 /* TouchBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6B35B4B22DA466600F262A2 /* TouchBarController.swift */; };
D6B35B4E22DA479E00F262A2 /* TouchBarItemIdentifiers.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6B35B4D22DA479E00F262A2 /* TouchBarItemIdentifiers.swift */; };
D6B35B5122DA4A2A00F262A2 /* DFRFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D6B35B5022DA4A2A00F262A2 /* DFRFoundation.framework */; };
D6B35B5522DA64AD00F262A2 /* RootTouchBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6B35B5422DA64AD00F262A2 /* RootTouchBarController.swift */; };
D6B35B5A22DA66A400F262A2 /* TouchBarWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6B35B5922DA66A400F262A2 /* TouchBarWidget.swift */; };
D6B35B5E22DA687E00F262A2 /* NowPlayingWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6B35B5D22DA687E00F262A2 /* NowPlayingWidget.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
D6B35B3522DA1B3C00F262A2 /* Underbar.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Underbar.app; sourceTree = BUILT_PRODUCTS_DIR; };
D6B35B3822DA1B3C00F262A2 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
D6B35B3A22DA1B3C00F262A2 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
D6B35B3C22DA1B3C00F262A2 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
D6B35B3F22DA1B3C00F262A2 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
D6B35B4122DA1B3C00F262A2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
D6B35B4222DA1B3C00F262A2 /* Underbar.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Underbar.entitlements; sourceTree = "<group>"; };
D6B35B4822DA1B8D00F262A2 /* NSTouchBar.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSTouchBar.h; sourceTree = "<group>"; };
D6B35B4A22DA1C8400F262A2 /* Underbar-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Underbar-Bridging-Header.h"; sourceTree = "<group>"; };
D6B35B4B22DA466600F262A2 /* TouchBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TouchBarController.swift; sourceTree = "<group>"; };
D6B35B4D22DA479E00F262A2 /* TouchBarItemIdentifiers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TouchBarItemIdentifiers.swift; sourceTree = "<group>"; };
D6B35B5022DA4A2A00F262A2 /* DFRFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DFRFoundation.framework; path = ../../../../System/Library/PrivateFrameworks/DFRFoundation.framework; sourceTree = "<group>"; };
D6B35B5422DA64AD00F262A2 /* RootTouchBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootTouchBarController.swift; sourceTree = "<group>"; };
D6B35B5922DA66A400F262A2 /* TouchBarWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TouchBarWidget.swift; sourceTree = "<group>"; };
D6B35B5D22DA687E00F262A2 /* NowPlayingWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NowPlayingWidget.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -28,6 +40,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
D6B35B5122DA4A2A00F262A2 /* DFRFoundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -39,6 +52,7 @@
children = (
D6B35B3722DA1B3C00F262A2 /* Underbar */,
D6B35B3622DA1B3C00F262A2 /* Products */,
D6B35B4F22DA4A2A00F262A2 /* Frameworks */,
);
sourceTree = "<group>";
};
@ -54,15 +68,45 @@
isa = PBXGroup;
children = (
D6B35B3822DA1B3C00F262A2 /* AppDelegate.swift */,
D6B35B3A22DA1B3C00F262A2 /* ViewController.swift */,
D6B35B4D22DA479E00F262A2 /* TouchBarItemIdentifiers.swift */,
D6B35B5722DA669000F262A2 /* Controllers */,
D6B35B5822DA669400F262A2 /* Widgets */,
D6B35B3C22DA1B3C00F262A2 /* Assets.xcassets */,
D6B35B3E22DA1B3C00F262A2 /* Main.storyboard */,
D6B35B4122DA1B3C00F262A2 /* Info.plist */,
D6B35B4222DA1B3C00F262A2 /* Underbar.entitlements */,
D6B35B4822DA1B8D00F262A2 /* NSTouchBar.h */,
D6B35B4A22DA1C8400F262A2 /* Underbar-Bridging-Header.h */,
);
path = Underbar;
sourceTree = "<group>";
};
D6B35B4F22DA4A2A00F262A2 /* Frameworks */ = {
isa = PBXGroup;
children = (
D6B35B5022DA4A2A00F262A2 /* DFRFoundation.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
D6B35B5722DA669000F262A2 /* Controllers */ = {
isa = PBXGroup;
children = (
D6B35B4B22DA466600F262A2 /* TouchBarController.swift */,
D6B35B5422DA64AD00F262A2 /* RootTouchBarController.swift */,
);
path = Controllers;
sourceTree = "<group>";
};
D6B35B5822DA669400F262A2 /* Widgets */ = {
isa = PBXGroup;
children = (
D6B35B5922DA66A400F262A2 /* TouchBarWidget.swift */,
D6B35B5D22DA687E00F262A2 /* NowPlayingWidget.swift */,
);
path = Widgets;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@ -133,8 +177,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D6B35B3B22DA1B3C00F262A2 /* ViewController.swift in Sources */,
D6B35B5A22DA66A400F262A2 /* TouchBarWidget.swift in Sources */,
D6B35B4E22DA479E00F262A2 /* TouchBarItemIdentifiers.swift in Sources */,
D6B35B4C22DA466600F262A2 /* TouchBarController.swift in Sources */,
D6B35B5E22DA687E00F262A2 /* NowPlayingWidget.swift in Sources */,
D6B35B3922DA1B3C00F262A2 /* AppDelegate.swift in Sources */,
D6B35B5522DA64AD00F262A2 /* RootTouchBarController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -279,9 +327,15 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
PRODUCT_BUNDLE_IDENTIFIER = net.shadowfacts.Underbar;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/$(PROJECT_NAME)/$(SWIFT_MODULE_NAME)-Bridging-Header.h";
SWIFT_VERSION = 5.0;
SYSTEM_FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks",
);
};
name = Debug;
};
@ -299,9 +353,15 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
PRODUCT_BUNDLE_IDENTIFIER = net.shadowfacts.Underbar;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/$(PROJECT_NAME)/$(SWIFT_MODULE_NAME)-Bridging-Header.h";
SWIFT_VERSION = 5.0;
SYSTEM_FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks",
);
};
name = Release;
};

View File

@ -11,16 +11,29 @@ import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
let statusBarItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
let rootController = RootTouchBarController()
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
statusBarItem.button!.image = NSImage(named: "underbar")!
let menu = NSMenu(title: "Underbar")
menu.addItem(NSMenuItem(title: "Quit Underbar", action: #selector(NSApp.terminate(_:)), keyEquivalent: "q"))
statusBarItem.menu = menu
NSTouchBar.presentSystemModalTouchBar(rootController.touchBar, placement: 1, systemTrayItemIdentifier: .underbar)
rootController.isVisible = true
DFRSystemModalShowsCloseBoxWhenFrontMost(false)
let systemItem = NSButtonTouchBarItem(identifier: .underbar, image: NSImage(named: "underbar")!, target: rootController, action: #selector(TouchBarController.toggle))
NSTouchBarItem.addSystemTrayItem(systemItem)
DFRElementSetControlStripPresenceForIdentifier(.underbar, true)
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
}

View File

@ -0,0 +1,24 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "underbar.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 596 B

View File

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="11134" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14835.7" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11134"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14835.7"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Application-->
@ -673,37 +674,16 @@
<outlet property="delegate" destination="Voe-Tx-rLC" id="PrD-fu-P6m"/>
</connections>
</application>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModuleProvider="target"/>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="Underbar" customModuleProvider="target"/>
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="75" y="0.0"/>
</scene>
<!--Window Controller-->
<scene sceneID="R2V-B0-nI4">
<objects>
<windowController id="B8D-0N-5wS" sceneMemberID="viewController">
<window key="window" title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="IQv-IB-iLA">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="480" height="270"/>
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
<connections>
<outlet property="delegate" destination="B8D-0N-5wS" id="98r-iN-zZc"/>
</connections>
</window>
<connections>
<segue destination="XfG-lQ-9wD" kind="relationship" relationship="window.shadowedContentViewController" id="cq2-FE-JQM"/>
</connections>
</windowController>
<customObject id="Oky-zY-oP4" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="75" y="250"/>
</scene>
<!--View Controller-->
<scene sceneID="hIz-AP-VOD">
<objects>
<viewController id="XfG-lQ-9wD" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="XfG-lQ-9wD" sceneMemberID="viewController">
<view key="view" id="m2S-Jp-Qdl">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask"/>

View File

@ -0,0 +1,47 @@
//
// RootTouchBarController.swift
// Underbar
//
// Created by Shadowfacts on 7/13/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import Cocoa
class RootTouchBarController: TouchBarController {
let nowPlaying = NowPlayingWidget()
override init() {
super.init()
widgets = [
nowPlaying
]
touchBar.defaultItemIdentifiers = [
.closeUnderbar,
.flexibleSpace,
.nowPlaying,
]
}
override func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? {
switch identifier {
case .closeUnderbar:
return createCloseItem()
case .nowPlaying:
return nowPlaying.item
default:
return super.touchBar(touchBar, makeItemForIdentifier: identifier)
}
}
func createCloseItem() -> NSTouchBarItem {
let item = NSCustomTouchBarItem(identifier: .closeUnderbar)
let button = NSButton(image: NSImage(named: "underbar")!, target: self, action: #selector(toggle))
button.widthAnchor.constraint(equalToConstant: 40).isActive = true
item.view = button
return item
}
}

View File

@ -0,0 +1,48 @@
//
// TouchBarController.swift
// Underbar
//
// Created by Shadowfacts on 7/13/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import Cocoa
class TouchBarController: NSObject, NSTouchBarDelegate {
let touchBar = NSTouchBar()
var widgets: [TouchBarWidget] = []
var isVisible = false
override init() {
super.init()
touchBar.delegate = self
}
@objc func toggle() {
if isVisible {
minimize()
} else {
present()
}
}
func present() {
NSTouchBar.presentSystemModalTouchBar(touchBar, placement: 1, systemTrayItemIdentifier: .underbar)
isVisible = true
DFRElementSetControlStripPresenceForIdentifier(.underbar, true)
}
func minimize() {
NSTouchBar.minimizeSystemModalTouchBar(touchBar)
isVisible = false
DFRElementSetControlStripPresenceForIdentifier(.underbar, true)
}
func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? {
return nil
}
}

View File

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

25
Underbar/NSTouchBar.h Normal file
View File

@ -0,0 +1,25 @@
//
// NSTouchbar.h
// Underbar
//
// Created by Shadowfacts on 7/13/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
#import <AppKit/AppKit.h>
extern void DFRElementSetControlStripPresenceForIdentifier(_Nonnull NSTouchBarItemIdentifier, BOOL);
extern void DFRSystemModalShowsCloseBoxWhenFrontMost(BOOL);
@interface NSTouchBarItem ()
+ (void)addSystemTrayItem:(nonnull NSTouchBarItem *)item;
@end
@interface NSTouchBar ()
+ (void)presentSystemModalTouchBar:(nonnull NSTouchBar *)touchBar placement:(long long)placement systemTrayItemIdentifier:(nonnull NSTouchBarItemIdentifier)identifier NS_AVAILABLE_MAC(10.14);
+ (void)minimizeSystemModalTouchBar:(nonnull NSTouchBar *)touchBar NS_AVAILABLE_MAC(10.14);
@end

View File

@ -0,0 +1,17 @@
//
// TouchBarItemIdentifiers.swift
// Underbar
//
// Created by Shadowfacts on 7/13/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import Cocoa
extension NSTouchBarItem.Identifier {
static let underbar = NSTouchBarItem.Identifier("underbar")
static let closeUnderbar = NSTouchBarItem.Identifier("underbar_close")
static let nowPlaying = NSTouchBarItem.Identifier("underbar_now_playing")
}

View File

@ -0,0 +1,9 @@
//
// Underbar-Bridging-Header.h
// Underbar
//
// Created by Shadowfacts on 7/13/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
#import "NSTouchBar.h"

View File

@ -1,27 +0,0 @@
//
// ViewController.swift
// Underbar
//
// Created by Shadowfacts on 7/13/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import Cocoa
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
}

View File

@ -0,0 +1,18 @@
//
// NowPlayingWidget.swift
// Underbar
//
// Created by Shadowfacts on 7/13/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import Cocoa
class NowPlayingWidget: TouchBarWidget {
override init() {
super.init()
item = NSButtonTouchBarItem(identifier: .nowPlaying, title: "Test", target: nil, action: nil)
}
}

View File

@ -0,0 +1,24 @@
//
// TouchBarWidget.swift
// Underbar
//
// Created by Shadowfacts on 7/13/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import Cocoa
class TouchBarWidget: NSObject {
var item: NSTouchBarItem!
override init() {
super.init()
}
convenience init(item: NSTouchBarItem) {
self.init()
self.item = item
}
}