You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2015/08/24 22:33:20 UTC
[2/3] mac commit: CB-9541 Add preferences to put app into "kiosk mode"
CB-9541 Add preferences to put app into "kiosk mode"
- adding HideMousePointer preference
Project: http://git-wip-us.apache.org/repos/asf/cordova-osx/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-osx/commit/61f89a78
Tree: http://git-wip-us.apache.org/repos/asf/cordova-osx/tree/61f89a78
Diff: http://git-wip-us.apache.org/repos/asf/cordova-osx/diff/61f89a78
Branch: refs/heads/master
Commit: 61f89a78351d1daf6ab68f8a0fb4814d71a489be
Parents: fd38253
Author: Tobias Bocanegra <tr...@adobe.com>
Authored: Fri Aug 21 17:12:11 2015 -0700
Committer: Tobias Bocanegra <tr...@adobe.com>
Committed: Fri Aug 21 17:12:11 2015 -0700
----------------------------------------------------------------------
CordovaLib/CordovaLib.xcodeproj/project.pbxproj | 8 ++
.../CordovaLib/Classes/CDVViewController.m | 12 +++
.../Classes/Commands/CDVCursorMonitorService.h | 30 ++++++
.../Classes/Commands/CDVCursorMonitorService.m | 103 +++++++++++++++++++
.../project/__PROJECT_NAME__/config.xml | 3 +
5 files changed, 156 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/61f89a78/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
index 18bae63..bd6d943 100644
--- a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
+++ b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
@@ -47,6 +47,8 @@
70BD67BB18FFA12D00A1EFCF /* ShellUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 70BD679518FFA12D00A1EFCF /* ShellUtils.h */; };
70BD67BC18FFA12D00A1EFCF /* ShellUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 70BD679618FFA12D00A1EFCF /* ShellUtils.m */; };
CC6A01B9AD6ECF2D913FF418 /* CDVWindowSizeCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = CC6A03B1971BACCB9183AEFE /* CDVWindowSizeCommand.h */; };
+ CC6A03130738A1F299369195 /* CDVCursorMonitorService.m in Sources */ = {isa = PBXBuildFile; fileRef = CC6A07666A2CE3AE46F85AD6 /* CDVCursorMonitorService.m */; };
+ CC6A060DFE3B49803140B568 /* CDVCursorMonitorService.h in Headers */ = {isa = PBXBuildFile; fileRef = CC6A08BE679E9B2A17CB995E /* CDVCursorMonitorService.h */; };
CC6A061F0987401A5AB7FE69 /* NSScreen+Utils.h in Headers */ = {isa = PBXBuildFile; fileRef = CC6A00E23A9BC2910E28D36E /* NSScreen+Utils.h */; };
CC6A07EE3FA39E9ED21FC2AD /* CDVWindowSizeCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = CC6A0DB9905DAB3A94C6BCC8 /* CDVWindowSizeCommand.m */; };
CC6A0C2EAD9E57810677CE21 /* NSScreen+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = CC6A01EC9D87C6FC66791911 /* NSScreen+Utils.m */; };
@@ -103,6 +105,8 @@
CC6A00E23A9BC2910E28D36E /* NSScreen+Utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSScreen+Utils.h"; sourceTree = "<group>"; };
CC6A01EC9D87C6FC66791911 /* NSScreen+Utils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSScreen+Utils.m"; sourceTree = "<group>"; };
CC6A03B1971BACCB9183AEFE /* CDVWindowSizeCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDVWindowSizeCommand.h; sourceTree = "<group>"; };
+ CC6A07666A2CE3AE46F85AD6 /* CDVCursorMonitorService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVCursorMonitorService.m; sourceTree = "<group>"; };
+ CC6A08BE679E9B2A17CB995E /* CDVCursorMonitorService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDVCursorMonitorService.h; sourceTree = "<group>"; };
CC6A0DB9905DAB3A94C6BCC8 /* CDVWindowSizeCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVWindowSizeCommand.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -220,6 +224,8 @@
70BD678F18FFA12D00A1EFCF /* CDVReachability.m */,
CC6A0DB9905DAB3A94C6BCC8 /* CDVWindowSizeCommand.m */,
CC6A03B1971BACCB9183AEFE /* CDVWindowSizeCommand.h */,
+ CC6A08BE679E9B2A17CB995E /* CDVCursorMonitorService.h */,
+ CC6A07666A2CE3AE46F85AD6 /* CDVCursorMonitorService.m */,
);
path = Commands;
sourceTree = "<group>";
@@ -269,6 +275,7 @@
70BD67B918FFA12D00A1EFCF /* NSWindow+Utils.h in Headers */,
CC6A01B9AD6ECF2D913FF418 /* CDVWindowSizeCommand.h in Headers */,
CC6A061F0987401A5AB7FE69 /* NSScreen+Utils.h in Headers */,
+ CC6A060DFE3B49803140B568 /* CDVCursorMonitorService.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -343,6 +350,7 @@
70BD67A718FFA12D00A1EFCF /* CDVConnection.m in Sources */,
CC6A07EE3FA39E9ED21FC2AD /* CDVWindowSizeCommand.m in Sources */,
CC6A0C2EAD9E57810677CE21 /* NSScreen+Utils.m in Sources */,
+ CC6A03130738A1F299369195 /* CDVCursorMonitorService.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/61f89a78/CordovaLib/CordovaLib/Classes/CDVViewController.m
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib/Classes/CDVViewController.m b/CordovaLib/CordovaLib/Classes/CDVViewController.m
index 6e8c1f4..cacc15f 100644
--- a/CordovaLib/CordovaLib/Classes/CDVViewController.m
+++ b/CordovaLib/CordovaLib/Classes/CDVViewController.m
@@ -21,6 +21,7 @@
#import "CDVConfigParser.h"
#import "CDVCommandDelegateImpl.h"
#import "CDVWindowSizeCommand.h"
+#import "CDVCursorMonitorService.h"
@interface CDVViewController ()
@@ -91,6 +92,7 @@
[self configureWebGL: prefs];
[self configureLocalStorage:prefs];
[self configureWindowSize];
+ [self configureHideMousePointer];
[self.webView setPreferences:prefs];
}
@@ -229,6 +231,16 @@
}
}
+/**
+ * Configures the hideMousePointer preference.
+ */
+- (void) configureHideMousePointer {
+ NSString *hide = self.settings[@"HideMousePointer"];
+ if (hide) {
+ [[CDVCursorMonitorService service] startWithTimeout:[hide integerValue]];
+ }
+}
+
- (void)registerPlugin:(CDVPlugin*)plugin withClassName:(NSString*)className
{
if ([plugin respondsToSelector:@selector(setViewController:)]) {
http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/61f89a78/CordovaLib/CordovaLib/Classes/Commands/CDVCursorMonitorService.h
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVCursorMonitorService.h b/CordovaLib/CordovaLib/Classes/Commands/CDVCursorMonitorService.h
new file mode 100644
index 0000000..3cca760
--- /dev/null
+++ b/CordovaLib/CordovaLib/Classes/Commands/CDVCursorMonitorService.h
@@ -0,0 +1,30 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <Foundation/Foundation.h>
+
+@interface CDVCursorMonitorService : NSObject
+
++ (CDVCursorMonitorService*) service;
+
+- (void) startWithTimeout: (CFTimeInterval) timeout;
+
+- (void) stop;
+
+@end
http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/61f89a78/CordovaLib/CordovaLib/Classes/Commands/CDVCursorMonitorService.m
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVCursorMonitorService.m b/CordovaLib/CordovaLib/Classes/Commands/CDVCursorMonitorService.m
new file mode 100644
index 0000000..461bc71
--- /dev/null
+++ b/CordovaLib/CordovaLib/Classes/Commands/CDVCursorMonitorService.m
@@ -0,0 +1,103 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVCursorMonitorService.h"
+
+@interface CDVCursorMonitorService ()
+ @property(nonatomic, readwrite) BOOL isRunning;
+ @property(nonatomic) CFTimeInterval timeout;
+@end
+
+@implementation CDVCursorMonitorService {
+ CFAbsoluteTime cursorLastMovedTime;
+ NSTimer* cursorHideTimer;
+ id localMonitor;
+ id globalMonitor;
+}
+
+#pragma mark - Public methods
+
++ (CDVCursorMonitorService*) service {
+ static CDVCursorMonitorService* sharedInstance;
+ static dispatch_once_t onceToken;
+
+ dispatch_once(&onceToken, ^{
+ sharedInstance = [[CDVCursorMonitorService alloc] init];
+ });
+
+ return sharedInstance;
+}
+
+- (void) startWithTimeout:(CFTimeInterval) timeout {
+ if (!self.isRunning) {
+ self.timeout = timeout;
+ cursorLastMovedTime = CFAbsoluteTimeGetCurrent();
+
+ if (timeout > 0) {
+ localMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:NSMouseMovedMask | NSLeftMouseDraggedMask handler:^NSEvent*(NSEvent* event) {
+ cursorLastMovedTime = CFAbsoluteTimeGetCurrent();
+ CGDisplayShowCursor(kCGDirectMainDisplay);
+ return event;
+ }];
+
+ globalMonitor = [NSEvent addGlobalMonitorForEventsMatchingMask:NSMouseMovedMask | NSLeftMouseDraggedMask handler:^(NSEvent* event) {
+ cursorLastMovedTime = CFAbsoluteTimeGetCurrent();
+ CGDisplayShowCursor(kCGDirectMainDisplay);
+ }];
+ cursorHideTimer = [NSTimer scheduledTimerWithTimeInterval:1
+ target:self
+ selector:@selector(handleCursorHideTimerFire:)
+ userInfo:nil
+ repeats:YES];
+ } else {
+ // hide the cursor immediately when the application becomes active
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleCursorHideTimerFire:)
+ name:NSApplicationDidBecomeActiveNotification
+ object:nil];
+ CGDisplayHideCursor(kCGDirectMainDisplay);
+ }
+ [self setIsRunning:YES];
+ }
+}
+
+- (void) stop {
+ if (self.isRunning) {
+ [NSEvent removeMonitor:localMonitor];
+ [NSEvent removeMonitor:globalMonitor];
+ [cursorHideTimer invalidate];
+ localMonitor = nil;
+ globalMonitor = nil;
+ cursorHideTimer = nil;
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationDidBecomeActiveNotification object:nil];
+
+ CGDisplayShowCursor(kCGDirectMainDisplay);
+
+ [self setIsRunning:NO];
+ }
+}
+
+#pragma mark - Private methods
+
+- (void) handleCursorHideTimerFire:(NSTimer*) timer {
+ if (CFAbsoluteTimeGetCurrent() - cursorLastMovedTime >= self.timeout) {
+ CGDisplayHideCursor(kCGDirectMainDisplay);
+ }
+}
+
+@end
http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/61f89a78/bin/templates/project/__PROJECT_NAME__/config.xml
----------------------------------------------------------------------
diff --git a/bin/templates/project/__PROJECT_NAME__/config.xml b/bin/templates/project/__PROJECT_NAME__/config.xml
index b24415a..7df4511 100644
--- a/bin/templates/project/__PROJECT_NAME__/config.xml
+++ b/bin/templates/project/__PROJECT_NAME__/config.xml
@@ -24,6 +24,9 @@
<!-- OSX: size of the application window in the format "wxh". special values 'auto' and 'fullscreen' -->
<preference name="WindowSize" value="auto" />
+ <!-- OSX: idle duration in seconds after which the mouse pointer should be hidden. '0' for always.-->
+ <preference name="HideMousePointer" value="1" />
+
<name>__PROJECT_NAME__</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org