Add activate statistics

This commit is contained in:
qianlifeng 2015-01-23 21:52:46 +08:00
parent 42d86fab8e
commit 4379145231
15 changed files with 83 additions and 56 deletions

View File

@ -6,6 +6,7 @@ using Newtonsoft.Json;
using Wox.Infrastructure.Storage;
using Wox.Plugin;
using System.Drawing;
using System.Reflection;
namespace Wox.Core.UserSettings
{
@ -14,6 +15,10 @@ namespace Wox.Core.UserSettings
[JsonProperty]
public bool DontPromptUpdateMsg { get; set; }
[JsonProperty]
public int ActivateTimes { get; set; }
[JsonProperty]
public bool EnableUpdateLog { get; set; }
@ -140,15 +145,7 @@ namespace Wox.Core.UserSettings
protected override string ConfigFolder
{
get
{
string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE");
if (userProfilePath == null)
{
throw new ArgumentException("Environment variable USERPROFILE is empty");
}
return Path.Combine(Path.Combine(userProfilePath, ".Wox"), "Config");
}
get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); }
}
protected override string ConfigName
@ -156,6 +153,15 @@ namespace Wox.Core.UserSettings
get { return "config"; }
}
public void IncreaseActivateTimes()
{
ActivateTimes++;
if (ActivateTimes % 15 == 0)
{
Save();
}
}
protected override UserSettingStorage LoadDefault()
{
DontPromptUpdateMsg = false;

View File

@ -83,8 +83,8 @@
<Compile Include="Plugin\PluginInstaller.cs" />
<Compile Include="Plugin\QueryDispatcher\IQueryDispatcher.cs" />
<Compile Include="Plugin\QueryDispatcher\QueryDispatcher.cs" />
<Compile Include="Plugin\QueryDispatcher\UserPluginQueryDispatcher.cs" />
<Compile Include="Plugin\QueryDispatcher\SystemPluginQueryDispatcher.cs" />
<Compile Include="Plugin\QueryDispatcher\RegularPluginQueryDispatcher.cs" />
<Compile Include="Plugin\QueryDispatcher\WildcardPluginQueryDispatcher.cs" />
<Compile Include="Plugin\JsonRPCPlugin.cs" />
<Compile Include="Plugin\JsonRPCPluginLoader.cs" />
<Compile Include="Plugin\CSharpPluginLoader.cs" />

View File

@ -6,6 +6,7 @@ using System.Reflection;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading;
using Wox.Infrastructure.Logger;
namespace Wox.Infrastructure.Storage
@ -18,6 +19,7 @@ namespace Wox.Infrastructure.Storage
[Serializable]
public abstract class BinaryStorage<T> : BaseStorage<T> where T : class, IStorage, new()
{
private static object syncObject = new object();
protected override string FileSuffix
{
get { return ".dat"; }
@ -87,25 +89,31 @@ namespace Wox.Infrastructure.Storage
protected override void SaveInternal()
{
try
ThreadPool.QueueUserWorkItem(o =>
{
FileStream fileStream = new FileStream(ConfigPath, FileMode.Create);
BinaryFormatter binaryFormatter = new BinaryFormatter
lock (syncObject)
{
AssemblyFormat = FormatterAssemblyStyle.Simple
};
binaryFormatter.Serialize(fileStream, serializedObject);
fileStream.Close();
}
catch (Exception e)
{
Log.Error(e.Message);
try
{
FileStream fileStream = new FileStream(ConfigPath, FileMode.Create);
BinaryFormatter binaryFormatter = new BinaryFormatter
{
AssemblyFormat = FormatterAssemblyStyle.Simple
};
binaryFormatter.Serialize(fileStream, serializedObject);
fileStream.Close();
}
catch (Exception e)
{
Log.Error(e);
#if (DEBUG)
{
throw;
}
{
throw;
}
#endif
}
}
}
});
}
}
}

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using Newtonsoft.Json;
namespace Wox.Infrastructure.Storage
@ -12,6 +13,7 @@ namespace Wox.Infrastructure.Storage
/// </summary>
public abstract class JsonStrorage<T> : BaseStorage<T> where T : class, IStorage, new()
{
private static object syncObject = new object();
protected override string FileSuffix
{
get { return ".json"; }
@ -39,8 +41,14 @@ namespace Wox.Infrastructure.Storage
protected override void SaveInternal()
{
string json = JsonConvert.SerializeObject(serializedObject, Formatting.Indented);
File.WriteAllText(ConfigPath, json);
ThreadPool.QueueUserWorkItem(o =>
{
lock (syncObject)
{
string json = JsonConvert.SerializeObject(serializedObject, Formatting.Indented);
File.WriteAllText(ConfigPath, json);
}
});
}
}
}

View File

@ -6,15 +6,16 @@
ResizeMode="NoResize"
Loaded="ActionKeyword_OnLoaded"
WindowStartupLocation="CenterScreen"
Height="200" Width="674.766">
Height="200" Width="600">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"></ColumnDefinition>
<ColumnDefinition Width="170"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Margin="10" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Text="{DynamicResource oldActionKeyword}"></TextBlock>
@ -24,8 +25,10 @@
<StackPanel Grid.Row="1" Orientation="Horizontal" Grid.Column="1" >
<TextBox x:Name="tbAction" Margin="10" Width="400" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBox>
</StackPanel>
<TextBlock Grid.Row="2" Grid.ColumnSpan="1" Grid.Column="1" Padding="5" Foreground="Gray" Text="{DynamicResource actionkeyword_tips}"></TextBlock>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="2" Grid.Column="1">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="3" Grid.Column="1">
<Button x:Name="btnCancel" Click="BtnCancel_OnClick" Margin="10 0 10 0" Width="80" Height="25" Content="{DynamicResource cancel}"></Button>
<Button x:Name="btnDone" Margin="10 0 10 0" Width="80" Height="25" Click="btnDone_OnClick">
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}"></TextBlock>

View File

@ -57,7 +57,7 @@ namespace Wox
}
//check new action keyword didn't used by other plugin
if (PluginManager.AllPlugins.Exists(o => o.Metadata.ActionKeyword == tbAction.Text.Trim()))
if (tbAction.Text.Trim() != PluginManager.ActionKeywordWildcard && PluginManager.AllPlugins.Exists(o => o.Metadata.ActionKeyword == tbAction.Text.Trim()))
{
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("newActionKeywordHasBeenAssigned"));
return;

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using Wox.Infrastructure.Storage;
@ -16,15 +17,7 @@ namespace Wox.ImageLoader
protected override string ConfigFolder
{
get
{
string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE");
if (userProfilePath == null)
{
throw new ArgumentException("Environment variable USERPROFILE is empty");
}
return Path.Combine(Path.Combine(userProfilePath, ".Wox"), "Config");
}
get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); }
}
protected override string ConfigName

View File

@ -8,6 +8,7 @@
<!--Setting General-->
<system:String x:Key="woxsettings">Wox Settings</system:String>
<system:String x:Key="general">General</system:String>
<system:String x:Key="startWoxOnSystemStartup">Start Wox on system startup</system:String>
<system:String x:Key="hideWoxWhenLoseFocus">Hide Wox when loses focus</system:String>
@ -61,6 +62,7 @@
<system:String x:Key="about">About</system:String>
<system:String x:Key="website">Website</system:String>
<system:String x:Key="version">Version</system:String>
<system:String x:Key="about_activate_times">You have activated Wox {0} times</system:String>
<!--Action Keyword Setting Dialog-->
<system:String x:Key="oldActionKeyword">Old Action Keyword</system:String>
@ -71,6 +73,8 @@
<system:String x:Key="newActionKeywordCannotBeEmpty">New Action Keyword can't be empty</system:String>
<system:String x:Key="newActionKeywordHasBeenAssigned">New ActionKeyword has been assigned to other plugin, please assign another new action keyword</system:String>
<system:String x:Key="succeed">Succeed</system:String>
<system:String x:Key="actionkeyword_tips">Use * if you don't want to specify a action keyword</system:String>
<!--Custom Query Hotkey Dialog-->
<system:String x:Key="preview">Preview</system:String>

View File

@ -8,6 +8,7 @@
<!--设置,通用-->
<system:String x:Key="woxsettings">Wox设置</system:String>
<system:String x:Key="general">通用</system:String>
<system:String x:Key="startWoxOnSystemStartup">开机启动</system:String>
<system:String x:Key="hideWoxWhenLoseFocus">失去焦点时自动隐藏Wox</system:String>
@ -61,7 +62,7 @@
<system:String x:Key="about">关于</system:String>
<system:String x:Key="website">网站</system:String>
<system:String x:Key="version">版本</system:String>
<system:String x:Key="about_activate_times">你已经激活了Wox {0} 次</system:String>
<!--Action Keyword 设置对话框-->
<system:String x:Key="oldActionKeyword">旧触发关键字</system:String>
@ -72,7 +73,8 @@
<system:String x:Key="newActionKeywordCannotBeEmpty">新触发关键字不能为空</system:String>
<system:String x:Key="newActionKeywordHasBeenAssigned">新触发关键字已经被指派给其他插件了,请重新选择一个关键字</system:String>
<system:String x:Key="succeed">成功</system:String>
<system:String x:Key="actionkeyword_tips">如果你不想设置触发关键字,可以使用*代替</system:String>
<!--Custom Query Hotkey 对话框-->
<system:String x:Key="preview">预览</system:String>
<system:String x:Key="hotkeyIsNotUnavailable">热键不可用,请选择一个新的热键</system:String>

View File

@ -8,6 +8,7 @@
<!--設置,通用-->
<system:String x:Key="woxsettings">Wox設置</system:String>
<system:String x:Key="general">通用</system:String>
<system:String x:Key="startWoxOnSystemStartup">開機啟動</system:String>
<system:String x:Key="hideWoxWhenLoseFocus">失去焦點時自動隱藏Wox</system:String>
@ -61,7 +62,7 @@
<system:String x:Key="about">關於</system:String>
<system:String x:Key="website">網站</system:String>
<system:String x:Key="version">版本</system:String>
<system:String x:Key="about_activate_times">你已經激活了Wox {0} 次</system:String>
<!--Action Keyword 設置對話框-->
<system:String x:Key="oldActionKeyword">舊觸發關鍵字</system:String>
@ -72,6 +73,7 @@
<system:String x:Key="newActionKeywordCannotBeEmpty">新觸發關鍵字不能為空</system:String>
<system:String x:Key="newActionKeywordHasBeenAssigned">新觸發關鍵字已經被指派給其他插件了,請重新選擇一個關鍵字</system:String>
<system:String x:Key="succeed">成功</system:String>
<system:String x:Key="actionkeyword_tips">如果你不想設置觸發關鍵字,可以使用*代替</system:String>
<!--Custom Query Hotkey 對話框-->
<system:String x:Key="preview">預覽</system:String>

View File

@ -292,6 +292,7 @@ namespace Wox
if (!IsVisible)
{
ShowWox();
UserSettingStorage.Instance.IncreaseActivateTimes();
}
else
{

View File

@ -7,7 +7,7 @@
xmlns:converters="clr-namespace:Wox.Converters"
xmlns:userSettings="clr-namespace:Wox.Core.UserSettings;assembly=Wox.Core"
Icon="Images\app.png"
Title="Wox Settings"
Title="{DynamicResource woxsettings}"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
Height="600" Width="800">
@ -310,6 +310,7 @@
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Margin="6" Text="{DynamicResource website}"></TextBlock>
@ -319,6 +320,8 @@
<StackPanel Grid.Column="1" Grid.Row="1" Orientation="Horizontal">
<TextBlock Margin="6" HorizontalAlignment="Left" x:Name="tbVersion" Text="1.0.0"></TextBlock>
</StackPanel>
<TextBlock x:Name="tbActivatedTimes" Grid.Row="2" Margin="6" Grid.ColumnSpan="2" Text="{DynamicResource about_activate_times}"></TextBlock>
</Grid>
</TabItem>
</TabControl>

View File

@ -21,6 +21,7 @@ using Microsoft.Win32;
using Wox.Core.i18n;
using Wox.Core.Theme;
using Wox.Core.UserSettings;
using Wox.Core.Version;
namespace Wox
{
@ -216,7 +217,10 @@ namespace Wox
#region About
tbVersion.Text = ConfigurationManager.AppSettings["version"];
tbVersion.Text = VersionManager.Instance.CurrentVersion.ToString();
string activateTimes = string.Format(InternationalizationManager.Instance.GetTranslation("about_activate_times"),
UserSettingStorage.Instance.ActivateTimes);
tbActivatedTimes.Text = activateTimes;
#endregion

View File

@ -4,6 +4,7 @@ using Newtonsoft.Json;
using Wox.Infrastructure.Storage;
using Wox.Plugin;
using System.IO;
using System.Reflection;
namespace Wox.Storage
{
@ -14,15 +15,7 @@ namespace Wox.Storage
protected override string ConfigFolder
{
get
{
string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE");
if (userProfilePath == null)
{
throw new ArgumentException("Environment variable USERPROFILE is empty");
}
return Path.Combine(Path.Combine(userProfilePath, ".Wox"), "Config");
}
get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); }
}
protected override string ConfigName

View File

@ -15,7 +15,7 @@ build:
after_test:
- ps: .\deploy\nuget\pack.ps1
- cmd: .\deploy\UpdateGenerator\build.bat
- cmd: .\deploy\Cleanup.bat
#- cmd: .\deploy\Cleanup.bat
deploy:
provider: NuGet