Skip to content

Commit

Permalink
Merge pull request #62 from FlutterPlaza/fix-duplicate-interface
Browse files Browse the repository at this point in the history
fix: duplicate interface definition for class 'NoScreenshotPlugin'
  • Loading branch information
fonkamloic authored Dec 14, 2024
2 parents 6418016 + 4863749 commit b95a0c7
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 28 deletions.
29 changes: 29 additions & 0 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
PODS:
- Flutter (1.0.0)
- no_screenshot (0.3.2-beta.1):
- Flutter
- ScreenProtectorKit (~> 1.3.1)
- ScreenProtectorKit (1.3.1)

DEPENDENCIES:
- Flutter (from `Flutter`)
- no_screenshot (from `.symlinks/plugins/no_screenshot/ios`)

SPEC REPOS:
trunk:
- ScreenProtectorKit

EXTERNAL SOURCES:
Flutter:
:path: Flutter
no_screenshot:
:path: ".symlinks/plugins/no_screenshot/ios"

SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
no_screenshot: 908a71edc63ea17016f46537e0f420bc3856ce2c
ScreenProtectorKit: 83a6281b02c7a5902ee6eac4f5045f674e902ae4

PODFILE CHECKSUM: c4c93c5f6502fe2754f48404d3594bf779584011

COCOAPODS: 1.15.2
2 changes: 1 addition & 1 deletion example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import Foundation
import no_screenshot

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
NoScreenshotPlugin.register(with: registry.registrar(forPlugin: "NoScreenshotPlugin"))
MacOSNoScreenshotPlugin.register(with: registry.registrar(forPlugin: "MacOSNoScreenshotPlugin"))
}
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.3.2-beta.1"
version: "0.3.2-beta.2"
path:
dependency: transitive
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Flutter
import UIKit
import ScreenProtectorKit

public class NoScreenshotPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
public class IOSNoScreenshotPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
private var screenProtectorKit: ScreenProtectorKit? = nil
private static var methodChannel: FlutterMethodChannel? = nil
private static var eventChannel: FlutterEventChannel? = nil
Expand All @@ -24,7 +24,7 @@ public class NoScreenshotPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
super.init()

// Restore the saved state from UserDefaults
var fetchVal = UserDefaults.standard.bool(forKey: NoScreenshotPlugin.preventScreenShotKey)
var fetchVal = UserDefaults.standard.bool(forKey: IOSNoScreenshotPlugin.preventScreenShotKey)
updateScreenshotState(isScreenshotBlocked: fetchVal)
}

Expand All @@ -36,7 +36,7 @@ public class NoScreenshotPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
let screenProtectorKit = ScreenProtectorKit(window: window as? UIWindow)
screenProtectorKit.configurePreventionScreenshot()

let instance = NoScreenshotPlugin(screenProtectorKit: screenProtectorKit)
let instance = IOSNoScreenshotPlugin(screenProtectorKit: screenProtectorKit)
registrar.addMethodCallDelegate(instance, channel: methodChannel!)
eventChannel?.setStreamHandler(instance)
registrar.addApplicationDelegate(instance)
Expand Down Expand Up @@ -64,16 +64,16 @@ public class NoScreenshotPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {

func persistState() {
// Persist the state when changed
UserDefaults.standard.set(NoScreenshotPlugin.preventScreenShot, forKey: NoScreenshotPlugin.preventScreenShotKey)
print("Persisted state: \(NoScreenshotPlugin.preventScreenShot)")
UserDefaults.standard.set(IOSNoScreenshotPlugin.preventScreenShot, forKey: IOSNoScreenshotPlugin.preventScreenShotKey)
print("Persisted state: \(IOSNoScreenshotPlugin.preventScreenShot)")
updateSharedPreferencesState("")
}

func fetchPersistedState() {
// Restore the saved state from UserDefaults
var fetchVal = UserDefaults.standard.bool(forKey: NoScreenshotPlugin.preventScreenShotKey) ? NoScreenshotPlugin.DISABLESCREENSHOT :NoScreenshotPlugin.ENABLESCREENSHOT
var fetchVal = UserDefaults.standard.bool(forKey: IOSNoScreenshotPlugin.preventScreenShotKey) ? IOSNoScreenshotPlugin.DISABLESCREENSHOT :IOSNoScreenshotPlugin.ENABLESCREENSHOT
updateScreenshotState(isScreenshotBlocked: fetchVal)
print("Fetched state: \(NoScreenshotPlugin.preventScreenShot)")
print("Fetched state: \(IOSNoScreenshotPlugin.preventScreenShot)")
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
Expand All @@ -85,7 +85,7 @@ public class NoScreenshotPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
shotOn()
result(true)
case "toggleScreenshot":
NoScreenshotPlugin.preventScreenShot ? shotOn(): shotOff()
IOSNoScreenshotPlugin.preventScreenShot ? shotOn(): shotOff()
result(true)
case "startScreenshotListening":
startListening()
Expand All @@ -99,13 +99,13 @@ public class NoScreenshotPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
}

private func shotOff() {
NoScreenshotPlugin.preventScreenShot = NoScreenshotPlugin.DISABLESCREENSHOT
IOSNoScreenshotPlugin.preventScreenShot = IOSNoScreenshotPlugin.DISABLESCREENSHOT
screenProtectorKit?.enabledPreventScreenshot()
persistState()
}

private func shotOn() {
NoScreenshotPlugin.preventScreenShot = NoScreenshotPlugin.ENABLESCREENSHOT
IOSNoScreenshotPlugin.preventScreenShot = IOSNoScreenshotPlugin.ENABLESCREENSHOT
screenProtectorKit?.disablePreventScreenshot()
persistState()
}
Expand All @@ -122,7 +122,7 @@ public class NoScreenshotPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {

@objc private func screenshotDetected() {
print("Screenshot detected")
updateSharedPreferencesState(NoScreenshotPlugin.screenshotPathPlaceholder)
updateSharedPreferencesState(IOSNoScreenshotPlugin.screenshotPathPlaceholder)
}

private func updateScreenshotState(isScreenshotBlocked: Bool) {
Expand All @@ -135,7 +135,7 @@ public class NoScreenshotPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {

private func updateSharedPreferencesState(_ screenshotData: String) {
let map: [String: Any] = [
"is_screenshot_on": NoScreenshotPlugin.preventScreenShot,
"is_screenshot_on": IOSNoScreenshotPlugin.preventScreenShot,
"screenshot_path": screenshotData,
"was_screenshot_taken": !screenshotData.isEmpty
]
Expand Down
2 changes: 1 addition & 1 deletion ios/Classes/NoScreenshotPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

@implementation NoScreenshotPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
[NoScreenshotPlugin registerWithRegistrar:registrar];
[IOSNoScreenshotPlugin registerWithRegistrar:registrar];
}
@end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Cocoa
import FlutterMacOS

public class NoScreenshotPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
public class MacOSNoScreenshotPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
private static var methodChannel: FlutterMethodChannel? = nil
private static var eventChannel: FlutterEventChannel? = nil
private static var preventScreenShot: Bool = false
Expand All @@ -21,7 +21,7 @@ public class NoScreenshotPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
methodChannel = FlutterMethodChannel(name: methodChannelName, binaryMessenger: registrar.messenger)
eventChannel = FlutterEventChannel(name: eventChannelName, binaryMessenger: registrar.messenger)

let instance = NoScreenshotPlugin()
let instance = MacOSNoScreenshotPlugin()
registrar.addMethodCallDelegate(instance, channel: methodChannel!)
eventChannel?.setStreamHandler(instance)

Expand All @@ -39,15 +39,15 @@ public class NoScreenshotPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
}

func persistState() {
UserDefaults.standard.set(NoScreenshotPlugin.preventScreenShot, forKey: NoScreenshotPlugin.preventScreenShotKey)
print("Persisted state: \(NoScreenshotPlugin.preventScreenShot)")
UserDefaults.standard.set(MacOSNoScreenshotPlugin.preventScreenShot, forKey: MacOSNoScreenshotPlugin.preventScreenShotKey)
print("Persisted state: \(MacOSNoScreenshotPlugin.preventScreenShot)")
updateSharedPreferencesState("")
}

func fetchPersistedState() {
let fetchVal = UserDefaults.standard.bool(forKey: NoScreenshotPlugin.preventScreenShotKey) ? NoScreenshotPlugin.DISABLESCREENSHOT : NoScreenshotPlugin.ENABLESCREENSHOT
let fetchVal = UserDefaults.standard.bool(forKey: MacOSNoScreenshotPlugin.preventScreenShotKey) ? MacOSNoScreenshotPlugin.DISABLESCREENSHOT : MacOSNoScreenshotPlugin.ENABLESCREENSHOT
updateScreenshotState(isScreenshotBlocked: fetchVal)
print("Fetched state: \(NoScreenshotPlugin.preventScreenShot)")
print("Fetched state: \(MacOSNoScreenshotPlugin.preventScreenShot)")
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
Expand All @@ -59,7 +59,7 @@ public class NoScreenshotPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
shotOn()
result(true)
case "toggleScreenshot":
NoScreenshotPlugin.preventScreenShot ? shotOn() : shotOff()
MacOSNoScreenshotPlugin.preventScreenShot ? shotOn() : shotOff()
result(true)
case "startScreenshotListening":
startListening()
Expand All @@ -73,7 +73,7 @@ public class NoScreenshotPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
}

private func shotOff() {
NoScreenshotPlugin.preventScreenShot = NoScreenshotPlugin.DISABLESCREENSHOT
MacOSNoScreenshotPlugin.preventScreenShot = MacOSNoScreenshotPlugin.DISABLESCREENSHOT
print("Screenshot and screen recording prevention activated.")

DispatchQueue.main.async {
Expand All @@ -85,7 +85,7 @@ public class NoScreenshotPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
}

private func shotOn() {
NoScreenshotPlugin.preventScreenShot = NoScreenshotPlugin.ENABLESCREENSHOT
MacOSNoScreenshotPlugin.preventScreenShot = MacOSNoScreenshotPlugin.ENABLESCREENSHOT
print("Screenshot and screen recording prevention deactivated.")

DispatchQueue.main.async {
Expand Down Expand Up @@ -118,7 +118,7 @@ public class NoScreenshotPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {

private func updateSharedPreferencesState(_ screenshotData: String) {
let map: [String: Any] = [
"is_screenshot_on": NoScreenshotPlugin.preventScreenShot,
"is_screenshot_on": MacOSNoScreenshotPlugin.preventScreenShot,
"screenshot_path": screenshotData,
"was_screenshot_taken": !screenshotData.isEmpty
]
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: no_screenshot
description: Flutter plugin to enable, disable, toggle or stream screenshot activities in your application.
version: 0.3.2-beta.1
version: 0.3.2-beta.2
homepage: https://flutterplaza.com
repository: https://github.com/FlutterPlaza/no_screenshot/releases/tag/v0.3.2-beta.1
repository: https://github.com/FlutterPlaza/no_screenshot/releases/tag/v0.3.2-beta.2

environment:
sdk: '>=3.0.0 <4.0.0'
Expand All @@ -29,4 +29,4 @@ flutter:
ios:
pluginClass: NoScreenshotPlugin
macos:
pluginClass: NoScreenshotPlugin
pluginClass: MacOSNoScreenshotPlugin

0 comments on commit b95a0c7

Please sign in to comment.