-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
10 changed files
with
908 additions
and
579 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
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
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,31 @@ | ||
import Intents | ||
|
||
@available(macOS 11.0, *) | ||
public class SetEphemeralPluginIntentHandler: NSObject, SetEphemeralPluginIntentHandling { | ||
@MainActor | ||
public func handle(intent: SetEphemeralPluginIntent) async -> SetEphemeralPluginIntentResponse { | ||
guard let id = intent.name, let content = intent.content, let exitAfter = intent.exitAfter else { | ||
return SetEphemeralPluginIntentResponse() | ||
} | ||
delegate.pluginManager.setEphemeralPlugin(pluginId: id, content: content, exitAfter: Double(truncating: exitAfter)) | ||
return SetEphemeralPluginIntentResponse() | ||
} | ||
|
||
public func resolveName(for intent: SetEphemeralPluginIntent) async -> INStringResolutionResult { | ||
guard let name = intent.name, !name.isEmpty else { | ||
return INStringResolutionResult.needsValue() | ||
} | ||
return INStringResolutionResult.success(with: name) | ||
} | ||
|
||
public func resolveContent(for intent: SetEphemeralPluginIntent) async -> INStringResolutionResult { | ||
guard let content = intent.content, !content.isEmpty else { | ||
return INStringResolutionResult.needsValue() | ||
} | ||
return INStringResolutionResult.success(with: content) | ||
} | ||
|
||
public func resolveExitAfter(for intent: SetEphemeralPluginIntent) async -> INTimeIntervalResolutionResult { | ||
INTimeIntervalResolutionResult.success(with: TimeInterval(truncating: intent.exitAfter ?? 0)) | ||
} | ||
} |
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
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,89 @@ | ||
import Combine | ||
import Foundation | ||
import os | ||
|
||
class EphemeralPlugin: Plugin { | ||
var id: PluginID | ||
let type: PluginType = .Ephemeral | ||
let name: String = "Ephemeral" | ||
let file: String = "none" | ||
|
||
var updateInterval: Double = 60 * 60 * 24 * 100 { | ||
didSet { | ||
cancellable.forEach { $0.cancel() } | ||
cancellable.removeAll() | ||
|
||
guard updateInterval != 0 else { return } | ||
updateTimerPublisher | ||
.autoconnect() | ||
.receive(on: RunLoop.main) | ||
.sink(receiveValue: { [weak self] _ in | ||
self?.terminate() | ||
}).store(in: &cancellable) | ||
} | ||
} | ||
|
||
var metadata: PluginMetadata? | ||
var lastUpdated: Date? | ||
var lastState: PluginState | ||
var lastRefreshReason: PluginRefreshReason = .FirstLaunch | ||
var contentUpdatePublisher = PassthroughSubject<String?, Never>() | ||
var operation: RunPluginOperation<ExecutablePlugin>? | ||
|
||
var content: String? = "..." { | ||
didSet { | ||
guard content != oldValue else { return } | ||
lastUpdated = Date() | ||
contentUpdatePublisher.send(content) | ||
} | ||
} | ||
|
||
var error: Error? | ||
var debugInfo = PluginDebugInfo() | ||
|
||
lazy var invokeQueue: OperationQueue = delegate.pluginManager.pluginInvokeQueue | ||
|
||
var updateTimerPublisher: Timer.TimerPublisher { | ||
Timer.TimerPublisher(interval: updateInterval, runLoop: .main, mode: .default) | ||
} | ||
|
||
var cronTimer: Timer? | ||
|
||
var cancellable: Set<AnyCancellable> = [] | ||
|
||
let prefs = PreferencesStore.shared | ||
|
||
init(id: PluginID, content: String, exitAfter: Double) { | ||
self.id = id | ||
lastState = .Success | ||
os_log("Initialized ephemeral plugin\n%{public}@", log: Log.plugin, description) | ||
refresh(reason: .FirstLaunch) | ||
self.content = content | ||
lastUpdated = Date() | ||
if exitAfter != 0 { | ||
updateInterval = exitAfter | ||
updateTimerPublisher | ||
.autoconnect() | ||
.receive(on: invokeQueue) | ||
.sink(receiveValue: { [weak self] _ in | ||
self?.terminate() | ||
}).store(in: &cancellable) | ||
} | ||
} | ||
|
||
func disable() {} | ||
|
||
func terminate() { | ||
delegate.pluginManager.setEphemeralPlugin(pluginId: id, content: "") | ||
} | ||
|
||
func enable() {} | ||
|
||
func start() {} | ||
|
||
func refresh(reason _: PluginRefreshReason) {} | ||
|
||
func invoke() -> String? { | ||
nil | ||
} | ||
} |
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
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
Oops, something went wrong.