Skip to content

Commit 4be5f0d

Browse files
committed
Patch 1.0.1
feat: - Added macOS support - Added Cocoapods support
1 parent fecd1af commit 4be5f0d

File tree

7 files changed

+102
-6
lines changed

7 files changed

+102
-6
lines changed

.github/release-cocoapods.yml renamed to .github/workflows/release-cocoapods.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
branches:
55
- master
66
workflow_dispatch:
7-
7+
88
jobs:
99
build:
1010
runs-on: macOS-latest

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Mijick
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

MijickTimer.podspec

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Pod::Spec.new do |s|
2+
s.name = 'MijickTimer'
3+
s.summary = 'Modern API for Timer'
4+
s.description = 'MijickTimer is a free, open-source library for the Swift language that makes the process of managing timers much easier and clearer.'
5+
6+
s.version = '1.0.1'
7+
s.ios.deployment_target = '13.0'
8+
s.osx.deployment_target = '10.15'
9+
s.swift_version = '5.0'
10+
11+
s.source_files = 'Sources/**/*'
12+
s.frameworks = 'SwiftUI', 'Foundation', 'Combine'
13+
14+
s.homepage = 'https://github.com/Mijick/Timer.git'
15+
s.license = { :type => 'MIT', :file => 'LICENSE' }
16+
s.author = { 'Mijick' => 'team@mijick.com' }
17+
s.source = { :git => 'https://github.com/Mijick/Timer.git', :tag => s.version.to_s }
18+
end

Package.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import PackageDescription
66
let package = Package(
77
name: "MijickTimer",
88
platforms: [
9-
.iOS(.v13)
9+
.iOS(.v13),
10+
.macOS(.v10_15)
1011
],
1112
products: [
1213
.library(name: "MijickTimer", targets: ["MijickTimer"]),

README.md

+27-2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ Timer is a free and open-source library dedicated for Swift that makes the proce
6262
| **Platforms** | **Minimum Swift Version** |
6363
|:----------|:----------|
6464
| iOS 13+ | 5.0 |
65+
| iPadOS 13+ | 5.0 |
66+
| macOS 10.15+ | 5.0 |
6567

6668
### ⏳ Installation
6769

@@ -74,8 +76,26 @@ Once you have your Swift package set up, adding Timer as a dependency is as easy
7476
dependencies: [
7577
.package(url: "https://github.com/Mijick/Timer", branch(“main”))
7678
]
77-
```
78-
79+
```
80+
81+
#### [Cocoapods][cocoapods]
82+
Cocoapods is a dependency manager for Swift and Objective-C Cocoa projects that helps to scale them elegantly.
83+
84+
Installation steps:
85+
- Install CocoaPods 1.10.0 (or later)
86+
- [Generate CocoaPods][generate_cocoapods] for your project
87+
```Swift
88+
pod init
89+
```
90+
- Add CocoaPods dependency into your `Podfile`
91+
```Swift
92+
pod 'MijickTimer'
93+
```
94+
- Install dependency and generate `.xcworkspace` file
95+
```Swift
96+
pod install
97+
```
98+
- Use new XCode project file `.xcworkspace`
7999
<br>
80100

81101
# Usage
@@ -160,17 +180,22 @@ Timer is released under the MIT license. See [LICENSE][License] for details.
160180
<br>
161181
[Navigattie] - Easier and cleaner way of navigating through your app
162182
<br>
183+
[CalendarView] - Create your own calendar object in no time
184+
<br>
163185
[GridView] - Lay out your data with no effort
164186

165187

166188

167189

168190
[MIT]: https://en.wikipedia.org/wiki/MIT_License
169191
[SPM]: https://www.swift.org/package-manager
192+
[cocoapods]: https://cocoapods.org/
193+
[generate_cocoapods]: https://github.com/square/cocoapods-generate
170194
171195
[Demo]: https://github.com/Mijick/Timer-Demo
172196
[License]: https://github.com/Mijick/Timer/blob/main/LICENSE
173197
174198
[PopupView]: https://github.com/Mijick/PopupView
175199
[Navigattie]: https://github.com/Mijick/Navigattie
200+
[CalendarView]: https://github.com/Mijick/CalendarView
176201
[GridView]: https://github.com/Mijick/GridView

Sources/Internal/Extensions/NotificationCenter++.swift

+14
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,25 @@ import SwiftUI
1313

1414
extension NotificationCenter {
1515
static func addAppStateNotifications(_ observer: Any, onDidEnterBackground backgroundNotification: Selector, onWillEnterForeground foregroundNotification: Selector) {
16+
#if os(iOS)
1617
Self.default.addObserver(observer, selector: (backgroundNotification), name: UIApplication.didEnterBackgroundNotification, object: nil)
1718
Self.default.addObserver(observer, selector: (foregroundNotification), name: UIApplication.willEnterForegroundNotification, object: nil)
19+
20+
#elseif os(macOS)
21+
Self.default.addObserver(observer, selector: (backgroundNotification), name: NSApplication.didResignActiveNotification, object: nil)
22+
Self.default.addObserver(observer, selector: (foregroundNotification), name: NSApplication.willBecomeActiveNotification, object: nil)
23+
24+
#endif
1825
}
1926
static func removeAppStateChangedNotifications(_ observer: Any) {
27+
#if os(iOS)
2028
Self.default.removeObserver(observer, name: UIApplication.didEnterBackgroundNotification, object: nil)
2129
Self.default.removeObserver(observer, name: UIApplication.willEnterForegroundNotification, object: nil)
30+
31+
#elseif os(macOS)
32+
Self.default.removeObserver(observer, name: NSApplication.didResignActiveNotification, object: nil)
33+
Self.default.removeObserver(observer, name: NSApplication.willBecomeActiveNotification, object: nil)
34+
35+
#endif
2236
}
2337
}

Sources/Internal/MTimer.swift

+19-2
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,31 @@ private extension MTimer {
8888
}
8989
private extension MTimer {
9090
func updateInternalTimer(_ start: Bool) { DispatchQueue.main.async { [self] in switch start {
91-
case true: internalTimer = .scheduledTimer(withTimeInterval: publisherTime, repeats: true, block: handleTimeChange); internalTimer?.tolerance = publisherTimeTolerance
92-
case false: internalTimer?.invalidate()
91+
case true: updateInternalTimerStart()
92+
case false: updateInternalTimerStop()
9393
}}}
9494
func updateObservers(_ start: Bool) { switch start {
9595
case true: addObservers()
9696
case false: removeObservers()
9797
}}
9898
}
99+
private extension MTimer {
100+
func updateInternalTimerStart() {
101+
internalTimer = .scheduledTimer(withTimeInterval: publisherTime, repeats: true, block: handleTimeChange)
102+
internalTimer?.tolerance = publisherTimeTolerance
103+
updateInternalTimerStartAddToRunLoop()
104+
}
105+
func updateInternalTimerStop() { internalTimer?.invalidate() }
106+
}
107+
private extension MTimer {
108+
/// **CONTEXT**: On macOS, when the mouse is down in a menu item or other tracking loop, the timer will not start.
109+
/// **DECISION**: Adding a timer the RunLoop seems to fix the issue issue.
110+
func updateInternalTimerStartAddToRunLoop() {
111+
#if os(macOS)
112+
if let internalTimer { RunLoop.main.add(internalTimer, forMode: .common) }
113+
#endif
114+
}
115+
}
99116

100117
// MARK: - Handling Time Change
101118
private extension MTimer {

0 commit comments

Comments
 (0)