private void GapBrowser_Loaded(object sender, RoutedEventArgs e) { this.bmHelper.ScrollDisabled = this.DisableBouncyScrolling; // prevents refreshing web control to initial state during pages transitions if (this.IsBrowserInitialized) { return; } this.domStorageHelper = new DOMStorageHelper(this.CordovaBrowser); string deviceUUID = ""; var UserSetting = Windows.Storage.ApplicationData.Current.LocalSettings; if (!UserSetting.Values.ContainsKey("DeviceID")) { UserSetting.Values["DeviceID"] = Guid.NewGuid().ToString(); deviceUUID = UserSetting.Values["DeviceID"].ToString(); } else { deviceUUID = UserSetting.Values["DeviceID"].ToString(); } CordovaBrowser.Navigate(StartPageUri); IsBrowserInitialized = true; }
void page_BackKeyPress(object sender, CancelEventArgs e) { if (OverrideBackButton) { try { CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('backbutton', {}, true);" }); e.Cancel = true; } catch (Exception ex) { Console.WriteLine("Exception while invoking backbutton into cordova view: " + ex.Message); } } else { try { PageDidChange = false; Uri uriBefore = this.Browser.Source; // calling js history.back with result in a page change if history was valid. CordovaBrowser.InvokeScript("eval", new string[] { "(function(){window.history.back();})()" }); Uri uriAfter = this.Browser.Source; e.Cancel = PageDidChange || (uriBefore != uriAfter); } catch (Exception) { e.Cancel = false; // exit the app ... ? } } }
void CordovaBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) { string[] autoloadPlugs = this.configHandler.AutoloadPlugins; foreach (string plugName in autoloadPlugs) { // nativeExecution.ProcessCommand(commandCallParams); } string nativeReady = "(function(){ cordova.require('cordova/channel').onNativeReady.fire()})();"; try { CordovaBrowser.InvokeScript("execScript", new string[] { nativeReady }); } catch (Exception /*ex*/) { Debug.WriteLine("Error calling js to fire nativeReady event. Did you include cordova-x.x.x.js in your html script tag?"); } if (this.CordovaBrowser.Opacity < 1) { this.CordovaBrowser.Opacity = 1; RotateIn.Begin(); } }
void page_BackKeyPress(object sender, CancelEventArgs e) { if (OverrideBackButton) { try { CordovaBrowser.InvokeScript("CordovaCommandResult", new string[] { "backbutton" }); e.Cancel = true; } catch (Exception ex) { Console.WriteLine("Exception while invoking backbutton into cordova view: " + ex.Message); } } else { try { PageDidChange = false; // calling js history.back with result in a page change if history was valid. CordovaBrowser.InvokeScript("eval", new string[] { "(function(){window.history.back();})()" }); e.Cancel = PageDidChange; } catch (Exception) { e.Cancel = false; // exit the app ... ? } } }
void page_BackKeyPress(object sender, CancelEventArgs e) { if (OverrideBackButton) { try { CordovaBrowser.InvokeScript("CordovaCommandResult", new string[] { "backbutton" }); e.Cancel = true; } catch (Exception ex) { Console.WriteLine("Exception while invoking backbutton into cordova view: " + ex.Message); } } else { if (history.Count > 1) { history.Pop(); Uri next = history.Peek(); IsBackButtonPressed = true; CordovaBrowser.Navigate(next); e.Cancel = true; } } }
void CordovaBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) { if (IsExiting) { // Special case, we navigate to about:blank when we are about to exit. IsolatedStorageSettings.ApplicationSettings.Save(); Application.Current.Terminate(); return; } Debug.WriteLine("CordovaBrowser_LoadCompleted"); string version = "?"; System.Windows.Resources.StreamResourceInfo streamInfo = Application.GetResourceStream(new Uri("VERSION", UriKind.Relative)); if (streamInfo != null) { using (StreamReader sr = new StreamReader(streamInfo.Stream)) { version = sr.ReadLine(); } } Debug.WriteLine("Apache Cordova native platform version " + version + " is starting"); string[] autoloadPlugs = this.configHandler.AutoloadPlugins; foreach (string plugName in autoloadPlugs) { nativeExecution.AutoLoadCommand(plugName); } // send js code to fire ready event string nativeReady = "(function(){ cordova.require('cordova/channel').onNativeReady.fire()})();"; try { CordovaBrowser.InvokeScript("eval", new string[] { nativeReady }); } catch (Exception /*ex*/) { Debug.WriteLine("Error calling js to fire nativeReady event. Did you include cordova.js in your html script tag?"); } // attach js code to dispatch exitApp string appExitHandler = "(function(){navigator.app = navigator.app || {}; navigator.app.exitApp= function(){cordova.exec(null,null,'CoreEvents','__exitApp',[]); }})();"; try { CordovaBrowser.InvokeScript("eval", new string[] { appExitHandler }); } catch (Exception /*ex*/) { Debug.WriteLine("Error calling js to add appExit funtion."); } if (this.CordovaBrowser.Opacity < 1) { FadeIn.Begin(); } }
/* * This method does the work of routing commands * NotifyEventArgs.Value contains a string passed from JS * If the command already exists in our map, we will just attempt to call the method(action) specified, and pass the args along * Otherwise, we create a new instance of the command, add it to the map, and call it ... * This method may also receive JS error messages caught by window.onerror, in any case where the commandStr does not appear to be a valid command * it is simply output to the debugger output, and the method returns. * **/ void CordovaBrowser_ScriptNotify(object sender, NotifyEventArgs e) { string commandStr = e.Value; string commandName = commandStr.Split('/').FirstOrDefault(); if (browserDecorators.ContainsKey(commandName)) { browserDecorators[commandName].HandleCommand(commandStr); return; } CordovaCommandCall commandCallParams = CordovaCommandCall.Parse(commandStr); if (commandCallParams == null) { // ERROR Debug.WriteLine("ScriptNotify :: " + commandStr); } else if (commandCallParams.Service == "CoreEvents") { switch (commandCallParams.Action.ToLower()) { case "overridebackbutton": string arg0 = JsonHelper.Deserialize <string[]>(commandCallParams.Args)[0]; this.OverrideBackButton = (arg0 != null && arg0.Length > 0 && arg0.ToLower() == "true"); break; case "__exitapp": Debug.WriteLine("Received exitApp command from javascript, app will now exit."); CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('pause');" }); CordovaBrowser.InvokeScript("eval", new string[] { "setTimeout(function(){ cordova.fireDocumentEvent('exit'); cordova.exec(null,null,'CoreEvents','__finalexit',[]); },0);" }); break; case "__finalexit": IsExiting = true; // hide the browser to prevent white flashes, since about:blank seems to always be white CordovaBrowser.Opacity = 0d; CordovaBrowser.Navigate(new Uri("about:blank", UriKind.Absolute)); break; } } else { if (configHandler.IsPluginAllowed(commandCallParams.Service)) { commandCallParams.Namespace = configHandler.GetNamespaceForCommand(commandCallParams.Service); nativeExecution.ProcessCommand(commandCallParams); } else { Debug.WriteLine("Error::Plugin not allowed in config.xml. " + commandCallParams.Service); } } }
void CordovaBrowser_Loaded(object sender, RoutedEventArgs e) { this.bmHelper.ScrollDisabled = this.DisableBouncyScrolling; if (DesignerProperties.IsInDesignTool) { return; } // prevents refreshing web control to initial state during pages transitions if (this.IsBrowserInitialized) { return; } try { // Before we possibly clean the ISO-Store, we need to grab our generated UUID, so we can rewrite it after. string deviceUUID = ""; using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication()) { try { IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream("DeviceID.txt", FileMode.Open, FileAccess.Read, appStorage); using (StreamReader reader = new StreamReader(fileStream)) { deviceUUID = reader.ReadLine(); } } catch (Exception /*ex*/) { deviceUUID = Guid.NewGuid().ToString(); Debug.WriteLine("Updating IsolatedStorage for APP:DeviceID :: " + deviceUUID); IsolatedStorageFileStream file = new IsolatedStorageFileStream("DeviceID.txt", FileMode.Create, FileAccess.Write, appStorage); using (StreamWriter writeFile = new StreamWriter(file)) { writeFile.WriteLine(deviceUUID); writeFile.Close(); } } } CordovaBrowser.Navigate(StartPageUri); IsBrowserInitialized = true; AttachHardwareButtonHandlers(); } catch (Exception ex) { Debug.WriteLine("ERROR: Exception in CordovaBrowser_Loaded :: {0}", ex.Message); } }
public void LoadPage(string url) { try { Uri newLoc = new Uri(url, UriKind.RelativeOrAbsolute); CordovaBrowser.Navigate(newLoc); } catch (Exception) { } }
void AppActivated(object sender, Microsoft.Phone.Shell.ActivatedEventArgs e) { Debug.WriteLine("INFO: AppActivated"); try { CordovaBrowser.InvokeScript("CordovaCommandResult", new string[] { "resume" }); } catch (Exception) { Debug.WriteLine("ERROR: Resume event error"); } }
void AppActivated(object sender, Microsoft.Phone.Shell.ActivatedEventArgs e) { Debug.WriteLine("INFO: AppActivated"); try { CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('resume');" }); } catch (Exception) { Debug.WriteLine("ERROR: Resume event error"); } }
void AppDeactivated(object sender, DeactivatedEventArgs e) { Debug.WriteLine("INFO: AppDeactivated because " + e.Reason); try { CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('pause');" }); } catch (Exception) { Debug.WriteLine("ERROR: Pause event error"); } }
private void service_Resuming(object sender, object e) { Debug.WriteLine("INFO: AppActivated"); try { CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('resume');" }); } catch (Exception) { Debug.WriteLine("ERROR: Resume event error"); } }
void AppDeactivated(object sender, DeactivatedEventArgs e) { Debug.WriteLine("INFO: AppDeactivated"); try { CordovaBrowser.InvokeScript("CordovaCommandResult", new string[] { "pause" }); } catch (Exception) { Debug.WriteLine("ERROR: Pause event error"); } }
private void service_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e) { Debug.WriteLine("INFO: AppDeactivated"); try { CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('pause');" }); } catch (Exception) { Debug.WriteLine("ERROR: Pause event error"); } }
void CordovaBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) { if (IsExiting) { // Special case, we navigate to about:blank when we are about to exit. IsolatedStorageSettings.ApplicationSettings.Save(); Application.Current.Terminate(); return; } Debug.WriteLine("CordovaBrowser_LoadCompleted"); string[] autoloadPlugs = this.configHandler.AutoloadPlugins; foreach (string plugName in autoloadPlugs) { //nativeExecution.ProcessCommand(commandCallParams); } // send js code to fire ready event string nativeReady = "(function(){ cordova.require('cordova/channel').onNativeReady.fire(); angular.bootstrap(document,['opvko']); alert('ready')})();"; try { CordovaBrowser.InvokeScript("execScript", new string[] { nativeReady }); } catch (Exception /*ex*/) { Debug.WriteLine("Error calling js to fire nativeReady event. Did you include cordova.js in your html script tag?"); } // attach js code to dispatch exitApp string appExitHandler = "(function(){navigator.app = navigator.app || {}; navigator.app.exitApp= function(){cordova.exec(null,null,'CoreEvents','__exitApp',[]); }})();"; try { CordovaBrowser.InvokeScript("execScript", new string[] { appExitHandler }); } catch (Exception /*ex*/) { Debug.WriteLine("Error calling js to add appExit funtion."); } if (this.CordovaBrowser.Opacity < 1) { FadeIn.Begin(); } }
void page_BackKeyPress(object sender, CancelEventArgs e) { if (OverrideBackButton) { try { //--this is a hack so that we can exit the app if necessary Object val = CordovaBrowser.InvokeScript("eval", "do_hardware_back_button()"); if (val.Equals("1")) { e.Cancel = true; } //-- //-- old cordova code // CordovaBrowser.InvokeScript("CordovaCommandResult", new string[] { "backbutton" }); // e.Cancel = true; //-- } catch (Exception ex) { Console.WriteLine("Exception while invoking backbutton into cordova view: " + ex.Message); } } else { try { PageDidChange = false; Uri uriBefore = this.Browser.Source; // calling js history.back with result in a page change if history was valid. CordovaBrowser.InvokeScript("eval", new string[] { "(function(){window.history.back();})()" }); Uri uriAfter = this.Browser.Source; e.Cancel = PageDidChange || (uriBefore != uriAfter); } catch (Exception) { e.Cancel = false; // exit the app ... ? } } }
void GapBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) { string nativeReady = "(function(){ cordova.require('cordova/channel').onNativeReady.fire()})();"; try { CordovaBrowser.InvokeScript("execScript", new string[] { nativeReady }); } catch (Exception /*ex*/) { Debug.WriteLine("Error calling js to fire nativeReady event. Did you include cordova-x.x.x.js in your html script tag?"); } if (this.CordovaBrowser.Opacity < 1) { this.CordovaBrowser.Opacity = 1; RotateIn.Begin(); } }
private void GapBrowser_LoadCompleted(object sender, NavigationEventArgs e) { string nativeReady = "(function(){ cordova.require('cordova/channel').onNativeReady.fire()})();"; try { var unloadFunc = "(function(){ function navigating(){ window.external.notify('%%' + location.href);} window.onbeforeunload=navigating;return location.href;})();"; var host = CordovaBrowser.InvokeScript("eval", new string[] { unloadFunc }); CordovaBrowser.AllowedScriptNotifyUris = new[] { new Uri(host) }; CordovaBrowser.InvokeScript("execScript", new string[] { nativeReady }); } catch (Exception /*ex*/) { Debug.WriteLine("Error calling js to fire nativeReady event. Did you include cordova-x.x.x.js in your html script tag?"); } if (this.CordovaBrowser.Opacity < 1) { this.CordovaBrowser.Opacity = 1; } }
void GapBrowser_Loaded(object sender, RoutedEventArgs e) { if (DesignerProperties.IsInDesignTool) { return; } // prevents refreshing web control to initial state during pages transitions if (this.IsBrowserInitialized) { return; } this.domStorageHelper = new DOMStorageHelper(this.CordovaBrowser); try { // Before we possibly clean the ISO-Store, we need to grab our generated UUID, so we can rewrite it after. string deviceUUID = ""; using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication()) { try { IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream("DeviceID.txt", FileMode.Open, FileAccess.Read, appStorage); using (StreamReader reader = new StreamReader(fileStream)) { deviceUUID = reader.ReadLine(); } } catch (Exception /*ex*/) { deviceUUID = Guid.NewGuid().ToString(); } Debug.WriteLine("Updating IsolatedStorage for APP:DeviceID :: " + deviceUUID); IsolatedStorageFileStream file = new IsolatedStorageFileStream("DeviceID.txt", FileMode.Create, FileAccess.Write, appStorage); using (StreamWriter writeFile = new StreamWriter(file)) { writeFile.WriteLine(deviceUUID); writeFile.Close(); } } StreamResourceInfo streamInfo = Application.GetResourceStream(new Uri("CordovaSourceDictionary.xml", UriKind.Relative)); if (streamInfo != null) { StreamReader sr = new StreamReader(streamInfo.Stream); //This will Read Keys Collection for the xml file XDocument document = XDocument.Parse(sr.ReadToEnd()); var files = from results in document.Descendants("FilePath") select new { path = (string)results.Attribute("Value") }; StreamResourceInfo fileResourceStreamInfo; using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication()) { foreach (var file in files) { fileResourceStreamInfo = Application.GetResourceStream(new Uri(file.path, UriKind.Relative)); if (fileResourceStreamInfo != null) { using (BinaryReader br = new BinaryReader(fileResourceStreamInfo.Stream)) { byte[] data = br.ReadBytes((int)fileResourceStreamInfo.Stream.Length); string strBaseDir = AppRoot + file.path.Substring(0, file.path.LastIndexOf(System.IO.Path.DirectorySeparatorChar)); if (!appStorage.DirectoryExists(strBaseDir)) { Debug.WriteLine("INFO: Creating Directory :: " + strBaseDir); appStorage.CreateDirectory(strBaseDir); } // This will truncate/overwrite an existing file, or using (IsolatedStorageFileStream outFile = appStorage.OpenFile(AppRoot + file.path, FileMode.Create)) { Debug.WriteLine("INFO: Writing data for " + AppRoot + file.path + " and length = " + data.Length); using (var writer = new BinaryWriter(outFile)) { writer.Write(data); } } } } else { Debug.WriteLine("ERROR: Failed to write file :: " + file.path + " did you forget to add it to the project?"); } } } } CordovaBrowser.Navigate(StartPageUri); IsBrowserInitialized = true; AttachHardwareButtonHandlers(); } catch (Exception ex) { Debug.WriteLine("ERROR: Exception in GapBrowser_Loaded :: {0}", ex.Message); } }