Skip to content

Commit

Permalink
feat: add screenshotTaken listener (#54)
Browse files Browse the repository at this point in the history
Co-authored-by: Robin Genz <[email protected]>
  • Loading branch information
qliqdev and robingenz authored Apr 6, 2023
1 parent b446085 commit 8fc812e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const disable = async () => {
* [`disable()`](#disable)
* [`addListener('screenRecordingStarted', ...)`](#addlistenerscreenrecordingstarted)
* [`addListener('screenRecordingStopped', ...)`](#addlistenerscreenrecordingstopped)
* [`addListener('screenshotTaken', ...)`](#addlistenerscreenshottaken)
* [`removeAllListeners()`](#removealllisteners)
* [Interfaces](#interfaces)

Expand Down Expand Up @@ -193,6 +194,28 @@ Only available on iOS for now.
--------------------


### addListener('screenshotTaken', ...)

```typescript
addListener(eventName: 'screenshotTaken', listenerFunc: () => void) => Promise<PluginListenerHandle> & PluginListenerHandle
```

Called when the screenshot is taken.

Only available on iOS for now.

| Param | Type |
| ------------------ | ------------------------------ |
| **`eventName`** | <code>'screenshotTaken'</code> |
| **`listenerFunc`** | <code>() =&gt; void</code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt; & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>

**Since:** 3.1.1

--------------------


### removeAllListeners()

```typescript
Expand Down
6 changes: 6 additions & 0 deletions ios/Plugin/PrivacyScreenPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class PrivacyScreenPlugin: CAPPlugin {
name: UIApplication.willResignActiveNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.onAppDetectCapturing),
name: UIScreen.capturedDidChangeNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.onAppDetectScreenshot),
name: UIApplication.userDidTakeScreenshotNotification, object: nil)
}

deinit {
Expand Down Expand Up @@ -64,6 +66,10 @@ public class PrivacyScreenPlugin: CAPPlugin {
}
}

@objc private func onAppDetectScreenshot() {
self.notifyListeners("screenshotTaken", data: nil)
}

private func privacyScreenConfig() -> PrivacyScreenConfig {
var config = PrivacyScreenConfig()
config.enable = getConfig().getBoolean("enable", config.enable)
Expand Down
11 changes: 11 additions & 0 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ export interface PrivacyScreenPlugin {
eventName: 'screenRecordingStopped',
listenerFunc: () => void,
): Promise<PluginListenerHandle> & PluginListenerHandle;
/**
* Called when the screenshot is taken.
*
* Only available on iOS for now.
*
* @since 3.1.1
*/
addListener(
eventName: 'screenshotTaken',
listenerFunc: () => void,
): Promise<PluginListenerHandle> & PluginListenerHandle;
/**
* Remove all listeners for this plugin.
*
Expand Down

0 comments on commit 8fc812e

Please sign in to comment.