initial work, added github to setting,

change update manage from static
created log folder prop for log class
This commit is contained in:
AT
2020-01-07 02:34:46 +02:00
parent 4cf3cff74d
commit 49b85d150c
13 changed files with 146 additions and 65 deletions

View File

@@ -1,7 +1,19 @@
<?xml version="1.0"?>
<configuration>
<!--https://msdn.microsoft.com/en-us/library/dd409252(v=vs.110).aspx-->
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Wox.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<runtime>
<loadFromRemoteSources enabled="true"/>
</runtime>
<applicationSettings>
<Wox.Properties.Settings>
<setting name="GithubRepo" serializeAs="String">
<value>https://github.com/Wox-launcher/Wox</value>
</setting>
</Wox.Properties.Settings>
</applicationSettings>
</configuration>

View File

@@ -25,6 +25,7 @@ namespace Wox
private Settings _settings;
private MainViewModel _mainVM;
private SettingWindowViewModel _settingsVM;
private readonly Updater _updater = new Updater(Wox.Properties.Settings.Default.GithubRepo);
[STAThread]
public static void Main()
@@ -50,7 +51,7 @@ namespace Wox
ImageLoader.Initialize();
_settingsVM = new SettingWindowViewModel();
_settingsVM = new SettingWindowViewModel(_updater);
_settings = _settingsVM.Settings;
Alphabet.Initialize(_settings);
@@ -111,12 +112,12 @@ namespace Wox
var timer = new Timer(1000 * 60 * 60 * 5);
timer.Elapsed += async (s, e) =>
{
await Updater.UpdateApp();
await _updater.UpdateApp();
};
timer.Start();
// check updates on startup
await Updater.UpdateApp();
await _updater.UpdateApp();
}
});
}

View File

@@ -12,7 +12,7 @@ namespace Wox.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.3.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
@@ -22,5 +22,14 @@ namespace Wox.Properties {
return defaultInstance;
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("https://github.com/Wox-launcher/Wox")]
public string GithubRepo {
get {
return ((string)(this["GithubRepo"]));
}
}
}
}

View File

@@ -1,7 +1,9 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:_settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="Wox.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="GithubRepo" Type="System.String" Scope="Application">
<Value Profile="(Default)">https://github.com/Wox-launcher/Wox</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@@ -23,7 +23,7 @@ namespace Wox
private void SetException(Exception exception)
{
string path = Path.Combine(Constant.DataDirectory, Log.DirectoryName, Constant.Version);
string path = Log.CurrentLogDirectory;
var directory = new DirectoryInfo(path);
var log = directory.GetFiles().OrderByDescending(f => f.LastWriteTime).First();

View File

@@ -260,53 +260,16 @@ namespace Wox
#region Proxy
private void OnTestProxyClick(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(_settings.Proxy.Server))
{
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("serverCantBeEmpty"));
return;
}
if (_settings.Proxy.Port <= 0)
{
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("portCantBeEmpty"));
return;
}
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Infrastructure.Constant.Repository);
if (string.IsNullOrEmpty(_settings.Proxy.UserName) || string.IsNullOrEmpty(_settings.Proxy.Password))
{
request.Proxy = new WebProxy(_settings.Proxy.Server, _settings.Proxy.Port);
}
else
{
request.Proxy = new WebProxy(_settings.Proxy.Server, _settings.Proxy.Port)
{
Credentials = new NetworkCredential(_settings.Proxy.UserName, _settings.Proxy.Password)
};
}
try
{
var response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("proxyIsCorrect"));
}
else
{
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("proxyConnectFailed"));
}
}
catch
{
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("proxyConnectFailed"));
}
{ // TODO: change to command
var msg = _viewModel.TestProxy();
MessageBox.Show(msg); // TODO: add message box service
}
#endregion
private async void OnCheckUpdates(object sender, RoutedEventArgs e)
{
await Updater.UpdateApp();
_viewModel.UpdateApp(); // TODO: change to command
}
private void OnRequestNavigate(object sender, RequestNavigateEventArgs e)

28
Wox/Settings.cs Normal file
View File

@@ -0,0 +1,28 @@
namespace Wox.Properties {
// This class allows you to handle specific events on the settings class:
// The SettingChanging event is raised before a setting's value is changed.
// The PropertyChanged event is raised after a setting's value is changed.
// The SettingsLoaded event is raised after the setting values are loaded.
// The SettingsSaving event is raised before the setting values are saved.
internal sealed partial class Settings {
public Settings() {
// // To add event handlers for saving and changing settings, uncomment the lines below:
//
// this.SettingChanging += this.SettingChangingEventHandler;
//
// this.SettingsSaving += this.SettingsSavingEventHandler;
//
}
private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
// Add code to handle the SettingChangingEvent event here.
}
private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
// Add code to handle the SettingsSaving event here.
}
}
}

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
@@ -20,10 +21,12 @@ namespace Wox.ViewModel
{
public class SettingWindowViewModel : BaseModel
{
private readonly Updater _updater;
private readonly WoxJsonStorage<Settings> _storage;
public SettingWindowViewModel()
public SettingWindowViewModel(Updater updater)
{
_updater = updater;
_storage = new WoxJsonStorage<Settings>();
Settings = _storage.Load();
Settings.PropertyChanged += (s, e) =>
@@ -39,6 +42,10 @@ namespace Wox.ViewModel
public Settings Settings { get; set; }
public async void UpdateApp()
{
await _updater.UpdateApp();
}
public void Save()
{
@@ -88,6 +95,50 @@ namespace Wox.ViewModel
public List<Language> Languages => _translater.LoadAvailableLanguages();
public IEnumerable<int> MaxResultsRange => Enumerable.Range(2, 16);
public string TestProxy()
{
var proxyServer = Settings.Proxy.Server;
var proxyUserName = Settings.Proxy.UserName;
if (string.IsNullOrEmpty(proxyServer))
{
return InternationalizationManager.Instance.GetTranslation("serverCantBeEmpty");
}
if (Settings.Proxy.Port <= 0)
{
return InternationalizationManager.Instance.GetTranslation("portCantBeEmpty");
}
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_updater.GitHubRepository);
if (string.IsNullOrEmpty(proxyUserName) || string.IsNullOrEmpty(Settings.Proxy.Password))
{
request.Proxy = new WebProxy(proxyServer, Settings.Proxy.Port);
}
else
{
request.Proxy = new WebProxy(proxyServer, Settings.Proxy.Port)
{
Credentials = new NetworkCredential(proxyUserName, Settings.Proxy.Password)
};
}
try
{
var response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
return InternationalizationManager.Instance.GetTranslation("proxyIsCorrect");
}
else
{
return InternationalizationManager.Instance.GetTranslation("proxyConnectFailed");
}
}
catch
{
return InternationalizationManager.Instance.GetTranslation("proxyConnectFailed");
}
}
#endregion
#region plugin
@@ -220,7 +271,7 @@ namespace Wox.ViewModel
},
new Result
{
Title = $"Open Source: {Constant.Repository}",
Title = $"Open Source: {_updater.GitHubRepository}",
SubTitle = "Please star it!"
}
};
@@ -330,8 +381,8 @@ namespace Wox.ViewModel
#region about
public static string Github => Constant.Repository;
public static string ReleaseNotes => @"https://github.com/Wox-launcher/Wox/releases/latest";
public string Github => _updater.GitHubRepository;
public string ReleaseNotes => _updater.GitHubRepository + @"/releases/latest";
public static string Version => Constant.Version;
public string ActivatedTimes => string.Format(_translater.GetTranslation("about_activate_times"), Settings.ActivateTimes);
#endregion

View File

@@ -165,6 +165,7 @@
<Compile Include="ResultListBox.xaml.cs">
<DependentUpon>ResultListBox.xaml</DependentUpon>
</Compile>
<Compile Include="Settings.cs" />
<Compile Include="Storage\HistoryItem.cs" />
<Compile Include="Storage\QueryHistory.cs" />
<Compile Include="Storage\TopMostRecord.cs" />