Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
CB-802 WP8 ConsoleHelper outputs all console.log calls to isolated st…
…orage file for watching with CordovaDeploy tool
  • Loading branch information
purplecabbage committed Dec 6, 2013
1 parent 9106996 commit 2171cd6a41c5d8fe4554e52e197552ed3a84ca94
Showing 1 changed file with 44 additions and 3 deletions.
@@ -1,7 +1,10 @@
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Text;

@@ -12,8 +15,23 @@ class ConsoleHelper : IBrowserDecorator

public WebBrowser Browser { get; set; }

public void InjectScript()
protected bool hasListener = false;



public void InjectScript()
{
using(IsolatedStorageFileStream file = new IsolatedStorageFileStream("debugOutput.txt", FileMode.Create, FileAccess.Write, IsolatedStorageFile.GetUserStoreForApplication()))
{
}

if (!hasListener)
{
PhoneApplicationService.Current.Closing += OnServiceClosing;
hasListener = true;
}


string script = @"(function(win) {
function exec(msg) { window.external.Notify('ConsoleLog/' + msg); }
var cons = win.console = win.console || {};
@@ -24,12 +42,35 @@ public void InjectScript()
cons.error = cons.error || function(msg) { exec('ERROR:' + msg ); };
})(window);";

Browser.InvokeScript("execScript", new string[] { script });
Browser.InvokeScript("execScript", new string[] { script });
}

void OnServiceClosing(object sender, ClosingEventArgs e)
{
using (IsolatedStorageFileStream file = new IsolatedStorageFileStream("debugOutput.txt", FileMode.Append, FileAccess.Write, IsolatedStorageFile.GetUserStoreForApplication()))
{
using (StreamWriter writeFile = new StreamWriter(file))
{
writeFile.WriteLine("EXIT");
writeFile.Close();
}
file.Close();
}
}

public bool HandleCommand(string commandStr)
{
Debug.WriteLine(commandStr.Substring("ConsoleLog/".Length));
string output = commandStr.Substring("ConsoleLog/".Length);
Debug.WriteLine(output);
using (IsolatedStorageFileStream file = new IsolatedStorageFileStream("debugOutput.txt", FileMode.Append, FileAccess.Write, IsolatedStorageFile.GetUserStoreForApplication()))
{
using (StreamWriter writeFile = new StreamWriter(file))
{
writeFile.WriteLine(output);
writeFile.Close();
}
file.Close();
}
return true;
}

0 comments on commit 2171cd6

Please sign in to comment.