Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality to enable or disable the PrivacyScreen #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,33 @@
<name>PrivacyScreenPlugin</name>
<description>Secures your app from displaying a screenshot in task switchers under Android and iOS. Keeps sensitive information private.</description>
<license>MIT</license>
<platform name="android">

<config-file parent="/*" target="res/xml/config.xml">
<feature name="PrivacyScreenPlugin">
<param name="android-package" value="org.devgeeks.privacyscreen.PrivacyScreenPlugin"/>
<param name="onload" value="true" />
</feature>
</config-file>
<js-module src="www/PrivacyScreenPlugin.js" name="privacyscreen">
<clobbers target="window.PrivacyScreen" />
</js-module>

<platform name="android">
<config-file parent="/*" target="res/xml/config.xml">
<feature name="PrivacyScreenPlugin">
<param name="android-package" value="org.devgeeks.privacyscreen.PrivacyScreenPlugin"/>
<param name="onload" value="true" />
</feature>
</config-file>

<source-file src="src/android/PrivacyScreenPlugin.java" target-dir="src/org/devgeeks/privacyscreen"/>
</platform>

<platform name="ios">
<config-file parent="/*" target="config.xml">
<feature name="PrivacyScreenPlugin">
<param name="ios-package" value="PrivacyScreenPlugin"/>
<param name="onload" value="true" />
</feature>
<preference name="PrivacyScreenEnabled" value="true" />
</config-file>

<config-file parent="/*" target="config.xml">
<feature name="PrivacyScreenPlugin">
<param name="ios-package" value="PrivacyScreenPlugin"/>
<param name="onload" value="true" />
</feature>
</config-file>

<source-file src="src/ios/PrivacyScreenPlugin.h"/>
<source-file src="src/ios/PrivacyScreenPlugin.m"/>
<source-file src="src/ios/PrivacyScreenPlugin.h"/>
<source-file src="src/ios/PrivacyScreenPlugin.m"/>
</platform>

</plugin>
9 changes: 8 additions & 1 deletion src/ios/PrivacyScreenPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ typedef struct {

} CDV_iOSDevice;

@interface PrivacyScreenPlugin : CDVPlugin
@interface PrivacyScreenPlugin : CDVPlugin {
@protected
BOOL _privacyScreenEnabled;
}

@property (readwrite, assign) BOOL privacyScreenEnabled;

- (void)enabled:(CDVInvokedUrlCommand*)command;

@end
23 changes: 23 additions & 0 deletions src/ios/PrivacyScreenPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@

@implementation PrivacyScreenPlugin

- (id)settingForKey:(NSString*)key
{
return [self.commandDelegate.settings objectForKey:[key lowercaseString]];
}

- (void)pluginInitialize
{
if ([self settingForKey:@"PrivacyScreenEnabled"]) {
self.privacyScreenEnabled = [(NSNumber*)[self settingForKey:@"PrivacyScreenEnabled"] boolValue];
}

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification object:nil];

Expand All @@ -30,6 +39,10 @@ - (void)onAppDidBecomeActive:(UIApplication *)application

- (void)onAppWillResignActive:(UIApplication *)application
{
if (!_privacyScreenEnabled) {
return;
}

CDVViewController *vc = (CDVViewController*)self.viewController;
NSString *imgName = [self getImageName:self.viewController.interfaceOrientation delegate:(id<CDVScreenOrientationDelegate>)vc device:[self getCurrentDevice]];
UIImage *splash = [UIImage imageNamed:imgName];
Expand Down Expand Up @@ -151,4 +164,14 @@ - (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(i
return imageName;
}

- (void)enabled:(CDVInvokedUrlCommand*)command
{
id value = [command.arguments objectAtIndex:0];
if (!([value isKindOfClass:[NSNumber class]])) {
value = [NSNumber numberWithBool:NO];
}

self.privacyScreenEnabled = [value boolValue];
}

@end
18 changes: 10 additions & 8 deletions www/PrivacyScreenPlugin.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//var exec = require('cordova/exec');

/**
* Not sure this will even have a JS API
*/
//exports.activate = function(arg, success, error) {
//exec(success, error, "PrivacyScreenPlugin", "activate", [arg]);
//};
var exec = require('cordova/exec');


var PrivacyScreen = function () {};

PrivacyScreen.enabled = function(enabled) {
exec(null, null, "PrivacyScreenPlugin", "enabled", [enabled]);
};

module.exports = PrivacyScreen;