cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an-s...@apache.org
Subject [1/2] cordova-paramedic git commit: Add plgin to nable package debugging mode on Windows
Date Thu, 02 Jun 2016 11:15:03 GMT
Repository: cordova-paramedic
Updated Branches:
  refs/heads/ci/windows [created] 007c9df7e


Add plgin to nable package debugging mode  on Windows


Project: http://git-wip-us.apache.org/repos/asf/cordova-paramedic/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-paramedic/commit/e93c9b41
Tree: http://git-wip-us.apache.org/repos/asf/cordova-paramedic/tree/e93c9b41
Diff: http://git-wip-us.apache.org/repos/asf/cordova-paramedic/diff/e93c9b41

Branch: refs/heads/ci/windows
Commit: e93c9b41976a6d75fdd0f4d2dee415a8dff8ba5a
Parents: d270995
Author: Vladimir Kotikov <v-vlkoti@microsoft.com>
Authored: Thu Jun 2 12:02:06 2016 +0300
Committer: Vladimir Kotikov <v-vlkoti@microsoft.com>
Committed: Thu Jun 2 12:02:06 2016 +0300

----------------------------------------------------------------------
 debug-mode-plugin/plugin.xml                    | 34 ++++++++
 .../scripts/EnableDebuggingForPackage.ps1       | 83 ++++++++++++++++++++
 debug-mode-plugin/scripts/disable-debug-mode.js | 32 ++++++++
 debug-mode-plugin/scripts/enable-debug-mode.js  | 46 +++++++++++
 4 files changed, 195 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-paramedic/blob/e93c9b41/debug-mode-plugin/plugin.xml
----------------------------------------------------------------------
diff --git a/debug-mode-plugin/plugin.xml b/debug-mode-plugin/plugin.xml
new file mode 100644
index 0000000..a78e173
--- /dev/null
+++ b/debug-mode-plugin/plugin.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+
+<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
+        id="debug-mode-plugin"
+        version="1.0.0-dev">
+
+    <name>Windows debug mode plugin</name>
+    <description>Plugin to enable package debugging to allow app run without active
local/remote desktop session</description>
+    <license>Apache 2.0</license>
+
+    <platform name="windows">
+        <hook type="after_plugin_install" src="scripts/enable-debug-mode.js" />
+        <hook type="before_plugin_uninstall" src="scripts/disable-debug-mode.js" />
+    </platform>
+
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-paramedic/blob/e93c9b41/debug-mode-plugin/scripts/EnableDebuggingForPackage.ps1
----------------------------------------------------------------------
diff --git a/debug-mode-plugin/scripts/EnableDebuggingForPackage.ps1 b/debug-mode-plugin/scripts/EnableDebuggingForPackage.ps1
new file mode 100644
index 0000000..5ed9d09
--- /dev/null
+++ b/debug-mode-plugin/scripts/EnableDebuggingForPackage.ps1
@@ -0,0 +1,83 @@
+<#
+       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.
+#>
+
+param(
+    [Parameter(Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)]
+    [string] $ID <# package.appxmanifest//Identity@name #>
+)
+
+$code = @"
+using System;
+using System.Runtime.InteropServices;
+namespace PackageDebug
+{
+    public enum PACKAGE_EXECUTION_STATE
+    {
+        PES_UNKNOWN,
+        PES_RUNNING,
+        PES_SUSPENDING,
+        PES_SUSPENDED,
+        PES_TERMINATED
+    }
+
+    [ComImport, Guid("B1AEC16F-2383-4852-B0E9-8F0B1DC66B4D")]
+    public class PackageDebugSettings
+    {
+    }
+
+    [ComImport, Guid("F27C3930-8029-4AD1-94E3-3DBA417810C1"),InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+    public interface IPackageDebugSettings
+    {
+        int EnableDebugging([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, [MarshalAs(UnmanagedType.LPWStr)]
string debuggerCommandLine, IntPtr environment);
+        int DisableDebugging([MarshalAs(UnmanagedType.LPWStr)] string packageFullName);
+        int Suspend([MarshalAs(UnmanagedType.LPWStr)] string packageFullName);
+        int Resume([MarshalAs(UnmanagedType.LPWStr)] string packageFullName);
+        int TerminateAllProcesses([MarshalAs(UnmanagedType.LPWStr)] string packageFullName);
+        int SetTargetSessionId(int sessionId);
+        int EnumerageBackgroundTasks([MarshalAs(UnmanagedType.LPWStr)] string packageFullName,
+                                                      out uint taskCount, out int intPtr,
[Out] string[] array);
+        int ActivateBackgroundTask(IntPtr something);
+        int StartServicing([MarshalAs(UnmanagedType.LPWStr)] string packageFullName);
+        int StopServicing([MarshalAs(UnmanagedType.LPWStr)] string packageFullName);
+        int StartSessionRedirection([MarshalAs(UnmanagedType.LPWStr)] string packageFullName,
uint sessionId);
+        int StopSessionRedirection([MarshalAs(UnmanagedType.LPWStr)] string packageFullName);
+        int GetPackageExecutionState([MarshalAs(UnmanagedType.LPWStr)] string packageFullName,
+                                            out PACKAGE_EXECUTION_STATE packageExecutionState);
+        int RegisterForPackageStateChanges([MarshalAs(UnmanagedType.LPWStr)] string packageFullName,
+                               IntPtr pPackageExecutionStateChangeNotification, out uint
pdwCookie);
+        int UnregisterForPackageStateChanges(uint dwCookie);
+    }
+
+    public class DebugTool
+    {
+        public static void EnableDebug(String packageFullName)
+        {
+            // Set debug mode for App and activate installed application
+            var debugSettings = (IPackageDebugSettings)(new PackageDebugSettings());
+            debugSettings.EnableDebugging(packageFullName, null, (IntPtr)null);
+        }
+    }
+}
+"@
+
+Add-Type -TypeDefinition $code
+
+$packageFullName = $(Get-AppxPackage $ID).PackageFullName
+Write-Host "Setting debug mode for application:" $ID
+[PackageDebug.DebugTool]::EnableDebug($packageFullName) | Out-Null

http://git-wip-us.apache.org/repos/asf/cordova-paramedic/blob/e93c9b41/debug-mode-plugin/scripts/disable-debug-mode.js
----------------------------------------------------------------------
diff --git a/debug-mode-plugin/scripts/disable-debug-mode.js b/debug-mode-plugin/scripts/disable-debug-mode.js
new file mode 100644
index 0000000..17e1b24
--- /dev/null
+++ b/debug-mode-plugin/scripts/disable-debug-mode.js
@@ -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.
+*/
+
+module.exports = function (context) {
+    var path = require('path');
+    var shell = context.requireCordovaModule('shelljs');
+
+    var libPath        = path.resolve(context.opts.projectRoot, "platforms/windows/cordova/lib");
+    var appUtilsPath   = path.join(libPath, "WindowsStoreAppUtils.ps1");
+    var appUtilsBackupPath   = path.join(libPath, "WindowsStoreAppUtils.ps1.bak");
+    var destScriptPath = path.join(libPath, "EnableDebuggingForPackage.ps1");
+
+    // Remove the patch and copu over backup StoreAppUtils script
+    shell.rm("-f", destScriptPath);
+    shell.cp("-f", appUtilsBackupPath, appUtilsPath);
+};

http://git-wip-us.apache.org/repos/asf/cordova-paramedic/blob/e93c9b41/debug-mode-plugin/scripts/enable-debug-mode.js
----------------------------------------------------------------------
diff --git a/debug-mode-plugin/scripts/enable-debug-mode.js b/debug-mode-plugin/scripts/enable-debug-mode.js
new file mode 100644
index 0000000..cbde75f
--- /dev/null
+++ b/debug-mode-plugin/scripts/enable-debug-mode.js
@@ -0,0 +1,46 @@
+/**
+    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.
+*/
+
+module.exports = function (context) {
+    var path = require('path');
+    var shell = context.requireCordovaModule('shelljs');
+
+    var libPath        = path.resolve(context.opts.projectRoot, "platforms/windows/cordova/lib");
+    var appUtilsPath   = path.join(libPath, "WindowsStoreAppUtils.ps1");
+    var appUtilsBackupPath   = path.join(libPath, "WindowsStoreAppUtils.ps1.bak");
+    var srcScriptPath  = path.join(__dirname, "EnableDebuggingForPackage.ps1");
+    var destScriptPath = path.join(libPath, "EnableDebuggingForPackage.ps1");
+
+    // copy over the patch
+    shell.cp("-f", srcScriptPath, libPath);
+    shell.cp("-f", appUtilsPath, appUtilsBackupPath);
+
+    // add extra code to patch
+    shell.sed(
+        "-i",
+        /^\s*\$appActivator .*$/gim,
+        "$&\n\n" +
+        "    # START ENABLE DEBUG MODE SECTION\n" +
+        "    powershell " + destScriptPath + " $$ID\n" +
+        "    $Ole32 = Add-Type -MemberDefinition '[DllImport(\"Ole32.dll\")]public static
extern int CoAllowSetForegroundWindow(IntPtr pUnk, IntPtr lpvReserved);' -Name 'Ole32' -Namespace
'Win32' -PassThru\n" +
+        "    $Ole32::CoAllowSetForegroundWindow([System.Runtime.InteropServices.Marshal]::GetIUnknownForObject($appActivator),
[System.IntPtr]::Zero)\n" +
+        "    # END ENABLE DEBUG MODE SECTION\n",
+        appUtilsPath
+    );
+};


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message