-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMainWindow.xaml.cs
105 lines (88 loc) · 3.15 KB
/
MainWindow.xaml.cs
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows;
using System.Windows.Input;
using Microsoft.Win32;
namespace PhantomUI
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
#region Init
public string ApplicationDirectory { get; set; }
public MainWindow()
{
//To get the location the assembly normally resides on disk or the install directory
string basePath = Assembly.GetExecutingAssembly().Location;
string baseDir = Path.GetDirectoryName(basePath);
ApplicationDirectory = baseDir;
InitializeComponent();
}
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
DragMove();
}
private void ButtonExitClick(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
#endregion
private async void ButtonRunClick(object sender, RoutedEventArgs e)
{
browseIcon.Icon = FontAwesome.WPF.FontAwesomeIcon.Spinner;
browseIcon.Spin = true;
_buttonRun.Visibility = Visibility.Hidden;
PhantomJs.FileType fileType = PhantomJs.FileType.Pdf;
if (_radioButtonJpeg.IsChecked == true)
{
fileType = PhantomJs.FileType.Jpeg;
}
else if (_radioButtonPng.IsChecked == true)
{
fileType = PhantomJs.FileType.Png;
}
var phantom = new PhantomJs();
var result = await phantom.GetPdfTask(_textBoxUrl.Text, fileType);
if (File.Exists(result))
{
Process.Start(result);
}
else
{
MessageBox.Show("Something went wrong ...", "Oops !", MessageBoxButton.OK, MessageBoxImage.Error);
}
browseIcon.Icon = FontAwesome.WPF.FontAwesomeIcon.Folder;
browseIcon.Spin = false;
_buttonRun.Visibility = Visibility.Visible;
}
private void ButtonBrowseClick(object sender, RoutedEventArgs e)
{
var dialog = new OpenFileDialog
{
Filter = @"Html Files (.html)|*.html|Htm Files (*.htm)|*.htm"
};
var result = dialog.ShowDialog();
if (result == true)
{
_textBoxUrl.Text = dialog.FileName;
}
}
private void ButtonGitHubClick(object sender, RoutedEventArgs e)
{
Process.Start("https://github.com/itechnology/PhantomUI");
}
private void ScriptButtonClick(object sender, RoutedEventArgs e)
{
Process.Start(string.Format(@"{0}\lib\scripts\run.js", ApplicationDirectory));
}
private void ConfigButtonClick(object sender, RoutedEventArgs e)
{
Process.Start(string.Format(@"{0}\lib\config.json", ApplicationDirectory));
}
}
}