-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGUI.psm1
47 lines (37 loc) · 1.28 KB
/
GUI.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function New-GUI {
param(
$xaml
)
try {
$TypeDefinition = Get-Content $PSScriptRoot\TypeDefinition.cs -Raw
Add-Type -TypeDefinition $TypeDefinition -ReferencedAssemblies @("System.Management.Automation", "Microsoft.CSharp", "System.Web.Extensions")
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
}
catch {}
$reader = (New-Object System.Xml.XmlNodeReader ([xml]$xaml))
$Form = [Windows.Markup.XamlReader]::Load($reader)
return $Form
}
function Set-GUIWebBrowserContent {
param (
$Html,
$Form
)
$WebBrowser = $Form.FindName("WebBrowser")
if ($Runspace) {
$WebBrowser.ObjectForScripting = [PowerShellHelper]::new($Runspace)
}
else {
$WebBrowser.ObjectForScripting = [PowerShellHelper]::new()
}
$WebBrowser.NavigateToString($Html)
}
function Start-MyGUI {
$html = Get-Content $PSScriptRoot\GUI.html -Raw
$module = Get-Content $PSScriptRoot\APIFunctions.psm1 -Raw
$html = $html.replace("{0}",$module)
$xaml = Get-Content $PSScriptRoot\Window.xaml -Raw
$form = New-GUI -xaml $xaml
Set-GUIWebBrowserContent -html $html -form $form
$Form.ShowDialog() | out-null
}