feat: quit the app when the window is closed

This commit is contained in:
Vatsaev Aslan 2019-12-10 08:17:47 +01:00
parent c0d46ca9f4
commit 8aeace623f
No known key found for this signature in database
GPG key ID: 3AA14A8E01168835
4 changed files with 47 additions and 23 deletions

View file

@ -125,20 +125,20 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0810;
LastUpgradeCheck = 0810;
LastUpgradeCheck = 1120;
ORGANIZATIONNAME = AVatsaev;
TargetAttributes = {
A362A1011DCE6D6B00737197 = {
CreatedOnToolsVersion = 8.1;
DevelopmentTeam = CW482378P7;
LastSwiftMigration = 0900;
DevelopmentTeam = 9K2GY8824J;
LastSwiftMigration = 1120;
ProvisioningStyle = Automatic;
};
};
};
buildConfigurationList = A362A0FD1DCE6D6B00737197 /* Build configuration list for PBXProject "touchbar_nyancat" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
@ -201,20 +201,30 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@ -250,20 +260,30 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@ -291,14 +311,15 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_IDENTITY = "Apple Development";
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = CW482378P7;
DEVELOPMENT_TEAM = 9K2GY8824J;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = touchbar_nyancat/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.vatsaev.touchbar-nyancat";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
@ -306,14 +327,15 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_IDENTITY = "Apple Development";
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = CW482378P7;
DEVELOPMENT_TEAM = 9K2GY8824J;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = touchbar_nyancat/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.vatsaev.touchbar-nyancat";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0810"
LastUpgradeVersion = "1120"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@ -27,8 +27,6 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
@ -38,8 +36,8 @@
ReferencedContainer = "container:touchbar_nyancat.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
@ -61,8 +59,6 @@
ReferencedContainer = "container:touchbar_nyancat.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"

View file

@ -35,7 +35,7 @@ class NyanCatCanvas: NSImageView {
}
self.canDrawSubviewsIntoLayer = true
self.frame = CGRect(x: xPosition, y: 0, width: 680, height: 30)
// self.frame = CGRect(x: xPosition, y: 0, width: 680, height: 30)
}
override func touchesBegan(with event: NSEvent) {

View file

@ -11,7 +11,7 @@ import AVFoundation
class NyanCatViewController: NSViewController , NSTouchBarDelegate{
class NyanCatViewController: NSViewController , NSTouchBarDelegate, NSWindowDelegate {
@objc var audio_player: AVAudioPlayer?
@ -54,13 +54,20 @@ class NyanCatViewController: NSViewController , NSTouchBarDelegate{
//NOTE: Swift's computed properties FTW!
sound = !sound
}
func windowWillClose(_ notification: Notification) {
NSApplication.shared.terminate(self)
}
override func viewWillAppear() {
super.viewWillAppear()
view.window?.delegate = self
bkg.layer?.backgroundColor = NSColor(red:0.08, green:0.31, blue:0.55, alpha:1.00).cgColor
sound_btn_image_on = NSImage(named: NSImage.Name(rawValue: "ic_volume_up_3x.png"))
sound_btn_image_off = NSImage(named: NSImage.Name(rawValue: "ic_volume_off_3x.png"))
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")!)
@ -74,8 +81,7 @@ class NyanCatViewController: NSViewController , NSTouchBarDelegate{
}catch{}
sound = true
}
override var representedObject: Any? {