Skip to content

Commit

Permalink
feat: macos support
Browse files Browse the repository at this point in the history
  • Loading branch information
fonkamloic committed Nov 8, 2024
1 parent 4d2706c commit adf6974
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion example/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
no_screenshot: fa5b394f299474b86373048f3a4c6e630d5ff029
no_screenshot: 5aa748db902621ad390390274689c8f015d32709

PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367

Expand Down
4 changes: 3 additions & 1 deletion example/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@
A9CC58A1EDA40E034D04800D /* Pods-RunnerTests.release.xcconfig */,
234B5FD704045AB80FD1910F /* Pods-RunnerTests.profile.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
Expand Down Expand Up @@ -579,6 +578,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.11;
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 5.0;
};
Expand Down Expand Up @@ -711,6 +711,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.11;
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
Expand All @@ -731,6 +732,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.11;
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 5.0;
};
Expand Down
16 changes: 9 additions & 7 deletions macos/Classes/NoScreenshotPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,29 +74,31 @@ public class NoScreenshotPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {

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

DispatchQueue.main.async {
if let window = NSApplication.shared.windows.first {
window.sharingType = .none
window.sharingType = .none // Prevents both screenshots and screen recordings
}
}
persistState()
}

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

DispatchQueue.main.async {
if let window = NSApplication.shared.windows.first {
window.sharingType = .readOnly // or .full, depending on your needs
window.sharingType = .readOnly // Allows screenshots and screen recordings
}
}
persistState()
}

private func startListening() {
// macOS does not provide a direct API for screenshot events, so we simulate this.
print("Start listening for screenshot.")
// macOS does not provide a direct API for detecting screen recording events, so we simulate this.
print("Start listening for screenshot and screen recording.")
persistState()
}

Expand All @@ -108,7 +110,7 @@ public class NoScreenshotPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
private func updateScreenshotState(isScreenshotBlocked: Bool) {
DispatchQueue.main.async {
if let window = NSApplication.shared.windows.first {
window.sharingType = isScreenshotBlocked ? .none : .readOnly // or .full
window.sharingType = isScreenshotBlocked ? .none : .readOnly
}
}
print("Updated screenshot state to \(isScreenshotBlocked ? "Blocked" : "Unblocked")")
Expand Down

0 comments on commit adf6974

Please sign in to comment.