fix SingleInstance

This commit is contained in:
bao-qian
2016-05-09 22:45:20 +01:00
parent 21285f02b8
commit fb3ba16a92
12 changed files with 56 additions and 192 deletions

View File

@@ -1,87 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{88731DA8-C020-476E-B79A-3ADEF65ACA9F}</ProjectGuid>
<Keyword>MakeFileProj</Keyword>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<NMakePreprocessorDefinitions>WIN32;_DEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
<NMakeBuildCommandLine>taskkill /f /fi "IMAGENAME eq Wox.exe"</NMakeBuildCommandLine>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<NMakePreprocessorDefinitions>WIN32;NDEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
<NMakeBuildCommandLine>taskkill /f /fi "IMAGENAME eq Wox.exe"</NMakeBuildCommandLine>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<NMakeBuildCommandLine>taskkill /f /fi "IMAGENAME eq Wox.exe"</NMakeBuildCommandLine>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<NMakeBuildCommandLine>taskkill /f /fi "IMAGENAME eq Wox.exe"</NMakeBuildCommandLine>
</PropertyGroup>
<ItemDefinitionGroup>
</ItemDefinitionGroup>
<ItemGroup>
<Text Include="readme.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<Text Include="readme.txt" />
</ItemGroup>
</Project>

View File

@@ -1,3 +0,0 @@
This is project is just a workaround for pre solution level build event
See http://stackoverflow.com/a/2295583/2833083
todo: we currently can only force close Wox, there should be a better way

28
Wox.sln
View File

@@ -6,13 +6,9 @@ MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Test", "Wox.Test\Wox.Test.csproj", "{FF742965-9A80-41A5-B042-D6C7D3A21708}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Test", "Wox.Test\Wox.Test.csproj", "{FF742965-9A80-41A5-B042-D6C7D3A21708}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{DB90F671-D861-46BB-93A3-F1304F5BA1C5} = {DB90F671-D861-46BB-93A3-F1304F5BA1C5} {DB90F671-D861-46BB-93A3-F1304F5BA1C5} = {DB90F671-D861-46BB-93A3-F1304F5BA1C5}
{88731DA8-C020-476E-B79A-3ADEF65ACA9F} = {88731DA8-C020-476E-B79A-3ADEF65ACA9F}
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin", "Wox.Plugin\Wox.Plugin.csproj", "{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin", "Wox.Plugin\Wox.Plugin.csproj", "{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}"
ProjectSection(ProjectDependencies) = postProject
{88731DA8-C020-476E-B79A-3ADEF65ACA9F} = {88731DA8-C020-476E-B79A-3ADEF65ACA9F}
EndProjectSection
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87}"
EndProject EndProject
@@ -25,7 +21,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox", "Wox\Wox.csproj", "{D
{59BD9891-3837-438A-958D-ADC7F91F6F7E} = {59BD9891-3837-438A-958D-ADC7F91F6F7E} {59BD9891-3837-438A-958D-ADC7F91F6F7E} = {59BD9891-3837-438A-958D-ADC7F91F6F7E}
{C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0} = {C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0} {C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0} = {C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0}
{787B8AA6-CA93-4C84-96FE-DF31110AD1C4} = {787B8AA6-CA93-4C84-96FE-DF31110AD1C4} {787B8AA6-CA93-4C84-96FE-DF31110AD1C4} = {787B8AA6-CA93-4C84-96FE-DF31110AD1C4}
{88731DA8-C020-476E-B79A-3ADEF65ACA9F} = {88731DA8-C020-476E-B79A-3ADEF65ACA9F}
{F35190AA-4758-4D9E-A193-E3BDF6AD3567} = {F35190AA-4758-4D9E-A193-E3BDF6AD3567} {F35190AA-4758-4D9E-A193-E3BDF6AD3567} = {F35190AA-4758-4D9E-A193-E3BDF6AD3567}
{FDED22C8-B637-42E8-824A-63B5B6E05A3A} = {FDED22C8-B637-42E8-824A-63B5B6E05A3A} {FDED22C8-B637-42E8-824A-63B5B6E05A3A} = {FDED22C8-B637-42E8-824A-63B5B6E05A3A}
{A3DCCBCA-ACC1-421D-B16E-210896234C26} = {A3DCCBCA-ACC1-421D-B16E-210896234C26} {A3DCCBCA-ACC1-421D-B16E-210896234C26} = {A3DCCBCA-ACC1-421D-B16E-210896234C26}
@@ -34,16 +29,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox", "Wox\Wox.csproj", "{D
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Infrastructure", "Wox.Infrastructure\Wox.Infrastructure.csproj", "{4FD29318-A8AB-4D8F-AA47-60BC241B8DA3}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Infrastructure", "Wox.Infrastructure\Wox.Infrastructure.csproj", "{4FD29318-A8AB-4D8F-AA47-60BC241B8DA3}"
ProjectSection(ProjectDependencies) = postProject
{88731DA8-C020-476E-B79A-3ADEF65ACA9F} = {88731DA8-C020-476E-B79A-3ADEF65ACA9F}
EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.PluginManagement", "Plugins\Wox.Plugin.PluginManagement\Wox.Plugin.PluginManagement.csproj", "{049490F0-ECD2-4148-9B39-2135EC346EBE}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.PluginManagement", "Plugins\Wox.Plugin.PluginManagement\Wox.Plugin.PluginManagement.csproj", "{049490F0-ECD2-4148-9B39-2135EC346EBE}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Core", "Wox.Core\Wox.Core.csproj", "{B749F0DB-8E75-47DB-9E5E-265D16D0C0D2}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Core", "Wox.Core\Wox.Core.csproj", "{B749F0DB-8E75-47DB-9E5E-265D16D0C0D2}"
ProjectSection(ProjectDependencies) = postProject
{88731DA8-C020-476E-B79A-3ADEF65ACA9F} = {88731DA8-C020-476E-B79A-3ADEF65ACA9F}
EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Program", "Plugins\Wox.Plugin.Program\Wox.Plugin.Program.csproj", "{FDB3555B-58EF-4AE6-B5F1-904719637AB4}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Program", "Plugins\Wox.Plugin.Program\Wox.Plugin.Program.csproj", "{FDB3555B-58EF-4AE6-B5F1-904719637AB4}"
EndProject EndProject
@@ -66,9 +55,6 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Color", "Plugins\Wox.Plugin.Color\Wox.Plugin.Color.csproj", "{F35190AA-4758-4D9E-A193-E3BDF6AD3567}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Color", "Plugins\Wox.Plugin.Color\Wox.Plugin.Color.csproj", "{F35190AA-4758-4D9E-A193-E3BDF6AD3567}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.CrashReporter", "Wox.CrashReporter\Wox.CrashReporter.csproj", "{2FEB2298-7653-4009-B1EA-FFFB1A768BCC}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.CrashReporter", "Wox.CrashReporter\Wox.CrashReporter.csproj", "{2FEB2298-7653-4009-B1EA-FFFB1A768BCC}"
ProjectSection(ProjectDependencies) = postProject
{88731DA8-C020-476E-B79A-3ADEF65ACA9F} = {88731DA8-C020-476E-B79A-3ADEF65ACA9F}
EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Everything", "Plugins\Wox.Plugin.Everything\Wox.Plugin.Everything.csproj", "{230AE83F-E92E-4E69-8355-426B305DA9C0}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Everything", "Plugins\Wox.Plugin.Everything\Wox.Plugin.Everything.csproj", "{230AE83F-E92E-4E69-8355-426B305DA9C0}"
EndProject EndProject
@@ -83,8 +69,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
SolutionAssemblyInfo.cs = SolutionAssemblyInfo.cs SolutionAssemblyInfo.cs = SolutionAssemblyInfo.cs
EndProjectSection EndProjectSection
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PreSolutionBuild", "PreSolutionBuild\PreSolutionBuild.vcxproj", "{88731DA8-C020-476E-B79A-3ADEF65ACA9F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorldCSharp", "Plugins\HelloWorldCSharp\HelloWorldCSharp.csproj", "{03FFA443-5F50-48D5-8869-F3DF316803AA}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorldCSharp", "Plugins\HelloWorldCSharp\HelloWorldCSharp.csproj", "{03FFA443-5F50-48D5-8869-F3DF316803AA}"
EndProject EndProject
Global Global
@@ -314,18 +298,6 @@ Global
{230AE83F-E92E-4E69-8355-426B305DA9C0}.Release|x64.Build.0 = Release|Any CPU {230AE83F-E92E-4E69-8355-426B305DA9C0}.Release|x64.Build.0 = Release|Any CPU
{230AE83F-E92E-4E69-8355-426B305DA9C0}.Release|x86.ActiveCfg = Release|Any CPU {230AE83F-E92E-4E69-8355-426B305DA9C0}.Release|x86.ActiveCfg = Release|Any CPU
{230AE83F-E92E-4E69-8355-426B305DA9C0}.Release|x86.Build.0 = Release|Any CPU {230AE83F-E92E-4E69-8355-426B305DA9C0}.Release|x86.Build.0 = Release|Any CPU
{88731DA8-C020-476E-B79A-3ADEF65ACA9F}.Debug|Any CPU.ActiveCfg = Debug|Win32
{88731DA8-C020-476E-B79A-3ADEF65ACA9F}.Debug|Any CPU.Build.0 = Debug|Win32
{88731DA8-C020-476E-B79A-3ADEF65ACA9F}.Debug|x64.ActiveCfg = Debug|x64
{88731DA8-C020-476E-B79A-3ADEF65ACA9F}.Debug|x64.Build.0 = Debug|x64
{88731DA8-C020-476E-B79A-3ADEF65ACA9F}.Debug|x86.ActiveCfg = Debug|Win32
{88731DA8-C020-476E-B79A-3ADEF65ACA9F}.Debug|x86.Build.0 = Debug|Win32
{88731DA8-C020-476E-B79A-3ADEF65ACA9F}.Release|Any CPU.ActiveCfg = Release|x64
{88731DA8-C020-476E-B79A-3ADEF65ACA9F}.Release|Any CPU.Build.0 = Release|x64
{88731DA8-C020-476E-B79A-3ADEF65ACA9F}.Release|x64.ActiveCfg = Release|x64
{88731DA8-C020-476E-B79A-3ADEF65ACA9F}.Release|x64.Build.0 = Release|x64
{88731DA8-C020-476E-B79A-3ADEF65ACA9F}.Release|x86.ActiveCfg = Release|Win32
{88731DA8-C020-476E-B79A-3ADEF65ACA9F}.Release|x86.Build.0 = Release|Win32
{03FFA443-5F50-48D5-8869-F3DF316803AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {03FFA443-5F50-48D5-8869-F3DF316803AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{03FFA443-5F50-48D5-8869-F3DF316803AA}.Debug|Any CPU.Build.0 = Debug|Any CPU {03FFA443-5F50-48D5-8869-F3DF316803AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{03FFA443-5F50-48D5-8869-F3DF316803AA}.Debug|x64.ActiveCfg = Debug|Any CPU {03FFA443-5F50-48D5-8869-F3DF316803AA}.Debug|x64.ActiveCfg = Debug|Any CPU

View File

@@ -10,11 +10,10 @@ using Stopwatch = Wox.Infrastructure.Stopwatch;
namespace Wox namespace Wox
{ {
public partial class App : ISingleInstanceApp, IDisposable public partial class App : IDisposable, ISingleInstanceApp
{ {
private const string Unique = "Wox_Unique_Application_Mutex";
public static MainWindow Window { get; private set; }
public static PublicAPIInstance API { get; private set; } public static PublicAPIInstance API { get; private set; }
private const string Unique = "Wox_Unique_Application_Mutex";
private static bool _disposed; private static bool _disposed;
[STAThread] [STAThread]
@@ -44,10 +43,14 @@ namespace Wox
API = new PublicAPIInstance(mainVM, mainVM._settings); API = new PublicAPIInstance(mainVM, mainVM._settings);
PluginManager.InitializePlugins(API, pluginsSettings); PluginManager.InitializePlugins(API, pluginsSettings);
Window = new MainWindow(mainVM._settings, mainVM);
var _notifyIconManager = new NotifyIconManager(API); var _notifyIconManager = new NotifyIconManager(API);
var window = new MainWindow(mainVM._settings, mainVM);
RegisterExitEvents(); RegisterExitEvents();
Current.MainWindow = window;
Current.MainWindow.Title = Infrastructure.Wox.Name;
window.Show();
}); });
} }
@@ -76,30 +79,21 @@ namespace Wox
AppDomain.CurrentDomain.UnhandledException += ErrorReporting.UnhandledExceptionHandle; AppDomain.CurrentDomain.UnhandledException += ErrorReporting.UnhandledExceptionHandle;
} }
public void OnActivate()
{
API.ShowApp();
}
private static void Save()
{
var vm = (MainViewModel)Window.DataContext;
vm.Save();
PluginManager.Save();
ImageLoader.Save();
_disposed = true;
}
public void Dispose() public void Dispose()
{ {
// if sessionending is called, exit proverbially be called when log off / shutdown // if sessionending is called, exit proverbially be called when log off / shutdown
// but if sessionending is not called, exit won't be called when log off / shutdown // but if sessionending is not called, exit won't be called when log off / shutdown
if (!_disposed) if (!_disposed)
{ {
Save(); var vm = (MainViewModel)Current.MainWindow.DataContext;
SingleInstance<App>.Cleanup(); vm.Save();
_disposed = true;
} }
} }
public void OnSecondAppStarted()
{
API.ShowApp();
}
} }
} }

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Windows;
using System.Windows.Threading; using System.Windows.Threading;
using Wox.Infrastructure.Exception; using Wox.Infrastructure.Exception;
using Wox.Infrastructure.Logger; using Wox.Infrastructure.Logger;
@@ -16,7 +17,7 @@ namespace Wox.Helper
public static void UnhandledExceptionHandle(object sender, UnhandledExceptionEventArgs e) public static void UnhandledExceptionHandle(object sender, UnhandledExceptionEventArgs e)
{ {
//handle non-ui thread exceptions //handle non-ui thread exceptions
App.Window.Dispatcher.Invoke(() => Application.Current.MainWindow.Dispatcher.Invoke(() =>
{ {
Report((Exception)e.ExceptionObject); Report((Exception)e.ExceptionObject);
if (!(e.ExceptionObject is WoxException)) if (!(e.ExceptionObject is WoxException))

View File

@@ -186,7 +186,7 @@ namespace Wox.Helper
public interface ISingleInstanceApp public interface ISingleInstanceApp
{ {
void OnActivate(); void OnSecondAppStarted();
} }
/// <summary> /// <summary>
@@ -416,7 +416,7 @@ namespace Wox.Helper
return; return;
} }
((TApplication)Application.Current).OnActivate(); ((TApplication)Application.Current).OnSecondAppStarted();
} }
#endregion #endregion
@@ -437,8 +437,7 @@ namespace Wox.Helper
if (Application.Current != null) if (Application.Current != null)
{ {
// Do an asynchronous call to ActivateFirstInstance function // Do an asynchronous call to ActivateFirstInstance function
Application.Current.Dispatcher.BeginInvoke( Application.Current.Dispatcher.Invoke(ActivateFirstInstance);
DispatcherPriority.Normal, new DispatcherOperationCallback(ActivateFirstInstanceCallback));
} }
} }

View File

@@ -10,6 +10,7 @@ using Wox.Core.Resource;
using Wox.Core.UserSettings; using Wox.Core.UserSettings;
using Wox.Helper; using Wox.Helper;
using Wox.Infrastructure.Hotkey; using Wox.Infrastructure.Hotkey;
using Wox.Infrastructure.Logger;
using Wox.ViewModel; using Wox.ViewModel;
using DataFormats = System.Windows.DataFormats; using DataFormats = System.Windows.DataFormats;
using DragEventArgs = System.Windows.DragEventArgs; using DragEventArgs = System.Windows.DragEventArgs;
@@ -42,8 +43,12 @@ namespace Wox
{ {
_settings.WindowLeft = Left; _settings.WindowLeft = Left;
_settings.WindowTop = Top; _settings.WindowTop = Top;
var vm = (MainViewModel) DataContext;
vm.Save();
} }
private void OnLoaded(object sender, RoutedEventArgs _) private void OnLoaded(object sender, RoutedEventArgs _)
{ {
InitProgressbarAnimation(); InitProgressbarAnimation();

View File

@@ -63,16 +63,17 @@ namespace Wox
public void CloseApp() public void CloseApp()
{ {
//notifyIcon.Visible = false; //notifyIcon.Visible = false;
Application.Current.Shutdown(); Application.Current.MainWindow.Close();
} }
public void RestarApp() public void RestarApp()
{ {
HideWox(); HideWox();
// we must force dispose application // we must manually save
// UpdateManager.RestartApp() will call Environment.Exit(0) // UpdateManager.RestartApp() will call Environment.Exit(0)
// which will cause ungraceful exit // which will cause ungraceful exit
((IDisposable) Application.Current).Dispose(); var vm = (MainViewModel) Application.Current.MainWindow.DataContext;
vm.Save();
UpdateManager.RestartApp(); UpdateManager.RestartApp();
} }

View File

@@ -7,7 +7,6 @@ using System.Net;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Forms;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
@@ -24,18 +23,11 @@ using Wox.Infrastructure.Hotkey;
using Wox.Infrastructure.Image; using Wox.Infrastructure.Image;
using Wox.Plugin; using Wox.Plugin;
using Wox.ViewModel; using Wox.ViewModel;
using Application = System.Windows.Forms.Application;
using CheckBox = System.Windows.Controls.CheckBox;
using Control = System.Windows.Controls.Control;
using Cursors = System.Windows.Input.Cursors;
using HorizontalAlignment = System.Windows.HorizontalAlignment;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using MessageBox = System.Windows.MessageBox;
using Stopwatch = Wox.Infrastructure.Stopwatch; using Stopwatch = Wox.Infrastructure.Stopwatch;
namespace Wox namespace Wox
{ {
public partial class SettingWindow : Window public partial class SettingWindow
{ {
public readonly IPublicAPI _api; public readonly IPublicAPI _api;
bool settingsLoaded; bool settingsLoaded;
@@ -227,7 +219,7 @@ namespace Wox
RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
true)) true))
{ {
key.SetValue("Wox", "\"" + Application.ExecutablePath + "\" --hidestart"); key.SetValue("Wox", "\"" + Infrastructure.Wox.ProgramPath + "\" --hidestart");
} }
} }
@@ -253,7 +245,7 @@ namespace Wox
private void SelectPythonDirectoryOnClick(object sender, RoutedEventArgs e) private void SelectPythonDirectoryOnClick(object sender, RoutedEventArgs e)
{ {
var dlg = new FolderBrowserDialog var dlg = new System.Windows.Forms.FolderBrowserDialog
{ {
SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
}; };
@@ -289,7 +281,7 @@ namespace Wox
{ {
SetHotkey(ctlHotkey.CurrentHotkey, delegate SetHotkey(ctlHotkey.CurrentHotkey, delegate
{ {
if (!App.Window.IsVisible) if (!System.Windows.Application.Current.MainWindow.IsVisible)
{ {
_api.ShowApp(); _api.ShowApp();
} }
@@ -433,48 +425,48 @@ namespace Wox
Title = "Wox is an effective launcher for windows", Title = "Wox is an effective launcher for windows",
SubTitle = "Wox provide bundles of features let you access infomations quickly.", SubTitle = "Wox provide bundles of features let you access infomations quickly.",
IcoPath = "Images/app.png", IcoPath = "Images/app.png",
PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath) PluginDirectory = Path.GetDirectoryName(Infrastructure.Wox.ProgramPath)
}, },
new Result new Result
{ {
Title = "Search applications", Title = "Search applications",
SubTitle = "Search applications, files (via everything plugin) and browser bookmarks", SubTitle = "Search applications, files (via everything plugin) and browser bookmarks",
IcoPath = "Images/app.png", IcoPath = "Images/app.png",
PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath) PluginDirectory = Path.GetDirectoryName(Infrastructure.Wox.ProgramPath)
}, },
new Result new Result
{ {
Title = "Search web contents with shortcuts", Title = "Search web contents with shortcuts",
SubTitle = "e.g. search google with g keyword or youtube keyword)", SubTitle = "e.g. search google with g keyword or youtube keyword)",
IcoPath = "Images/app.png", IcoPath = "Images/app.png",
PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath) PluginDirectory = Path.GetDirectoryName(Infrastructure.Wox.ProgramPath)
}, },
new Result new Result
{ {
Title = "clipboard history ", Title = "clipboard history ",
IcoPath = "Images/app.png", IcoPath = "Images/app.png",
PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath) PluginDirectory = Path.GetDirectoryName(Infrastructure.Wox.ProgramPath)
}, },
new Result new Result
{ {
Title = "Themes support", Title = "Themes support",
SubTitle = "get more themes from http://www.getwox.com/theme", SubTitle = "get more themes from http://www.getwox.com/theme",
IcoPath = "Images/app.png", IcoPath = "Images/app.png",
PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath) PluginDirectory = Path.GetDirectoryName(Infrastructure.Wox.ProgramPath)
}, },
new Result new Result
{ {
Title = "Plugins support", Title = "Plugins support",
SubTitle = "get more plugins from http://www.getwox.com/plugin", SubTitle = "get more plugins from http://www.getwox.com/plugin",
IcoPath = "Images/app.png", IcoPath = "Images/app.png",
PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath) PluginDirectory = Path.GetDirectoryName(Infrastructure.Wox.ProgramPath)
}, },
new Result new Result
{ {
Title = "Wox is an open-source software", Title = "Wox is an open-source software",
SubTitle = "Wox benefits from the open-source community a lot", SubTitle = "Wox benefits from the open-source community a lot",
IcoPath = "Images/app.png", IcoPath = "Images/app.png",
PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath) PluginDirectory = Path.GetDirectoryName(Infrastructure.Wox.ProgramPath)
} }
}); });

View File

@@ -11,6 +11,7 @@ using Wox.Core.UserSettings;
using Wox.Helper; using Wox.Helper;
using Wox.Infrastructure; using Wox.Infrastructure;
using Wox.Infrastructure.Hotkey; using Wox.Infrastructure.Hotkey;
using Wox.Infrastructure.Image;
using Wox.Infrastructure.Storage; using Wox.Infrastructure.Storage;
using Wox.Plugin; using Wox.Plugin;
using Wox.Storage; using Wox.Storage;
@@ -47,6 +48,7 @@ namespace Wox.ViewModel
private CancellationTokenSource _updateSource; private CancellationTokenSource _updateSource;
private CancellationToken _updateToken; private CancellationToken _updateToken;
private bool _saved;
#endregion #endregion
@@ -54,6 +56,7 @@ namespace Wox.ViewModel
public MainViewModel() public MainViewModel()
{ {
_saved = false;
_queryTextBeforeLoadContextMenu = ""; _queryTextBeforeLoadContextMenu = "";
_queryText = ""; _queryText = "";
_lastQuery = new Query(); _lastQuery = new Query();
@@ -592,10 +595,18 @@ namespace Wox.ViewModel
public void Save() public void Save()
{ {
_settingsStorage.Save(); if (!_saved)
_queryHistoryStorage.Save(); {
_userSelectedRecordStorage.Save(); _settingsStorage.Save();
_topMostRecordStorage.Save(); _queryHistoryStorage.Save();
_userSelectedRecordStorage.Save();
_topMostRecordStorage.Save();
PluginManager.Save();
ImageLoader.Save();
_saved = true;
}
} }
/// <summary> /// <summary>

View File

@@ -432,8 +432,7 @@
</PostBuildEvent> </PostBuildEvent>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<PreBuildEvent> <PreBuildEvent>taskkill /f /fi "IMAGENAME eq Wox.exe</PreBuildEvent>
</PreBuildEvent>
</PropertyGroup> </PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.