-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// swift-tools-version: 5.7 | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "DoNotDisturbPlugin", | ||
platforms: [.macOS(.v12)], | ||
products: [ | ||
.plugin(name: "DoNilDisturbPlugin", targets: ["DoNilDisturb"]) | ||
], | ||
targets: [ | ||
// Your app or library | ||
.executableTarget( | ||
name: "MyApp", | ||
plugins: [ | ||
.plugin(name: "DoNilDisturb") | ||
] | ||
), | ||
// Your plugin's IMPLEMENTATION | ||
.executableTarget( | ||
name: "PluginBinary", | ||
path: "PluginBinary" | ||
), | ||
// Your plugin's INTERFACE | ||
.plugin( | ||
name: "DoNilDisturb", | ||
capability: .buildTool(), | ||
dependencies: [ | ||
.target(name: "PluginBinary") | ||
] | ||
) | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Foundation | ||
|
||
extension String: Error { } | ||
|
||
@main class PluginBinary { | ||
static func main() throws { | ||
let outputURL = URL(fileURLWithPath: ProcessInfo.processInfo.arguments[1]) | ||
let content: String | ||
|
||
if (9.0...18.0 ~= Date().time) { // Your 9-6 basically | ||
// Working hours | ||
content = "// All is good, do not disturb is off." | ||
} else { | ||
// DND | ||
content = #"#error("Do not disturb is ON")"# | ||
} | ||
|
||
try content.write(to: outputURL, atomically: true, encoding: .utf8) | ||
} | ||
} | ||
|
||
// https://stackoverflow.com/a/62616907/208205 | ||
// https://creativecommons.org/licenses/by-sa/4.0/ | ||
extension Date { | ||
/// time returns a double for which the integer represents the hours from 1 to 24 and the decimal value represents the minutes. | ||
var time: Double { | ||
Double(Calendar.current.component(.hour, from: self)) + Double(Calendar.current.component(.minute, from: self)) / 100 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Foundation | ||
import PackagePlugin | ||
|
||
@main | ||
struct DoNilDisturb: BuildToolPlugin { | ||
|
||
func createBuildCommands(context: PackagePlugin.PluginContext, target: PackagePlugin.Target) async throws -> [PackagePlugin.Command] { | ||
let output = context.pluginWorkDirectory.appending(["DND.swift"]) | ||
|
||
return [ | ||
.buildCommand( | ||
displayName: "Do Not Disturb", | ||
executable: try context.tool(named: "PluginBinary").path, | ||
arguments: [output.string], | ||
outputFiles: [output] | ||
) | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,32 @@ | ||
# DoNilDisturbPlugin | ||
A plugin for your Xcode project that stops you from working outside work hours | ||
# DoNilDisturb Swift Plugin | ||
|
||
Use Xcode 14+ to make use of this amazing and novel Swift plugin in your package. | ||
|
||
The plugin stops you from working on your 9-5 project outside of 9-5 hours: | ||
|
||
![Project failing to compile with a message that do not disturb is on](etc/dnd.png) | ||
|
||
Add this to your dependencies in your Package.swift: | ||
|
||
```swift | ||
.package(url: "https://github.com/icanzilb/DoNilDisturbPlugin.git", from: "0.0.1"), | ||
``` | ||
|
||
**And then**, add the plugin in your target definition(still in Package.swift: | ||
|
||
```swift | ||
.target( | ||
name: "MyTarget", | ||
plugins: [ | ||
.plugin(name: "DoNilDisturbPlugin") | ||
] | ||
) | ||
``` | ||
|
||
That's all. Your target will fail to build outside of working hours. | ||
|
||
Enjoy your time off work. | ||
|
||
## License | ||
|
||
MIT, of course. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Foundation | ||
|
||
@main | ||
class MyApp { | ||
static func main() throws { | ||
print("My App runs!") | ||
print("But it only builds during workng hours") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import XCTest | ||
@testable import DoNotDisturbPlugin | ||
|
||
final class DoNotDisturbPluginTests: XCTestCase { | ||
func testExample() throws { | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.