mirror of
https://github.com/avatsaev/touchbar_nyancat
synced 2024-11-24 20:23:06 +00:00
added mute btn and played with computed properties
This commit is contained in:
parent
a1d942eff1
commit
685f759b9f
29 changed files with 114 additions and 23 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
touchbar_nyancat.app/Contents/Resources/ic_volume_off_3x.png
Normal file
BIN
touchbar_nyancat.app/Contents/Resources/ic_volume_off_3x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 704 B |
BIN
touchbar_nyancat.app/Contents/Resources/ic_volume_up_3x.png
Normal file
BIN
touchbar_nyancat.app/Contents/Resources/ic_volume_up_3x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 626 B |
|
@ -6,24 +6,32 @@
|
|||
<dict>
|
||||
<key>Resources/Base.lproj/Main.storyboardc/Info.plist</key>
|
||||
<data>
|
||||
D+r6E3dOSFOd8j+c/1nDO1nKhsA=
|
||||
a/nJsCwDzqSeX22Dex+G4TC6pHE=
|
||||
</data>
|
||||
<key>Resources/Base.lproj/Main.storyboardc/NSWindowController-B8D-0N-5wS.nib/keyedobjects-101201.nib</key>
|
||||
<data>
|
||||
F2h5vrRlEKCuRc8h5vHj1sgJ3Hs=
|
||||
rex2AleGzy7SsoWis2mahqU4H/E=
|
||||
</data>
|
||||
<key>Resources/Base.lproj/Main.storyboardc/NSWindowController-B8D-0N-5wS.nib/keyedobjects.nib</key>
|
||||
<data>
|
||||
iMjr/hWuAQg4RQDisHPiM6AdNDE=
|
||||
oZpx0/yr06n6WWXBgEoxp4XjHlA=
|
||||
</data>
|
||||
<key>Resources/Base.lproj/Main.storyboardc/XfG-lQ-9wD-view-m2S-Jp-Qdl.nib</key>
|
||||
<data>
|
||||
20wn7A8HqRgiOP5bVsDievK78Og=
|
||||
w6eENI7Z44k/SHinRPt1AmuMm/g=
|
||||
</data>
|
||||
<key>Resources/NyanCatCanvas.nib</key>
|
||||
<data>
|
||||
g8HRzKNlbZtprh3YsNHf3AQ2w78=
|
||||
</data>
|
||||
<key>Resources/ic_volume_off_3x.png</key>
|
||||
<data>
|
||||
vpU5qU7trtaGuphPNYPBsykIt+k=
|
||||
</data>
|
||||
<key>Resources/ic_volume_up_3x.png</key>
|
||||
<data>
|
||||
QHz7fVUKbXe25cu/R2l43fHEpLY=
|
||||
</data>
|
||||
<key>Resources/icon.png</key>
|
||||
<data>
|
||||
WudcYlInuEcIvHfC3N+EJVeI8sA=
|
||||
|
@ -182,28 +190,28 @@
|
|||
<dict>
|
||||
<key>hash2</key>
|
||||
<data>
|
||||
GMjzaUtvteV6B35HSHHvSpXBkoaKARV3ycz7dAy37So=
|
||||
RCVqG2FAQ28C4/piccP6X4CQwev1GglZefWtakHYkAE=
|
||||
</data>
|
||||
</dict>
|
||||
<key>Resources/Base.lproj/Main.storyboardc/NSWindowController-B8D-0N-5wS.nib/keyedobjects-101201.nib</key>
|
||||
<dict>
|
||||
<key>hash2</key>
|
||||
<data>
|
||||
7dKMR0612E4op/Ij0+xWNSjnVIW0KK0SlqBewQdFLvE=
|
||||
YhXPdmS0wzNPtC30uvkhktJQUisXOXUX/0y+tXFCBx0=
|
||||
</data>
|
||||
</dict>
|
||||
<key>Resources/Base.lproj/Main.storyboardc/NSWindowController-B8D-0N-5wS.nib/keyedobjects.nib</key>
|
||||
<dict>
|
||||
<key>hash2</key>
|
||||
<data>
|
||||
/j1MqU6h7DW+eWQKyHLW8EpAzzNA06VGR1mgAIaQdpw=
|
||||
9FGVpVkbZQcjqMO9MZusNimlIDPOe2VC+8vLt2cci9c=
|
||||
</data>
|
||||
</dict>
|
||||
<key>Resources/Base.lproj/Main.storyboardc/XfG-lQ-9wD-view-m2S-Jp-Qdl.nib</key>
|
||||
<dict>
|
||||
<key>hash2</key>
|
||||
<data>
|
||||
wNq8hgQGHzQvFo7V59g1ZOyqNH+lwApOVmEypf+Q1r0=
|
||||
bDXCN6ATWEk0jPj7TzNeCu9ekx1R0wKNJ8F0ltLqIRg=
|
||||
</data>
|
||||
</dict>
|
||||
<key>Resources/NyanCatCanvas.nib</key>
|
||||
|
@ -213,6 +221,20 @@
|
|||
K7873FAPSvn0Go2R8dGMWPkH2nQN4dS8wrQP+9DmvlE=
|
||||
</data>
|
||||
</dict>
|
||||
<key>Resources/ic_volume_off_3x.png</key>
|
||||
<dict>
|
||||
<key>hash2</key>
|
||||
<data>
|
||||
fcY3u/RpOiryv3tBi1q0tM4fqCwVV3t611HS92Ewsco=
|
||||
</data>
|
||||
</dict>
|
||||
<key>Resources/ic_volume_up_3x.png</key>
|
||||
<dict>
|
||||
<key>hash2</key>
|
||||
<data>
|
||||
8hj3LjXj0CAZ0i49/fhmwtSsSrfnfi7JPl2ZnCw1ZzE=
|
||||
</data>
|
||||
</dict>
|
||||
<key>Resources/icon.png</key>
|
||||
<dict>
|
||||
<key>hash2</key>
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
A34053A21DCF56600081ABF1 /* ic_volume_off_3x.png in Resources */ = {isa = PBXBuildFile; fileRef = A34053A11DCF56600081ABF1 /* ic_volume_off_3x.png */; };
|
||||
A34053A41DCF56640081ABF1 /* ic_volume_up_3x.png in Resources */ = {isa = PBXBuildFile; fileRef = A34053A31DCF56640081ABF1 /* ic_volume_up_3x.png */; };
|
||||
A362A1061DCE6D6B00737197 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A362A1051DCE6D6B00737197 /* AppDelegate.swift */; };
|
||||
A362A1081DCE6D6B00737197 /* NyanCatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A362A1071DCE6D6B00737197 /* NyanCatViewController.swift */; };
|
||||
A362A10A1DCE6D6B00737197 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A362A1091DCE6D6B00737197 /* Assets.xcassets */; };
|
||||
|
@ -19,6 +21,8 @@
|
|||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
A34053A11DCF56600081ABF1 /* ic_volume_off_3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ic_volume_off_3x.png; sourceTree = "<group>"; };
|
||||
A34053A31DCF56640081ABF1 /* ic_volume_up_3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ic_volume_up_3x.png; sourceTree = "<group>"; };
|
||||
A362A1021DCE6D6B00737197 /* touchbar_nyancat.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = touchbar_nyancat.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
A362A1051DCE6D6B00737197 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
A362A1071DCE6D6B00737197 /* NyanCatViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NyanCatViewController.swift; sourceTree = "<group>"; };
|
||||
|
@ -78,6 +82,8 @@
|
|||
A3826CD61DCE73EA00B7C41E /* img */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A34053A11DCF56600081ABF1 /* ic_volume_off_3x.png */,
|
||||
A34053A31DCF56640081ABF1 /* ic_volume_up_3x.png */,
|
||||
A3A050E31DCEAB08009D9775 /* nyan_long@2x.gif */,
|
||||
A3A050DF1DCE9E03009D9775 /* icon.png */,
|
||||
);
|
||||
|
@ -157,7 +163,9 @@
|
|||
A3A050DC1DCE96BD009D9775 /* nyan_music.mp3 in Resources */,
|
||||
A362A10A1DCE6D6B00737197 /* Assets.xcassets in Resources */,
|
||||
A362A10D1DCE6D6B00737197 /* Main.storyboard in Resources */,
|
||||
A34053A21DCF56600081ABF1 /* ic_volume_off_3x.png in Resources */,
|
||||
A3A050E41DCEAB08009D9775 /* nyan_long@2x.gif in Resources */,
|
||||
A34053A41DCF56640081ABF1 /* ic_volume_up_3x.png in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Bucket
|
||||
type = "1"
|
||||
version = "2.0">
|
||||
</Bucket>
|
|
@ -68,6 +68,26 @@
|
|||
<subviews>
|
||||
<customView translatesAutoresizingMaskIntoConstraints="NO" id="iUM-SV-UtP">
|
||||
<rect key="frame" x="0.0" y="0.0" width="480" height="250"/>
|
||||
<subviews>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="uCH-1A-AJh">
|
||||
<rect key="frame" x="413" y="202" width="53" height="32"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="41" id="QZ9-15-4hC"/>
|
||||
<constraint firstAttribute="height" constant="21" id="Tel-0Z-dcP"/>
|
||||
</constraints>
|
||||
<buttonCell key="cell" type="push" bezelStyle="rounded" imagePosition="only" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyUpOrDown" inset="2" id="Uwj-zc-KXn">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
<connections>
|
||||
<action selector="toggle_sound:" target="XfG-lQ-9wD" id="DxC-Yp-VN2"/>
|
||||
</connections>
|
||||
</buttonCell>
|
||||
</button>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="uCH-1A-AJh" firstAttribute="top" secondItem="iUM-SV-UtP" secondAttribute="top" constant="20" id="Jew-ed-Aov"/>
|
||||
<constraint firstAttribute="trailing" secondItem="uCH-1A-AJh" secondAttribute="trailing" constant="20" id="ZrN-ZA-iBJ"/>
|
||||
</constraints>
|
||||
</customView>
|
||||
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="gMT-xv-P4n">
|
||||
<rect key="frame" x="180" y="63" width="121" height="124"/>
|
||||
|
@ -93,6 +113,7 @@
|
|||
</view>
|
||||
<connections>
|
||||
<outlet property="bkg" destination="iUM-SV-UtP" id="Y8L-Wa-nPi"/>
|
||||
<outlet property="sound_btn" destination="Uwj-zc-KXn" id="jky-Ou-f9G"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
</objects>
|
||||
|
|
|
@ -15,32 +15,67 @@ class NyanCatViewController: NSViewController , NSTouchBarDelegate{
|
|||
|
||||
var audio_player: AVAudioPlayer?
|
||||
|
||||
//NOTE: I fucking love Swift's computed properties!
|
||||
var sound: Bool = true {
|
||||
|
||||
didSet{
|
||||
|
||||
if sound {
|
||||
audio_player?.play()
|
||||
sound_btn.image = sound_btn_image_on
|
||||
}else{
|
||||
audio_player?.pause()
|
||||
sound_btn.image = sound_btn_image_off
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var sound_btn_title: String?
|
||||
var sound_btn_image_on: NSImage?
|
||||
var sound_btn_image_off: NSImage?
|
||||
|
||||
|
||||
@IBOutlet weak var sound_btn: NSButtonCell!
|
||||
@IBOutlet weak var bkg: NSView!
|
||||
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
|
||||
self.view.wantsLayer = true
|
||||
|
||||
let nyan_music = URL(fileURLWithPath: Bundle.main.path(forResource: "nyan_music", ofType: "mp3")!)
|
||||
|
||||
do {
|
||||
|
||||
try audio_player = AVAudioPlayer(contentsOf: nyan_music)
|
||||
audio_player?.numberOfLoops = -1
|
||||
audio_player?.prepareToPlay()
|
||||
|
||||
audio_player?.play()
|
||||
|
||||
}catch{}
|
||||
|
||||
self.view.wantsLayer = true
|
||||
|
||||
}
|
||||
|
||||
|
||||
@IBAction func toggle_sound(_ sender: Any) {
|
||||
|
||||
//NOTE: Swift's computed properties FTW!
|
||||
sound = !sound
|
||||
}
|
||||
|
||||
override func viewWillAppear() {
|
||||
|
||||
bkg.layer?.backgroundColor = NSColor(red:0.08, green:0.31, blue:0.55, alpha:1.00).cgColor
|
||||
|
||||
sound_btn_image_on = NSImage(named: "ic_volume_up_3x.png")
|
||||
sound_btn_image_off = NSImage(named: "ic_volume_off_3x.png")
|
||||
|
||||
|
||||
let nyan_music = URL(fileURLWithPath: Bundle.main.path(forResource: "nyan_music", ofType: "mp3")!)
|
||||
|
||||
do {
|
||||
|
||||
try audio_player = AVAudioPlayer(contentsOf: nyan_music)
|
||||
audio_player?.numberOfLoops = -1
|
||||
audio_player?.prepareToPlay()
|
||||
|
||||
}catch{}
|
||||
|
||||
sound = true
|
||||
|
||||
|
||||
}
|
||||
|
||||
override var representedObject: Any? {
|
||||
|
|
BIN
touchbar_nyancat/ic_volume_off_3x.png
Normal file
BIN
touchbar_nyancat/ic_volume_off_3x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 704 B |
BIN
touchbar_nyancat/ic_volume_up_3x.png
Normal file
BIN
touchbar_nyancat/ic_volume_up_3x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 626 B |
Loading…
Reference in a new issue