Skip to content

Commit

Permalink
Vpm can now talk to the license pages through javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
microdee committed Jan 25, 2017
1 parent 3f43151 commit a6274f9
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 4 deletions.
48 changes: 45 additions & 3 deletions src/vpm/UserAgree.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,39 @@ namespace vpm
/// </summary>
public partial class UserAgree : Window
{
public JsVPackInterop InteropObj;
public ListBoxItem SelectedPack;
public bool PackChanged = false;
public UserAgree()
{
InitializeComponent();
}

public void DisableAgree()
{
Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
{
AgreeAndInstall.IsEnabled = false;
}));
}
public void EnableAgree()
{
Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
{
AgreeAndInstall.IsEnabled = true;
}));
}

public void ContinueFromJS()
{
Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
{
AgreeAndInstall.IsEnabled = true;
AgreeAndInstall.IsChecked = true;
if (VPackList.SelectedIndex < VPackList.Items.Count - 1)
VPackList.SelectedIndex = (VPackList.SelectedIndex + 1) % VPackList.Items.Count;
}));
}
private void ContinueInstall_Click(object sender, RoutedEventArgs e)
{
VpmConfig.Instance.InstallationCancelled = false;
Expand All @@ -39,6 +66,12 @@ private void ContinueInstall_Click(object sender, RoutedEventArgs e)

private void UserAgree_OnInitialized(object sender, EventArgs e)
{

InteropObj = new JsVPackInterop
{
UserAgreeWindow = this
};
Browser.RegisterJsObject("vpm", InteropObj);
foreach (var vpack in VpmConfig.Instance.PackList)
{
var item = new ListBoxItem
Expand All @@ -51,7 +84,7 @@ private void UserAgree_OnInitialized(object sender, EventArgs e)
};
VPackList.Items.Add(item);
}
var delay = new Timer { Interval = 1500 };
var delay = new Timer { Interval = 1000 };
delay.Elapsed += (o, ee) =>
{
Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
Expand All @@ -66,7 +99,7 @@ private void UserAgree_OnInitialized(object sender, EventArgs e)
private void VPackList_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if(e.AddedItems.Count <= 0) return;

PackChanged = true;
SelectedPack = (ListBoxItem)e.AddedItems[0];
var pack = (VPack)SelectedPack.Content;
AgreeAndInstall.IsChecked = pack.Agreed;
Expand All @@ -90,15 +123,17 @@ private void Browser_OnLoadingStateChanged(object sender, LoadingStateChangedEve
{
Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action( () =>
{
if (!PackChanged) return;
if (e.IsLoading)
{
AgreeAndInstall.IsEnabled = false;
NextPack.IsEnabled = false;
InteropObj.CurrentPack = (VPack)SelectedPack.Content;
}
else
{
AgreeAndInstall.IsEnabled = true;
NextPack.IsEnabled = true;
PackChanged = false;
}
}));
}
Expand All @@ -107,5 +142,12 @@ private void NextPack_OnClick(object sender, RoutedEventArgs e)
{
VPackList.SelectedIndex = (VPackList.SelectedIndex + 1) % VPackList.Items.Count;
}
/*
private void AgreeAndInstall_OnIsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if(AgreeAndInstall.IsEnabled)
Console.WriteLine("Agree Enabled");
}
*/
}
}
40 changes: 40 additions & 0 deletions src/vpm/vpack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,53 @@

namespace vpm
{
public class JsVPackInterop
{
public VPack CurrentPack;
public UserAgree UserAgreeWindow;

public string GetPackXml()
{
return CurrentPack.RawXml;
}

public void Continue(string data)
{
SetInstallData(data);
UserAgreeWindow.ContinueFromJS();
}
public void SetInstallData(string data)
{
CurrentPack.InstallDataFromJS = data;
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("Licensing page passed data for the installation script.");
Console.ResetColor();
}
public void DisableAgree()
{
UserAgreeWindow.DisableAgree();
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("Licensing page Disabled the \"Agree\" checkbox.");
Console.ResetColor();
}
public void EnableAgree()
{
UserAgreeWindow.EnableAgree();
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("Licensing page Enabled the \"Agree\" checkbox.");
Console.ResetColor();
}
}
public class VPack
{
public string Name;
public string Author;
public string Source;
public string TempDir;
public string LicenseUrl;
public string InstallDataFromJS;
public string InstallScript;
public string RawXml;
public bool Agreed = false;
public List<string> Aliases = new List<string>();
public List<VPack> Dependencies = new List<VPack>();
Expand Down Expand Up @@ -58,6 +97,7 @@ public VPack(string name, string source, IEnumerable<string> aliases = null, Xml
}
if (xmldoc != null)
{
RawXml = xmldoc.ToString();
var licensenode = xmldoc.SelectSingleNode("/vpack/meta/license");
LicenseUrl = licensenode != null ? licensenode.InnerText.Trim() : "http://www.imxprs.com/free/microdee/vpmnolicense";

Expand Down
4 changes: 3 additions & 1 deletion src/vpm/vpm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@
<Analyzer Include="packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" />
</ItemGroup>
<ItemGroup>
<Content Include="box-01.ico" />
<Content Include="box-01.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="FodyWeavers.xml" />
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit a6274f9

Please sign in to comment.