From 144e3e42f8170885a10b71834c7928bd006bd33b Mon Sep 17 00:00:00 2001 From: Fred Meng Date: Wed, 8 Dec 2021 20:01:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A4=9A=E7=A7=8D?= =?UTF-8?q?=E6=8C=89=E9=94=AE=E8=A7=A6=E5=8F=91=E7=9A=84=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=EF=BC=9A=E7=A9=BA=E6=A0=BC=E5=90=AF=E5=81=9C=EF=BC=9Besc?= =?UTF-8?q?=E9=87=8D=E7=BD=AE=EF=BC=9Bbackspace=E4=BF=AE=E6=94=B9=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TomatoKitchenTimer.xcodeproj/project.pbxproj | 72 +++++++++---------- .../contents.xcworkspacedata | 2 +- .../xcshareddata/IDEWorkspaceChecks.plist | 0 3 files changed, 37 insertions(+), 37 deletions(-) mode change 100644 => 100755 TomatoKitchenTimer.xcodeproj/project.pbxproj mode change 100644 => 100755 TomatoKitchenTimer.xcodeproj/project.xcworkspace/contents.xcworkspacedata mode change 100644 => 100755 TomatoKitchenTimer.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/TomatoKitchenTimer.xcodeproj/project.pbxproj b/TomatoKitchenTimer.xcodeproj/project.pbxproj old mode 100644 new mode 100755 index 42ede1a..4d229fb --- a/TomatoKitchenTimer.xcodeproj/project.pbxproj +++ b/TomatoKitchenTimer.xcodeproj/project.pbxproj @@ -47,17 +47,17 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 85331A5A1CF3EFA70086BE54 /* TomatoKitchenTimer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TomatoKitchenTimer.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 85331A5A1CF3EFA70086BE54 /* Scream Timer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Scream Timer.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 85331A5D1CF3EFA70086BE54 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 85331A5F1CF3EFA70086BE54 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 85331A611CF3EFA70086BE54 /* Document.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Document.swift; sourceTree = ""; }; 85331A631CF3EFA70086BE54 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 85331A661CF3EFA70086BE54 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 85331A681CF3EFA70086BE54 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 85331A6D1CF3EFA80086BE54 /* TomatoKitchenTimer.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TomatoKitchenTimer.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 85331A6D1CF3EFA80086BE54 /* Scream Timer.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Scream Timer.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 85331A711CF3EFA80086BE54 /* TomatoKitchenTimerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TomatoKitchenTimerTests.swift; sourceTree = ""; }; 85331A731CF3EFA80086BE54 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 85331A781CF3EFA80086BE54 /* TomatoKitchenTimer.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TomatoKitchenTimer.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 85331A781CF3EFA80086BE54 /* Scream Timer.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Scream Timer.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 85331A7E1CF3EFA80086BE54 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 85331A8D1CF4B2430086BE54 /* TimerCore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TimerCore.swift; sourceTree = ""; }; 85331A921CF4B9500086BE54 /* TomatoKitchenTimerUITests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "TomatoKitchenTimerUITests-Bridging-Header.h"; sourceTree = ""; }; @@ -115,9 +115,9 @@ 85331A5B1CF3EFA70086BE54 /* Products */ = { isa = PBXGroup; children = ( - 85331A5A1CF3EFA70086BE54 /* TomatoKitchenTimer.app */, - 85331A6D1CF3EFA80086BE54 /* TomatoKitchenTimer.xctest */, - 85331A781CF3EFA80086BE54 /* TomatoKitchenTimer.xctest */, + 85331A5A1CF3EFA70086BE54 /* Scream Timer.app */, + 85331A6D1CF3EFA80086BE54 /* Scream Timer.xctest */, + 85331A781CF3EFA80086BE54 /* Scream Timer.xctest */, ); name = Products; sourceTree = ""; @@ -175,9 +175,9 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ - 85331A591CF3EFA70086BE54 /* TomatoKitchenTimer */ = { + 85331A591CF3EFA70086BE54 /* Scream Timer */ = { isa = PBXNativeTarget; - buildConfigurationList = 85331A811CF3EFA80086BE54 /* Build configuration list for PBXNativeTarget "TomatoKitchenTimer" */; + buildConfigurationList = 85331A811CF3EFA80086BE54 /* Build configuration list for PBXNativeTarget "Scream Timer" */; buildPhases = ( 85331A561CF3EFA70086BE54 /* Sources */, 85331A571CF3EFA70086BE54 /* Frameworks */, @@ -187,14 +187,14 @@ ); dependencies = ( ); - name = TomatoKitchenTimer; + name = "Scream Timer"; productName = BigTimer; - productReference = 85331A5A1CF3EFA70086BE54 /* TomatoKitchenTimer.app */; + productReference = 85331A5A1CF3EFA70086BE54 /* Scream Timer.app */; productType = "com.apple.product-type.application"; }; - 85331A6C1CF3EFA80086BE54 /* TomatoKitchenTimerTests */ = { + 85331A6C1CF3EFA80086BE54 /* Scream TimerTests */ = { isa = PBXNativeTarget; - buildConfigurationList = 85331A841CF3EFA80086BE54 /* Build configuration list for PBXNativeTarget "TomatoKitchenTimerTests" */; + buildConfigurationList = 85331A841CF3EFA80086BE54 /* Build configuration list for PBXNativeTarget "Scream TimerTests" */; buildPhases = ( 85331A691CF3EFA80086BE54 /* Sources */, 85331A6A1CF3EFA80086BE54 /* Frameworks */, @@ -205,14 +205,14 @@ dependencies = ( 85331A6F1CF3EFA80086BE54 /* PBXTargetDependency */, ); - name = TomatoKitchenTimerTests; + name = "Scream TimerTests"; productName = BigTimerTests; - productReference = 85331A6D1CF3EFA80086BE54 /* TomatoKitchenTimer.xctest */; + productReference = 85331A6D1CF3EFA80086BE54 /* Scream Timer.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; - 85331A771CF3EFA80086BE54 /* TomatoKitchenTimerUITests */ = { + 85331A771CF3EFA80086BE54 /* Scream TimerUITests */ = { isa = PBXNativeTarget; - buildConfigurationList = 85331A871CF3EFA80086BE54 /* Build configuration list for PBXNativeTarget "TomatoKitchenTimerUITests" */; + buildConfigurationList = 85331A871CF3EFA80086BE54 /* Build configuration list for PBXNativeTarget "Scream TimerUITests" */; buildPhases = ( 85331A741CF3EFA80086BE54 /* Sources */, 85331A751CF3EFA80086BE54 /* Frameworks */, @@ -223,9 +223,9 @@ dependencies = ( 85331A7A1CF3EFA80086BE54 /* PBXTargetDependency */, ); - name = TomatoKitchenTimerUITests; + name = "Scream TimerUITests"; productName = BigTimerUITests; - productReference = 85331A781CF3EFA80086BE54 /* TomatoKitchenTimer.xctest */; + productReference = 85331A781CF3EFA80086BE54 /* Scream Timer.xctest */; productType = "com.apple.product-type.bundle.ui-testing"; }; /* End PBXNativeTarget section */ @@ -254,7 +254,7 @@ }; }; }; - buildConfigurationList = 85331A551CF3EFA70086BE54 /* Build configuration list for PBXProject "TomatoKitchenTimer" */; + buildConfigurationList = 85331A551CF3EFA70086BE54 /* Build configuration list for PBXProject "Scream Timer" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = en; hasScannedForEncodings = 0; @@ -267,9 +267,9 @@ projectDirPath = ""; projectRoot = ""; targets = ( - 85331A591CF3EFA70086BE54 /* TomatoKitchenTimer */, - 85331A6C1CF3EFA80086BE54 /* TomatoKitchenTimerTests */, - 85331A771CF3EFA80086BE54 /* TomatoKitchenTimerUITests */, + 85331A591CF3EFA70086BE54 /* Scream Timer */, + 85331A6C1CF3EFA80086BE54 /* Scream TimerTests */, + 85331A771CF3EFA80086BE54 /* Scream TimerUITests */, ); }; /* End PBXProject section */ @@ -343,12 +343,12 @@ /* Begin PBXTargetDependency section */ 85331A6F1CF3EFA80086BE54 /* PBXTargetDependency */ = { isa = PBXTargetDependency; - target = 85331A591CF3EFA70086BE54 /* TomatoKitchenTimer */; + target = 85331A591CF3EFA70086BE54 /* Scream Timer */; targetProxy = 85331A6E1CF3EFA80086BE54 /* PBXContainerItemProxy */; }; 85331A7A1CF3EFA80086BE54 /* PBXTargetDependency */ = { isa = PBXTargetDependency; - target = 85331A591CF3EFA70086BE54 /* TomatoKitchenTimer */; + target = 85331A591CF3EFA70086BE54 /* Scream Timer */; targetProxy = 85331A791CF3EFA80086BE54 /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ @@ -480,7 +480,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.15; PRODUCT_BUNDLE_IDENTIFIER = com.mebusw.TomatoKitchenTimer; - PRODUCT_NAME = TomatoKitchenTimer; + PRODUCT_NAME = "Scream Timer"; SWIFT_VERSION = 5.0; }; name = Debug; @@ -495,7 +495,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.15; PRODUCT_BUNDLE_IDENTIFIER = com.mebusw.TomatoKitchenTimer; - PRODUCT_NAME = TomatoKitchenTimer; + PRODUCT_NAME = "Scream Timer"; SWIFT_VERSION = 5.0; }; name = Release; @@ -508,9 +508,9 @@ INFOPLIST_FILE = TomatoKitchenTimerTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.mebusw.TomatoKitchenTimerTests; - PRODUCT_NAME = TomatoKitchenTimer; + PRODUCT_NAME = "Scream Timer"; SWIFT_VERSION = 3.0; - TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TomatoKitchenTimer.app/Contents/MacOS/TomatoKitchenTimer"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Scream Timer.app/Contents/MacOS/Scream Timer"; }; name = Debug; }; @@ -522,9 +522,9 @@ INFOPLIST_FILE = TomatoKitchenTimerTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.mebusw.TomatoKitchenTimerTests; - PRODUCT_NAME = TomatoKitchenTimer; + PRODUCT_NAME = "Scream Timer"; SWIFT_VERSION = 3.0; - TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TomatoKitchenTimer.app/Contents/MacOS/TomatoKitchenTimer"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Scream Timer.app/Contents/MacOS/Scream Timer"; }; name = Release; }; @@ -536,7 +536,7 @@ INFOPLIST_FILE = TomatoKitchenTimerUITests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.mebusw.TomatoKitchenTimerUITests; - PRODUCT_NAME = TomatoKitchenTimer; + PRODUCT_NAME = "Scream Timer"; SWIFT_OBJC_BRIDGING_HEADER = "TomatoKitchenTimerUITests/TomatoKitchenTimerUITests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 3.0; @@ -552,7 +552,7 @@ INFOPLIST_FILE = TomatoKitchenTimerUITests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.mebusw.TomatoKitchenTimerUITests; - PRODUCT_NAME = TomatoKitchenTimer; + PRODUCT_NAME = "Scream Timer"; SWIFT_OBJC_BRIDGING_HEADER = "TomatoKitchenTimerUITests/TomatoKitchenTimerUITests-Bridging-Header.h"; SWIFT_VERSION = 3.0; TEST_TARGET_NAME = TomatoKitchenTimer; @@ -562,7 +562,7 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 85331A551CF3EFA70086BE54 /* Build configuration list for PBXProject "TomatoKitchenTimer" */ = { + 85331A551CF3EFA70086BE54 /* Build configuration list for PBXProject "Scream Timer" */ = { isa = XCConfigurationList; buildConfigurations = ( 85331A7F1CF3EFA80086BE54 /* Debug */, @@ -571,7 +571,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 85331A811CF3EFA80086BE54 /* Build configuration list for PBXNativeTarget "TomatoKitchenTimer" */ = { + 85331A811CF3EFA80086BE54 /* Build configuration list for PBXNativeTarget "Scream Timer" */ = { isa = XCConfigurationList; buildConfigurations = ( 85331A821CF3EFA80086BE54 /* Debug */, @@ -580,7 +580,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 85331A841CF3EFA80086BE54 /* Build configuration list for PBXNativeTarget "TomatoKitchenTimerTests" */ = { + 85331A841CF3EFA80086BE54 /* Build configuration list for PBXNativeTarget "Scream TimerTests" */ = { isa = XCConfigurationList; buildConfigurations = ( 85331A851CF3EFA80086BE54 /* Debug */, @@ -589,7 +589,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 85331A871CF3EFA80086BE54 /* Build configuration list for PBXNativeTarget "TomatoKitchenTimerUITests" */ = { + 85331A871CF3EFA80086BE54 /* Build configuration list for PBXNativeTarget "Scream TimerUITests" */ = { isa = XCConfigurationList; buildConfigurations = ( 85331A881CF3EFA80086BE54 /* Debug */, diff --git a/TomatoKitchenTimer.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/TomatoKitchenTimer.xcodeproj/project.xcworkspace/contents.xcworkspacedata old mode 100644 new mode 100755 index 9a738ec..945a25a --- a/TomatoKitchenTimer.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/TomatoKitchenTimer.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:/Users/fred/Working/Projects/02 GitProjects/TomatoKitchenTimer/Scream Timer.xcodeproj"> diff --git a/TomatoKitchenTimer.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/TomatoKitchenTimer.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist old mode 100644 new mode 100755 From 2e4557beb152bc25a1bf946792e256ca37158e9e Mon Sep 17 00:00:00 2001 From: Fred Meng Date: Mon, 13 Dec 2021 18:12:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8C=89=E9=94=AE?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=9A=E7=A9=BA=E6=A0=BC=E9=94=AE=E3=80=81?= =?UTF-8?q?=E5=9B=9E=E8=BD=A6=E9=94=AE=E5=90=AF=E5=81=9C=EF=BC=9Besc?= =?UTF-8?q?=E9=94=AE=E5=8F=96=E6=B6=88=E5=92=8C=E9=87=8D=E7=BD=AE=EF=BC=9B?= =?UTF-8?q?backspace=E9=94=AE=E5=88=A0=E9=99=A4=E9=94=99=E8=AF=AF=E9=94=AE?= =?UTF-8?q?=E5=85=A5=E7=9A=84=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TomatoKitchenTimer.xcodeproj/project.pbxproj | 8 +- TomatoKitchenTimer/Base.lproj/Main.storyboard | 12 +- TomatoKitchenTimer/TimerCore.swift | 117 ++++++++++++++---- TomatoKitchenTimer/ViewController.swift | 31 +++-- .../TomatoKitchenTimerTests.swift | 44 +++---- 5 files changed, 150 insertions(+), 62 deletions(-) mode change 100644 => 100755 TomatoKitchenTimer/Base.lproj/Main.storyboard mode change 100644 => 100755 TomatoKitchenTimer/TimerCore.swift mode change 100644 => 100755 TomatoKitchenTimer/ViewController.swift diff --git a/TomatoKitchenTimer.xcodeproj/project.pbxproj b/TomatoKitchenTimer.xcodeproj/project.pbxproj index 4d229fb..c65b4ce 100755 --- a/TomatoKitchenTimer.xcodeproj/project.pbxproj +++ b/TomatoKitchenTimer.xcodeproj/project.pbxproj @@ -235,7 +235,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 1150; + LastUpgradeCheck = 1310; ORGANIZATIONNAME = JackyShen; TargetAttributes = { 85331A591CF3EFA70086BE54 = { @@ -254,7 +254,7 @@ }; }; }; - buildConfigurationList = 85331A551CF3EFA70086BE54 /* Build configuration list for PBXProject "Scream Timer" */; + buildConfigurationList = 85331A551CF3EFA70086BE54 /* Build configuration list for PBXProject "TomatoKitchenTimer" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = en; hasScannedForEncodings = 0; @@ -389,6 +389,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -445,6 +446,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -562,7 +564,7 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 85331A551CF3EFA70086BE54 /* Build configuration list for PBXProject "Scream Timer" */ = { + 85331A551CF3EFA70086BE54 /* Build configuration list for PBXProject "TomatoKitchenTimer" */ = { isa = XCConfigurationList; buildConfigurations = ( 85331A7F1CF3EFA80086BE54 /* Debug */, diff --git a/TomatoKitchenTimer/Base.lproj/Main.storyboard b/TomatoKitchenTimer/Base.lproj/Main.storyboard old mode 100644 new mode 100755 index d994746..8bc6ba3 --- a/TomatoKitchenTimer/Base.lproj/Main.storyboard +++ b/TomatoKitchenTimer/Base.lproj/Main.storyboard @@ -1,7 +1,8 @@ - + - + + @@ -679,7 +680,7 @@ - + @@ -688,10 +689,13 @@ - + + + NSAllRomanInputSourcesLocaleIdentifier + diff --git a/TomatoKitchenTimer/TimerCore.swift b/TomatoKitchenTimer/TimerCore.swift old mode 100644 new mode 100755 index 54804dd..8fe8206 --- a/TomatoKitchenTimer/TimerCore.swift +++ b/TomatoKitchenTimer/TimerCore.swift @@ -11,75 +11,124 @@ import Cocoa class TimerCore: NSObject { var isRunning:Bool = false - var seq:[Int] = [0, 0, 0, 0, 0, 0] + var isEscaping:Bool = false + var seq6:[Int] = [0, 0, 0, 0, 0, 0] + var seq4:[Int] = [0, 0, 0, 0] var targetSeconds:Int = 0 var countDownSeconds:Int = 0 var timer:Timer? var timeUpCallback: () -> Void = {} var tickCallback: () -> Void = {} + var escCallback: () -> Void = {} var startTime:Date? var log: String = "" override init() { super.init() + } - func toogleStartStop(startCallback: () -> Void = {}, stopCallback: () -> Void = {}, timeUpCallback: @escaping () -> Void = {}, tickCallback: @escaping () -> Void = {}) { + func toogleStartStop(startCallback: () -> Void = {}, stopCallback: () -> Void = {}, escCallback: () -> Void = {}, timeUpCallback: @escaping () -> Void = {}, tickCallback: @escaping () -> Void = {}) { self.timeUpCallback = timeUpCallback self.tickCallback = tickCallback - if !isRunning { - self.countDownSeconds = self.targetSeconds - timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(self.tick(_:)), userInfo: nil, repeats: true) - RunLoop.current.add(timer!, forMode: RunLoop.Mode.common) - startTime = Date() - - startCallback() + if isEscaping { + resetAll() + escCallback() + isEscaping = false + isRunning = false + } else { - reset() - stopCallback() + + if !isRunning { + self.countDownSeconds = self.targetSeconds + timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(self.tick(_:)), userInfo: nil, repeats: true) + RunLoop.current.add(timer!, forMode: RunLoop.Mode.common) + startTime = Date() + + startCallback() + } else { + resetCountDown() + stopCallback() + } + isRunning = !isRunning } - isRunning = !isRunning } @objc func tick(_ timer : Timer) { let interval:TimeInterval = Date().timeIntervalSince(startTime!) - print(interval) - print(Date()) - print(startTime ?? 0) - self.log = String.init(format: "%f=====%s======%s\n", interval ,String(describing: startTime!), String(describing: Date())) + countDownSeconds = targetSeconds - Int(interval) self.tickCallback() if countDownSeconds <= 0 { isRunning = false - reset() + resetCountDown() self.timeUpCallback() } } - fileprivate func reset() { + fileprivate func resetCountDown() { countDownSeconds = 0 timer?.invalidate() } - func put(_ number:Int) { - seq.remove(at: 0) - seq.append(number) + fileprivate func resetAll() { + countDownSeconds = 0 + targetSeconds = 0 + seq4 = [0, 0, 0, 0] + + timer?.invalidate() + } + +// 可以设置小时、分钟、秒 + func putHMS(_ number:Int) { + seq6.remove(at: 0) + seq6.append(number) - var hour = seq[0] * 10 + seq[1] + var hour = seq6[0] * 10 + seq6[1] hour = hour > 23 ? 23 : hour - var minute = seq[2] * 10 + seq[3] + var minute = seq6[2] * 10 + seq6[3] minute = minute > 59 ? 59 : minute - var second = seq[4] * 10 + seq[5] + var second = seq6[4] * 10 + seq6[5] second = second > 59 ? 59 : second - + targetSeconds = hour * 3600 + minute * 60 + second } + + + fileprivate func caculateTargetSeconds() { + var minute = seq4[0] * 10 + seq4[1] + minute = minute > 59 ? 59 : minute + var second = seq4[2] * 10 + seq4[3] + second = second > 59 ? 59 : second + + targetSeconds = minute * 60 + second + } + + // 只需要设置分钟和秒 + func putMS(_ number:Int) { + seq4.remove(at: 0) + seq4.append(number) + caculateTargetSeconds() + } - func secToDisplayable(_ seconds: Int) -> String { + func delByBackSpace() + { + if !isRunning { + for index in (1...3).reversed() { + seq4[index] = seq4[index - 1] + } + seq4[0] = 0 + + caculateTargetSeconds() + } + } + + //显示小时分钟秒 + func secToDisplayableHMS(_ seconds: Int) -> String { let hour = seconds / 3600 let minute = (seconds - hour * 3600) / 60 let second = seconds - hour * 3600 - minute * 60 @@ -90,4 +139,20 @@ class TimerCore: NSObject { } return displayable } + + //显示分钟秒 + func secToDisplayableMS(_ seconds: Int) -> String { + + let minute = seconds / 60 + let second = seconds - minute * 60 + + let displayable = String(format: "%02d:%02d", minute, second) + + return displayable + } + + func setEscaping(_ isescaping: Bool) + { + self.isEscaping = isescaping + } } diff --git a/TomatoKitchenTimer/ViewController.swift b/TomatoKitchenTimer/ViewController.swift old mode 100644 new mode 100755 index 0421805..353aeee --- a/TomatoKitchenTimer/ViewController.swift +++ b/TomatoKitchenTimer/ViewController.swift @@ -18,6 +18,10 @@ import AVFoundation class ViewController: NSViewController, NSControlTextEditingDelegate { let KEY_ENTER:UInt16 = 36 + let KEY_SPACE:UInt16 = 49 + let KEY_ESC:UInt16 = 53 + let KEY_BACKSPACE:UInt16 = 51 + @IBOutlet var countDownText:NSTextFieldCell? @IBOutlet var targetText:NSTextFieldCell? @IBOutlet var startStopBtn:NSButton? @@ -30,7 +34,7 @@ class ViewController: NSViewController, NSControlTextEditingDelegate { override func viewDidAppear() { super.viewDidAppear() - self.view.window?.title = "Tomato Timer" + self.view.window?.title = "Scream Timer" } override func viewDidLoad() { @@ -66,21 +70,27 @@ class ViewController: NSViewController, NSControlTextEditingDelegate { startCallback: { //self.startStopBtn?.title = "Stop" self.startStopBtn?.image = NSImage(contentsOf: URL(fileURLWithPath: Bundle.main.path(forResource: "PicButtonStop", ofType: "png")!)) - self.countDownText?.title = self.timerCore.secToDisplayable(self.timerCore.targetSeconds) + self.countDownText?.title = self.timerCore.secToDisplayableMS(self.timerCore.targetSeconds) }, stopCallback: { //self.startStopBtn?.title = "Start" self.startStopBtn?.image = NSImage(contentsOf: URL(fileURLWithPath: Bundle.main.path(forResource: "PicButtonStart", ofType: "png")!)) }, + escCallback: { + self.startStopBtn?.image = NSImage(contentsOf: URL(fileURLWithPath: Bundle.main.path(forResource: "PicButtonStart", ofType: "png")!)) + self.countDownText?.title = self.timerCore.secToDisplayableMS(self.timerCore.countDownSeconds) + self.targetText?.title = self.timerCore.secToDisplayableMS(self.timerCore.countDownSeconds) + }, timeUpCallback: { //self.startStopBtn?.title = "Start" self.startStopBtn?.image = NSImage(contentsOf: URL(fileURLWithPath: Bundle.main.path(forResource: "PicButtonStart", ofType: "png")!)) self.playSoundClip() }, tickCallback: { - self.countDownText?.title = self.timerCore.secToDisplayable(self.timerCore.countDownSeconds) + self.countDownText?.title = self.timerCore.secToDisplayableMS(self.timerCore.countDownSeconds) self.logger?.title += self.timerCore.log - }) + } + ) } @@ -89,11 +99,18 @@ class ViewController: NSViewController, NSControlTextEditingDelegate { print(event.keyCode) switch event.keyCode { - case KEY_ENTER: + case KEY_ENTER,KEY_SPACE: toogleStartStop(self) case 18,19,20,21,23,22,26,28,25,29: - timerCore.put(keyCodeToNumber(event.keyCode)) - targetText?.title = timerCore.secToDisplayable(timerCore.targetSeconds) + timerCore.putMS(keyCodeToNumber(event.keyCode)) + targetText?.title = timerCore.secToDisplayableMS(timerCore.targetSeconds) + case KEY_ESC: + timerCore.setEscaping(true) + toogleStartStop(self) + targetText?.title = timerCore.secToDisplayableMS(timerCore.targetSeconds) + case KEY_BACKSPACE: + timerCore.delByBackSpace() + targetText?.title = timerCore.secToDisplayableMS(timerCore.targetSeconds) default: print("other keys, \(event.keyCode)") } diff --git a/TomatoKitchenTimerTests/TomatoKitchenTimerTests.swift b/TomatoKitchenTimerTests/TomatoKitchenTimerTests.swift index 8133a76..9711192 100644 --- a/TomatoKitchenTimerTests/TomatoKitchenTimerTests.swift +++ b/TomatoKitchenTimerTests/TomatoKitchenTimerTests.swift @@ -31,48 +31,48 @@ class TomatoKitchenTimerTests: XCTestCase { func testPutMoreThanSixNumbers() { - timerCore.put(1) - timerCore.put(2) - timerCore.put(3) - timerCore.put(4) - timerCore.put(5) - timerCore.put(6) - XCTAssertEqual([1, 2, 3, 4, 5, 6], timerCore.seq) + timerCore.putHMS(1) + timerCore.putHMS(2) + timerCore.putHMS(3) + timerCore.putHMS(4) + timerCore.putHMS(5) + timerCore.putHMS(6) + XCTAssertEqual([1, 2, 3, 4, 5, 6], timerCore.seq6) - timerCore.put(7) - XCTAssertEqual([2, 3, 4, 5, 6, 7], timerCore.seq) + timerCore.putHMS(7) + XCTAssertEqual([2, 3, 4, 5, 6, 7], timerCore.seq6) } func testGenerateNumberPairsAndTotal() { - timerCore.put(1) - timerCore.put(2) - timerCore.put(3) - timerCore.put(4) - timerCore.put(5) - timerCore.put(6) + timerCore.putHMS(1) + timerCore.putHMS(2) + timerCore.putHMS(3) + timerCore.putHMS(4) + timerCore.putHMS(5) + timerCore.putHMS(6) XCTAssertEqual(12 * 3600 + 34 * 60 + 56, timerCore.targetSeconds) } func testValidateNumberPairs() { - timerCore.put(7) + timerCore.putHMS(7) XCTAssertEqual(7, timerCore.targetSeconds) - timerCore.put(8) + timerCore.putHMS(8) XCTAssertEqual(59, timerCore.targetSeconds) - timerCore.put(1) + timerCore.putHMS(1) XCTAssertEqual(7 * 60 + 59, timerCore.targetSeconds) - timerCore.put(2) + timerCore.putHMS(2) XCTAssertEqual(59 * 60 + 12, timerCore.targetSeconds) } func testSecondsToDisplayable() { - XCTAssertEqual("00:02", timerCore.secToDisplayable(2)) - XCTAssertEqual("01:02", timerCore.secToDisplayable(62)) - XCTAssertEqual("01:01:02", timerCore.secToDisplayable(3662)) + XCTAssertEqual("00:02", timerCore.secToDisplayableHMS(2)) + XCTAssertEqual("01:02", timerCore.secToDisplayableHMS(62)) + XCTAssertEqual("01:01:02", timerCore.secToDisplayableHMS(3662)) } func testPerformanceExample() {