cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shaz...@apache.org
Subject [1/3] mac commit: CB-9541 Add preferences to put app into "kiosk mode"
Date Mon, 24 Aug 2015 20:33:19 GMT
Repository: cordova-osx
Updated Branches:
  refs/heads/master f2704f12b -> 764313e9d


CB-9541 Add preferences to put app into "kiosk mode"

- adding WindowSize 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/fd38253b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-osx/tree/fd38253b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-osx/diff/fd38253b

Branch: refs/heads/master
Commit: fd38253bdfd7d6f1a25214ca4b2be571201c7565
Parents: e9c12d9
Author: Tobias Bocanegra <tripod@adobe.com>
Authored: Fri Aug 21 16:26:10 2015 -0700
Committer: Tobias Bocanegra <tripod@adobe.com>
Committed: Fri Aug 21 16:26:10 2015 -0700

----------------------------------------------------------------------
 CordovaLib/CordovaLib.xcodeproj/project.pbxproj |  16 ++
 .../CordovaLib/Classes/CDVViewController.h      |   7 +-
 .../CordovaLib/Classes/CDVViewController.m      | 182 +++++++++++++------
 .../Classes/Commands/CDVWindowSizeCommand.h     |  32 ++++
 .../Classes/Commands/CDVWindowSizeCommand.m     |  70 +++++++
 .../CordovaLib/Classes/Utils/NSScreen+Utils.h   |  30 +++
 .../CordovaLib/Classes/Utils/NSScreen+Utils.m   |  73 ++++++++
 .../__PROJECT_NAME__/MainViewController.xib     |  51 +-----
 .../project/__PROJECT_NAME__/config.xml         |   6 +
 9 files changed, 364 insertions(+), 103 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/fd38253b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
index 7caacbe..18bae63 100644
--- a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
+++ b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
@@ -46,6 +46,10 @@
 		70BD67BA18FFA12D00A1EFCF /* NSWindow+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef
= 70BD679418FFA12D00A1EFCF /* NSWindow+Utils.m */; };
 		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 */; };
+		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 */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
@@ -96,6 +100,10 @@
 		70BD679618FFA12D00A1EFCF /* ShellUtils.m */ = {isa = PBXFileReference; fileEncoding = 4;
lastKnownFileType = sourcecode.c.objc; path = ShellUtils.m; sourceTree = "<group>";
};
 		70DAA9241908E82600AF3749 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType
= wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework;
sourceTree = SDKROOT; };
 		70E382C81909BBFF0029A2F0 /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType
= wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework;
sourceTree = DEVELOPER_DIR; };
+		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>";
};
+		CC6A0DB9905DAB3A94C6BCC8 /* CDVWindowSizeCommand.m */ = {isa = PBXFileReference; fileEncoding
= 4; lastKnownFileType = sourcecode.c.objc; path = CDVWindowSizeCommand.m; sourceTree = "<group>";
};
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -210,6 +218,8 @@
 				70BD678D18FFA12D00A1EFCF /* CDVPluginResult.m */,
 				70BD678E18FFA12D00A1EFCF /* CDVReachability.h */,
 				70BD678F18FFA12D00A1EFCF /* CDVReachability.m */,
+				CC6A0DB9905DAB3A94C6BCC8 /* CDVWindowSizeCommand.m */,
+				CC6A03B1971BACCB9183AEFE /* CDVWindowSizeCommand.h */,
 			);
 			path = Commands;
 			sourceTree = "<group>";
@@ -223,6 +233,8 @@
 				70BD679418FFA12D00A1EFCF /* NSWindow+Utils.m */,
 				70BD679518FFA12D00A1EFCF /* ShellUtils.h */,
 				70BD679618FFA12D00A1EFCF /* ShellUtils.m */,
+				CC6A01EC9D87C6FC66791911 /* NSScreen+Utils.m */,
+				CC6A00E23A9BC2910E28D36E /* NSScreen+Utils.h */,
 			);
 			path = Utils;
 			sourceTree = "<group>";
@@ -255,6 +267,8 @@
 				70BD67A618FFA12D00A1EFCF /* CDVConnection.h in Headers */,
 				70BD67A018FFA12D00A1EFCF /* CDVCommandDelegateImpl.h in Headers */,
 				70BD67B918FFA12D00A1EFCF /* NSWindow+Utils.h in Headers */,
+				CC6A01B9AD6ECF2D913FF418 /* CDVWindowSizeCommand.h in Headers */,
+				CC6A061F0987401A5AB7FE69 /* NSScreen+Utils.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -327,6 +341,8 @@
 				70BD67BA18FFA12D00A1EFCF /* NSWindow+Utils.m in Sources */,
 				70BD67B418FFA12D00A1EFCF /* CDVPluginResult.m in Sources */,
 				70BD67A718FFA12D00A1EFCF /* CDVConnection.m in Sources */,
+				CC6A07EE3FA39E9ED21FC2AD /* CDVWindowSizeCommand.m in Sources */,
+				CC6A0C2EAD9E57810677CE21 /* NSScreen+Utils.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/fd38253b/CordovaLib/CordovaLib/Classes/CDVViewController.h
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib/Classes/CDVViewController.h b/CordovaLib/CordovaLib/Classes/CDVViewController.h
index 5b75daf..9315f72 100644
--- a/CordovaLib/CordovaLib/Classes/CDVViewController.h
+++ b/CordovaLib/CordovaLib/Classes/CDVViewController.h
@@ -6,9 +6,9 @@
  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
@@ -52,6 +52,9 @@
 @property (nonatomic, readonly, strong) id <CDVCommandDelegate> commandDelegate;
 
 - (id)getCommandInstance:(NSString*)pluginName;
+
+- (IBAction) toggleFullScreen:(id) sender;
+
 - (void)registerPlugin:(CDVPlugin*)plugin withClassName:(NSString*)className;
 - (void)registerPlugin:(CDVPlugin*)plugin withPluginName:(NSString*)pluginName;
 

http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/fd38253b/CordovaLib/CordovaLib/Classes/CDVViewController.m
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib/Classes/CDVViewController.m b/CordovaLib/CordovaLib/Classes/CDVViewController.m
index 89d1cc2..6e8c1f4 100644
--- a/CordovaLib/CordovaLib/Classes/CDVViewController.m
+++ b/CordovaLib/CordovaLib/Classes/CDVViewController.m
@@ -6,9 +6,9 @@
  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
@@ -20,6 +20,7 @@
 #import "CDVViewController.h"
 #import "CDVConfigParser.h"
 #import "CDVCommandDelegateImpl.h"
+#import "CDVWindowSizeCommand.h"
 
 @interface CDVViewController ()
 
@@ -29,6 +30,10 @@
 @property (nonatomic, readwrite, strong) NSArray* startupPluginNames;
 @property (nonatomic, readwrite, strong) NSDictionary* pluginsMap;
 @property (nonatomic, readwrite, assign) BOOL loadFromString;
+@property (readwrite, assign) BOOL initialized;
+
+@property (readwrite, assign) BOOL cfgFullScreen;
+@property (readwrite, assign) NSSize cfgWindowSize;
 
 @end
 
@@ -43,16 +48,14 @@
 
 - (void) awakeFromNib
 {
-    _commandDelegate = [[CDVCommandDelegateImpl alloc] initWithViewController:self];
-
     // make the linker happy since CDVWebViewDelegate is not referenced anywhere and would
be stripped out
     // see http://stackoverflow.com/questions/1725881/unknown-class-myclass-in-interface-builder-file-error-at-runtime
     [CDVWebViewDelegate class];
     //self.webViewDelegate.viewController = self;
-    
+
     NSURL* appURL = nil;
     NSString* loadErr = nil;
-    
+
     if ([self.startPage rangeOfString:@"://"].location != NSNotFound) {
         appURL = [NSURL URLWithString:self.startPage];
     } else if ([self.wwwFolderName rangeOfString:@"://"].location != NSNotFound) {
@@ -68,60 +71,41 @@
             appURL = [NSURL fileURLWithPath:startFilePath];
         }
     }
-    
+
     if (!loadErr) {
         NSURLRequest* appReq = [NSURLRequest requestWithURL:appURL cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:20.0];
         [[self.webView mainFrame] loadRequest:appReq];
-        
+
     } else {
         NSString* html = [NSString stringWithFormat:@"<html><body> %@ </body></html>",
loadErr];
         [[self.webView mainFrame] loadHTMLString:html baseURL:nil];
     }
-    
+
     for (NSString* pluginName in self.startupPluginNames) {
         [self getCommandInstance:pluginName];
     }
-    
-    // initialize items based on settings
-    
-    BOOL enableWebGL = [[self.settings objectForKey:@"EnableWebGL"] boolValue];
+
     WebPreferences* prefs = [self.webView preferences];
     [prefs setAutosaves:YES];
 
-    // Note that this preference may not be Mac App Store safe
-    if (enableWebGL) {
-        [prefs setWebGLEnabled:YES];
-    }
-
-    // ensure that local storage is enable and paths are correct
-    NSString* webStoragePath = [self.settings valueForKey:@"OSXLocalStoragePath"];
-    if (webStoragePath == nil) {
-        NSString* appBundleID = [[NSBundle mainBundle] bundleIdentifier];
-        NSFileManager* fileManager = [[NSFileManager alloc] init];
-        NSError* err = nil;
-        NSURL* dir = [fileManager URLForDirectory:NSApplicationSupportDirectory
-                                         inDomain:NSUserDomainMask
-                                appropriateForURL:nil
-                                           create:YES
-                                            error:&err];
-        if (err) {
-            NSLog(@"error finding app support directory %@", err);
-            webStoragePath = [NSString stringWithFormat:@"~/Library/Application Support/%@",
appBundleID];
-        } else {
-            NSURL* folder = [[NSURL alloc] initFileURLWithPath:[dir path] isDirectory:YES];
-            NSURL* storageURL = [NSURL URLWithString:appBundleID relativeToURL:folder];
-            webStoragePath = storageURL.path;
-        }
-    }
-    [prefs _setLocalStorageDatabasePath:webStoragePath];
-    [prefs setLocalStorageEnabled:YES];
-    NSLog(@"WebStoragePath is '%@', modify in config.xml.", webStoragePath);
+    [self configureWebGL: prefs];
+    [self configureLocalStorage:prefs];
+    [self configureWindowSize];
     [self.webView setPreferences:prefs];
 }
 
-- (void) __init
-{
-    [self loadSettings];
+- (void)__init {
+    if ((self != nil) && !self.initialized) {
+        _commandQueue = [[CDVCommandQueue alloc] initWithViewController:self];
+        _commandDelegate = [[CDVCommandDelegateImpl alloc] initWithViewController:self];
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppDidFinishLaunching:)
+                                                     name:NSApplicationWillFinishLaunchingNotification
object:nil];
+
+        self.initialized = YES;
+
+        // load config.xml settings
+        [self loadSettings];
+    }
 }
 
 - (id) init
@@ -147,17 +131,17 @@
 - (void)loadSettings
 {
     CDVConfigParser* delegate = [[CDVConfigParser alloc] init];
-    
+
     // read from config.xml in the app bundle
     NSString* path = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"xml"];
-    
+
     if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
         NSAssert(NO, @"ERROR: config.xml does not exist.");
         return;
     }
-    
+
     NSURL* url = [NSURL fileURLWithPath:path];
-    
+
     configParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
     if (configParser == nil) {
         NSLog(@"Failed to initialize XML parser.");
@@ -165,33 +149,96 @@
     }
     [configParser setDelegate:((id < NSXMLParserDelegate >)delegate)];
     [configParser parse];
-    
+
     // Get the plugin dictionary, whitelist and settings from the delegate.
     self.pluginsMap = delegate.pluginsDict;
     self.startupPluginNames = delegate.startupPluginNames;
     self.settings = delegate.settings;
-    
+
     // And the start folder/page.
     self.wwwFolderName = @"www";
     self.startPage = delegate.startPage;
     if (self.startPage == nil) {
         self.startPage = @"index.html";
     }
-    
+
     // Initialize the plugin objects dict.
     self.pluginObjects = [[NSMutableDictionary alloc] initWithCapacity:20];
 }
 
+/**
+ * Configures WebGL
+ */
+- (void) configureWebGL: (WebPreferences*) prefs {
+    // initialize items based on settings
+    BOOL enableWebGL = [self.settings[@"EnableWebGL"] boolValue];
+
+    // Note that this preference may not be Mac App Store safe
+    if (enableWebGL) {
+        [prefs setWebGLEnabled:YES];
+    }
+}
+
+/**
+ * Configures Local Storage path
+ */
+- (void) configureLocalStorage: (WebPreferences*) prefs {
+    // ensure that local storage is enable and paths are correct
+    NSString* webStoragePath = self.settings[@"OSXLocalStoragePath"];
+    if (webStoragePath == nil) {
+        NSString* appBundleID = [[NSBundle mainBundle] bundleIdentifier];
+        NSFileManager* fileManager = [[NSFileManager alloc] init];
+        NSError* err = nil;
+        NSURL* dir = [fileManager URLForDirectory:NSApplicationSupportDirectory
+                                         inDomain:NSUserDomainMask
+                                appropriateForURL:nil
+                                           create:YES
+                                            error:&err];
+        if (err) {
+            NSLog(@"error finding app support directory %@", err);
+            webStoragePath = [NSString stringWithFormat:@"~/Library/Application Support/%@",
appBundleID];
+        } else {
+            NSURL* folder = [[NSURL alloc] initFileURLWithPath:[dir path] isDirectory:YES];
+            NSURL* storageURL = [NSURL URLWithString:appBundleID relativeToURL:folder];
+            webStoragePath = storageURL.path;
+        }
+    }
+    [prefs _setLocalStorageDatabasePath:webStoragePath];
+    [prefs setLocalStorageEnabled:YES];
+    NSLog(@"WebStoragePath is '%@', modify in config.xml.", webStoragePath);
+}
+
+/**
+ * Configures the windowsSize preference. the preference either has the format "WxH" or a
constant string "fullscreen" or "auto".
+ */
+- (void) configureWindowSize {
+    _cfgWindowSize.width = 0;
+    _cfgWindowSize.height = 0;
+    _cfgFullScreen = false;
+    NSString* windowSize = self.settings[@"WindowSize"];
+    if (!windowSize) {
+        // use default
+    } else if ([windowSize isEqualToString:@"fullscreen"]) {
+        _cfgFullScreen = true;
+    } else {
+        NSArray *dims = [windowSize componentsSeparatedByString: @"x"];
+        if (dims.count == 2) {
+            _cfgWindowSize.width = [dims[0] integerValue];
+            _cfgWindowSize.height = [dims[1] integerValue];
+        }
+    }
+}
+
 - (void)registerPlugin:(CDVPlugin*)plugin withClassName:(NSString*)className
 {
     if ([plugin respondsToSelector:@selector(setViewController:)]) {
         [plugin setViewController:self];
     }
-    
+
     if ([plugin respondsToSelector:@selector(setCommandDelegate:)]) {
         [plugin setCommandDelegate:_commandDelegate];
     }
-    
+
     [self.pluginObjects setObject:plugin forKey:className];
     [plugin pluginInitialize];
 }
@@ -201,11 +248,11 @@
     if ([plugin respondsToSelector:@selector(setViewController:)]) {
         [plugin setViewController:self];
     }
-    
+
     if ([plugin respondsToSelector:@selector(setCommandDelegate:)]) {
         [plugin setCommandDelegate:_commandDelegate];
     }
-    
+
     NSString* className = NSStringFromClass([plugin class]);
     [self.pluginObjects setObject:plugin forKey:className];
     [self.pluginsMap setValue:className forKey:[pluginName lowercaseString]];
@@ -223,15 +270,15 @@
     // possible issue is there can be duplicates possible if you had:
     // "org.apache.cordova.Foo" and "org.apache.cordova.foo" - only the lower-cased entry
will match
     NSString* className = [self.pluginsMap objectForKey:[pluginName lowercaseString]];
-    
+
     if (className == nil) {
         return nil;
     }
-    
+
     id obj = [self.pluginObjects objectForKey:className];
     if (!obj) {
         obj = [[NSClassFromString (className)alloc] initWithWebView:webView];
-        
+
         if (obj != nil) {
             [self registerPlugin:obj withClassName:className];
         } else {
@@ -241,6 +288,25 @@
     return obj;
 }
 
+/**
+ * Implement our own fullscreen logic
+ */
+- (IBAction) toggleFullScreen:(id)sender {
+    [CDVWindowSizeCommand toggleFullScreen:self.window];
+}
+
+- (void) onAppDidFinishLaunching:(NSNotification*) notification {
+    if (_cfgFullScreen) {
+        [CDVWindowSizeCommand makeFullScreen:self.window];
+    } else if (_cfgWindowSize.height > 0 && _cfgWindowSize.width > 0) {
+        [CDVWindowSizeCommand setSizeOfWindow:self.window size:_cfgWindowSize];
+    }
+    [self showWindow:self];
+    [self.window makeKeyAndOrderFront:self];
+    [[NSApplication sharedApplication] activateIgnoringOtherApps : YES];
+}
+
+
 - (void) windowResized:(NSNotification*)notification;
 {
 }

http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/fd38253b/CordovaLib/CordovaLib/Classes/Commands/CDVWindowSizeCommand.h
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVWindowSizeCommand.h b/CordovaLib/CordovaLib/Classes/Commands/CDVWindowSizeCommand.h
new file mode 100644
index 0000000..9a55ebb
--- /dev/null
+++ b/CordovaLib/CordovaLib/Classes/Commands/CDVWindowSizeCommand.h
@@ -0,0 +1,32 @@
+/*
+ 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 CDVWindowSizeCommand : NSObject
+
++ (void) makeFullScreen:(NSWindow*) window;
+
++ (void) removeFullScreen:(NSWindow*) window;
+
++ (void) toggleFullScreen:(NSWindow*) window;
+
++ (void) setSizeOfWindow:(NSWindow*) window size: (NSSize) size;
+@end

http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/fd38253b/CordovaLib/CordovaLib/Classes/Commands/CDVWindowSizeCommand.m
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVWindowSizeCommand.m b/CordovaLib/CordovaLib/Classes/Commands/CDVWindowSizeCommand.m
new file mode 100644
index 0000000..a8c9307
--- /dev/null
+++ b/CordovaLib/CordovaLib/Classes/Commands/CDVWindowSizeCommand.m
@@ -0,0 +1,70 @@
+/*
+ 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 "CDVWindowSizeCommand.h"
+#import "NSScreen+Utils.h"
+
+@implementation CDVWindowSizeCommand {
+}
+
+static NSRect savedFrameRect;
+
+/**
+ * Makes the window fullscreen by resizing it to the size of all attached displays. This
is different from just entering
+ * normal OSX fullscreen mode which only overs the main display.
+ */
++ (void) makeFullScreen:(NSWindow*) window {
+    NSRect fullScreenRect = [NSScreen fullScreenRect];
+    NSLog(@"Full screen resolution: %.1f x %.1f", fullScreenRect.size.width, fullScreenRect.size.height);
+    [window setStyleMask:window.styleMask & ~NSTitledWindowMask];
+    [window setHidesOnDeactivate:YES];
+    [window setLevel:NSMainMenuWindowLevel + 1];
+    savedFrameRect = window.frame;
+    [window setFrame:fullScreenRect display:YES];
+}
+
+/**
+ * Takes the window off fullscreen mode.
+ */
++ (void) removeFullScreen:(NSWindow*) window {
+    [window setStyleMask:window.styleMask | NSTitledWindowMask];
+    [window setHidesOnDeactivate:NO];
+    [window setLevel:NSNormalWindowLevel];
+    [window setFrame:savedFrameRect display:YES];
+}
+
+/**
+ * Toggles fullscreen mode of the window.
+ */
++ (void) toggleFullScreen:(NSWindow*) window {
+    if ((window.styleMask & NSTitledWindowMask) == NSTitledWindowMask) {
+        [CDVWindowSizeCommand makeFullScreen:window];
+    } else {
+        [CDVWindowSizeCommand removeFullScreen:window];
+    }
+}
+
++ (void) setSizeOfWindow:(NSWindow*) window size:(NSSize) size {
+    NSLog(@"Set window size to %.1f x %.1f", size.width, size.height);
+    NSRect frameRect = window.frame;
+    frameRect.size = size;
+    [window setFrame:frameRect display:YES];
+}
+
+@end

http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/fd38253b/CordovaLib/CordovaLib/Classes/Utils/NSScreen+Utils.h
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib/Classes/Utils/NSScreen+Utils.h b/CordovaLib/CordovaLib/Classes/Utils/NSScreen+Utils.h
new file mode 100644
index 0000000..8a48090
--- /dev/null
+++ b/CordovaLib/CordovaLib/Classes/Utils/NSScreen+Utils.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 <Cocoa/Cocoa.h>
+
+@interface NSScreen (Utils)
+
++ (NSArray*) sortedScreens;
+
++ (NSArray*) sortedScreenRects;
+
++ (NSRect) fullScreenRect;
+
+@end

http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/fd38253b/CordovaLib/CordovaLib/Classes/Utils/NSScreen+Utils.m
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib/Classes/Utils/NSScreen+Utils.m b/CordovaLib/CordovaLib/Classes/Utils/NSScreen+Utils.m
new file mode 100644
index 0000000..30a0da3
--- /dev/null
+++ b/CordovaLib/CordovaLib/Classes/Utils/NSScreen+Utils.m
@@ -0,0 +1,73 @@
+/*
+ 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 "NSScreen+Utils.h"
+
+@implementation NSScreen (Utils)
+
++ (NSArray*) sortedScreens {
+    NSArray* sortedScreens = [[NSScreen screens] sortedArrayUsingComparator:^NSComparisonResult(NSScreen*
screen1, NSScreen* screen2) {
+        if (screen1.frame.origin.x > screen2.frame.origin.x) {
+            return (NSComparisonResult) NSOrderedDescending;
+        }
+
+        if (screen1.frame.origin.x < screen2.frame.origin.x) {
+            return (NSComparisonResult) NSOrderedAscending;
+        }
+
+        return (NSComparisonResult) NSOrderedSame;
+    }];
+    return sortedScreens;
+}
+
++ (NSArray*) sortedScreenRects {
+    NSMutableArray* screenWidths = [[NSMutableArray alloc] init];
+    NSRect mainScreenRect;
+
+    mainScreenRect = [[NSScreen mainScreen] frame];
+    [screenWidths addObject:[NSValue valueWithRect:mainScreenRect]];
+
+    NSArray* sortedScreens = [self sortedScreens];
+
+    for (NSScreen* screen in sortedScreens) {
+        if ([screen isNotEqualTo:[NSScreen mainScreen]] &&
+                screen.frame.origin.y + screen.frame.size.height == mainScreenRect.origin.y
+ mainScreenRect.size.height &&
+                screen.frame.origin.x > mainScreenRect.origin.x) {
+            [screenWidths addObject:[NSValue valueWithRect:screen.frame]];
+        }
+    }
+
+    return screenWidths;
+}
+
++ (NSRect) fullScreenRect {
+    NSArray* screenRects = [self sortedScreenRects];
+    NSRect rect = [[NSScreen mainScreen] frame];
+    CGFloat finalWidth = 0.0f;
+
+    for (NSValue* rectValue in screenRects) {
+        finalWidth += [rectValue rectValue].size.width;
+    }
+
+    rect.size.width = finalWidth;
+
+    return rect;
+}
+
+@end

http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/fd38253b/bin/templates/project/__PROJECT_NAME__/MainViewController.xib
----------------------------------------------------------------------
diff --git a/bin/templates/project/__PROJECT_NAME__/MainViewController.xib b/bin/templates/project/__PROJECT_NAME__/MainViewController.xib
index fbc6137..1d8d96f 100644
--- a/bin/templates/project/__PROJECT_NAME__/MainViewController.xib
+++ b/bin/templates/project/__PROJECT_NAME__/MainViewController.xib
@@ -15,8 +15,8 @@
         <customObject id="-3" userLabel="Application"/>
         <menu title="AMainMenu" systemMenu="main" id="29">
             <items>
-                <menuItem id="56">
-                    <menu key="submenu" systemMenu="apple" id="57">
+                <menuItem title="__PROJECT_NAME__" id="56">
+                    <menu key="submenu" title="__PROJECT_NAME__" systemMenu="apple" id="57">
                         <items>
                             <menuItem title="About __PROJECT_NAME__" id="58">
                                 <modifierMask key="keyEquivalentModifierMask"/>
@@ -53,53 +53,18 @@
                                     <action selector="unhideAllApplications:" target="-1"
id="370"/>
                                 </connections>
                             </menuItem>
-                            <menuItem isSeparatorItem="YES" id="149">
-                                <modifierMask key="keyEquivalentModifierMask" command="YES"/>
-                            </menuItem>
-                            <menuItem title="Quit __PROJECT_NAME__" keyEquivalent="q"
id="136">
-                                <connections>
-                                    <action selector="terminate:" target="-3" id="449"/>
-                                </connections>
-                            </menuItem>
-                        </items>
-                    </menu>
-                </menuItem>
-                <menuItem title="File" id="83"/>
-                <menuItem title="Edit" id="217"/>
-                <menuItem title="Format" id="375">
-                    <modifierMask key="keyEquivalentModifierMask"/>
-                </menuItem>
-                <menuItem title="View" id="295">
-                    <menu key="submenu" title="View" id="296">
-                        <items>
-                            <menuItem title="Enter Full Screen" keyEquivalent="f" id="afF-KY-ioe">
+                            <menuItem title="Toggle Full Screen" keyEquivalent="f" id="afF-KY-ioe">
                                 <modifierMask key="keyEquivalentModifierMask" control="YES"
command="YES"/>
                                 <connections>
-                                    <action selector="toggleFullScreen:" target="-1" id="dWi-nX-EnS"/>
+                                    <action selector="toggleFullScreen:" target="732"
id="nPq-se-igd"/>
                                 </connections>
                             </menuItem>
-                        </items>
-                    </menu>
-                </menuItem>
-                <menuItem title="Window" id="19">
-                    <menu key="submenu" title="Window" systemMenu="window" id="24">
-                        <items>
-                            <menuItem title="Minimize" keyEquivalent="m" id="23">
-                                <connections>
-                                    <action selector="performMiniaturize:" target="-1"
id="37"/>
-                                </connections>
-                            </menuItem>
-                            <menuItem title="Zoom" id="239">
-                                <connections>
-                                    <action selector="performZoom:" target="-1" id="240"/>
-                                </connections>
-                            </menuItem>
-                            <menuItem isSeparatorItem="YES" id="92">
+                            <menuItem isSeparatorItem="YES" id="149">
                                 <modifierMask key="keyEquivalentModifierMask" command="YES"/>
                             </menuItem>
-                            <menuItem title="Bring All to Front" id="5">
+                            <menuItem title="Quit __PROJECT_NAME__" keyEquivalent="q"
id="136">
                                 <connections>
-                                    <action selector="arrangeInFront:" target="-1" id="39"/>
+                                    <action selector="terminate:" target="-3" id="449"/>
                                 </connections>
                             </menuItem>
                         </items>
@@ -119,7 +84,7 @@
                 </menuItem>
             </items>
         </menu>
-        <window title="__PROJECT_NAME__" allowsToolTipsWhenApplicationIsInactive="NO"
autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="371">
+        <window title="__PROJECT_NAME__" allowsToolTipsWhenApplicationIsInactive="NO"
autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default"
id="371">
             <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"
resizable="YES"/>
             <windowCollectionBehavior key="collectionBehavior" fullScreenPrimary="YES"/>
             <rect key="contentRect" x="335" y="299" width="640" height="480"/>

http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/fd38253b/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 59e74a5..b24415a 100644
--- a/bin/templates/project/__PROJECT_NAME__/config.xml
+++ b/bin/templates/project/__PROJECT_NAME__/config.xml
@@ -17,7 +17,13 @@
     <preference name="PageLength" value="0"/>
     <preference name="PaginationBreakingMode" value="page"/>
     <preference name="PaginationMode" value="unpaginated"/>
+
+    <!-- OSX: location of the local storage path -->
     <preference name="OSXLocalStoragePath" value="~/Library/Application Support/__PROJECT_NAME__"/>
+
+    <!-- OSX: size of the application window in the format "wxh". special values 'auto'
and 'fullscreen' -->
+    <preference name="WindowSize" value="auto" />
+
     <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


Mime
View raw message