Skip to content

Commit

Permalink
Merge branch 'release/1.0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
canton7 committed Mar 2, 2015
2 parents 48482cc + 372a091 commit 2b37034
Show file tree
Hide file tree
Showing 19 changed files with 139 additions and 68 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
Changelog
=========

v1.0.4
------

- Handle Syncthing upgrades (previously would require a 'Kill all syncthing processes' then 'Start')
- Fix crash when logging out / shutting down with SyncTrayzor opened (caused by embedded browser component)
- Don't unload browser when minimized. This means that open Syncthing dialogs aren't closed when minimizing
- Reduce memory usage if SyncTrayzor is never restored from tray
- UI tweaks and fixes
- Add VC++ x64 Redist to the installer

v1.0.3
------

Expand Down
1 change: 1 addition & 0 deletions installer/installer.iss
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Source: "{#AppBin}\locales\*"; DestDir: "{app}\locales"; Flags: ignoreversion
Source: "{#AppSrc}\Icons\default.ico"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#AppRoot}\*.md"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#AppRoot}\*.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "*.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "syncthing.exe"; DestDir: "{userappdata}\{#AppDataFolder}"
Source: "dotNet451Setup.exe"; DestDir: {tmp}; Flags: deleteafterinstall; Check: FrameworkIsNotInstalled

Expand Down
Binary file added installer/msvcp110.dll
Binary file not shown.
Binary file added installer/msvcr110.dll
Binary file not shown.
Binary file added installer/vccorlib110.dll
Binary file not shown.
14 changes: 12 additions & 2 deletions src/SyncTrayzor/Bootstrapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NLog;
using CefSharp;
using NLog;
using Stylet;
using StyletIoC;
using SyncTrayzor.NotifyIcon;
Expand All @@ -8,6 +9,7 @@
using SyncTrayzor.SyncThing;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -39,9 +41,18 @@ protected override void Configure()
{
GlobalDiagnosticsContext.Set("LogFilePath", this.Container.Get<IConfigurationProvider>().BasePath);

// Must be done before ConfigurationApplicator.ApplyConfiguration
#if DEBUG
this.Container.Get<IAutostartProvider>().IsEnabled = false;
#endif

var notifyIconManager = this.Container.Get<INotifyIconManager>();
notifyIconManager.Setup((INotifyIconDelegate)this.RootViewModel);
this.Container.Get<ConfigurationApplicator>().ApplyConfiguration();

// Horrible workaround for a CefSharp crash on logout/shutdown
// https://github.com/cefsharp/CefSharp/issues/800#issuecomment-75058534
this.Application.SessionEnding += (o, e) => Process.GetCurrentProcess().Kill();
}

protected override void Launch()
Expand Down Expand Up @@ -79,7 +90,6 @@ protected override void OnUnhandledException(DispatcherUnhandledExceptionEventAr
var vm = this.Container.Get<UnhandledExceptionViewModel>();
vm.Exception = e.Exception;
windowManager.ShowDialog(vm);
//windowManager.ShowMessageBox(String.Format("Unhandled error: {0}", e.Exception.Message), "Unhandled error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/SyncTrayzor/Pages/NewVersionAlertView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="https://github.com/canton7/Stylet"
Height="400" Width="400">
Width="400" MaxHeight="600"
SizeToContent="Height">
<DockPanel Margin="10">
<TextBlock DockPanel.Dock="Top" TextWrapping="Wrap">
A new version of SyncTrayzor is available!<LineBreak/><LineBreak/>
Expand All @@ -14,6 +15,7 @@
<Button IsDefault="True" Command="{s:Action Download}">Yes</Button>
<Button IsCancel="True" Command="{s:Action Close}">No</Button>
</StackPanel>
<TextBox IsReadOnly="True" TextWrapping="Wrap" Text="{Binding Changelog}"/>
<TextBox IsReadOnly="True" TextWrapping="Wrap" Text="{Binding Changelog}"
ScrollViewer.VerticalScrollBarVisibility="Auto"/>
</DockPanel>
</Window>
2 changes: 1 addition & 1 deletion src/SyncTrayzor/Pages/NewVersionAlertViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class NewVersionAlertViewModel : Screen

public NewVersionAlertViewModel()
{
this.DisplayName = "New Version Available";
this.DisplayName = "SyncTrayzor update available";
}

public void Download()
Expand Down
21 changes: 5 additions & 16 deletions src/SyncTrayzor/Pages/ViewerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,18 @@ public ViewerViewModel(ISyncThingManager syncThingManager)
webBrowser.RequestHandler = this;
webBrowser.LifeSpanHandler = this;
});

this.StateChanged += (o, e) =>
{
if (e.NewState == ScreenState.Active && (e.PreviousState == ScreenState.Initial || e.PreviousState == ScreenState.Closed))
Cef.Initialize(new CefSettings());
};
}

public void RefreshBrowser()
protected override void OnInitialActivate()
{
this.Location = "about:blank";
if (this.syncThingManager.State == SyncThingState.Running && this.IsActive)
this.Location = this.syncThingManager.Address.NormalizeZeroHost().ToString();
Cef.Initialize();
}

protected override void OnActivate()
{
this.RefreshBrowser();
}

protected override void OnDeactivate()
public void RefreshBrowser()
{
this.Location = "about:blank";
if (this.syncThingManager.State == SyncThingState.Running)
this.Location = this.syncThingManager.Address.NormalizeZeroHost().ToString();
}

protected override void OnClose()
Expand Down
4 changes: 2 additions & 2 deletions src/SyncTrayzor/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.3.0")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyVersion("1.0.4.0")]
[assembly: AssemblyFileVersion("1.0.4.0")]
24 changes: 19 additions & 5 deletions src/SyncTrayzor/Services/AutostartProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace SyncTrayzor.Services
{
public interface IAutostartProvider
{
bool IsEnabled { get; set; }
bool CanRead { get; }
bool CanWrite { get; }

Expand All @@ -29,25 +30,38 @@ public class AutostartProvider : IAutostartProvider
{
private const string applicationName = "SyncTrayzor";

public bool CanRead { get; private set; }
public bool CanWrite { get; private set; }
public bool IsEnabled { get; set; }

private bool _canRead;
public bool CanRead
{
get { return this.IsEnabled && this._canRead; }
}

private bool _canWrite;
public bool CanWrite
{
get { return this.IsEnabled && this._canWrite; }
}

public AutostartProvider()
{
this.IsEnabled = true; // Default

// Check our access
try
{
this.OpenRegistryKey(true).Dispose();
this.CanWrite = true;
this.CanRead = true;
this._canWrite = true;
this._canRead = true;
return;
}
catch (SecurityException) { }

try
{
this.OpenRegistryKey(false).Dispose();
this.CanRead = true;
this._canRead = true;
}
catch (SecurityException) { }
}
Expand Down
3 changes: 1 addition & 2 deletions src/SyncTrayzor/Services/ConfigurationApplicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ public ConfigurationApplicator(

private void UpdateConfigOnInit()
{
#if !DEBUG
this.UpdateAutostart();
#endif
}

private void UpdateAutostart()
Expand Down Expand Up @@ -97,6 +95,7 @@ private void ApplyNewConfiguration(Configuration configuration)
this.syncThingManager.ExecutablePath = configuration.SyncthingPath;
this.syncThingManager.ApiKey = configuration.SyncthingApiKey;

// Debug builds never set autostart
// Don't have permission? Meh
if (this.autostartProvider.CanWrite)
this.autostartProvider.SetAutoStart(new AutostartConfiguration() { AutoStart = configuration.StartOnLogon, StartMinimized = configuration.StartMinimized });
Expand Down
26 changes: 23 additions & 3 deletions src/SyncTrayzor/Services/UpdateChecker/UpdateChecker.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Stylet;
using NLog;
using Stylet;
using SyncTrayzor.Pages;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -35,6 +36,11 @@ public VersionCheckResults(Version latestVersion, bool latestVersionIsNewer, str
this.LatestVersionDownloadUrl = latestVersionDownloadUrl;
this.LatestVersionChangelog = latestVersionChangelog;
}

public override string ToString()
{
return String.Format("<VersionCheckResults LatestVersion={0} IsNewer={1} DownloadUrl={2}>", this.LatestVersion, this.LatestVersionIsNewer, this.LatestVersionDownloadUrl);
}
}

public interface IUpdateChecker
Expand All @@ -48,6 +54,8 @@ public interface IUpdateChecker

public class UpdateChecker : IUpdateChecker
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();

private readonly IWindowManager windowManager;
private readonly IGithubApiClient apiClient;
private readonly Func<NewVersionAlertViewModel> newersionAlertViewModelFactory;
Expand All @@ -74,12 +82,18 @@ public async Task<VersionCheckResults> FetchUpdatesAsync()
var latestRelease = await this.apiClient.FetchLatestReleaseAsync();

if (latestRelease == null)
{
logger.Info("No suitable releases found");
return null;
}

return new VersionCheckResults(latestRelease.Version, latestRelease.Version > applicationVersion, latestRelease.DownloadUrl, latestRelease.Body);
var results = new VersionCheckResults(latestRelease.Version, latestRelease.Version > applicationVersion, latestRelease.DownloadUrl, latestRelease.Body);
logger.Info("Found new version: {0}", results);
return results;
}
catch (Exception)
catch (Exception e)
{
logger.Warn("Fetching updates failed with an error", e);
return null;
}
}
Expand All @@ -101,9 +115,15 @@ public async Task CheckForUpdatesAsync()
vm.Version = results.LatestVersion;
var result = this.windowManager.ShowDialog(vm);
if (result == true)
{
logger.Info("Proceeding to download URL {0}", results.LatestVersionDownloadUrl);
Process.Start(results.LatestVersionDownloadUrl);
}
else
{
logger.Info("Ignoring version {0}", results.LatestVersion);
this.OnVersionIgnored(results.LatestVersion);
}
}
}

Expand Down
7 changes: 1 addition & 6 deletions src/SyncTrayzor/SyncThing/SyncThingEventWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,7 @@ protected override async Task PollAsync()
{
try
{
List<Event> events;
// If we don't know what the latest event ID is (disconnection? new connection?), make sure we find out
if (this.lastEventId == 0)
events = await this.apiClient.FetchEventsAsync(0, 1);
else
events = await this.apiClient.FetchEventsAsync(this.lastEventId);
var events = await this.apiClient.FetchEventsAsync(this.lastEventId);

foreach (var evt in events)
{
Expand Down
8 changes: 8 additions & 0 deletions src/SyncTrayzor/SyncThing/SyncThingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ private void SetState(SyncThingState state)
if (state == this.State)
return;

// We really need a proper state machine here....
// There's a race if Syncthing can't start because the database is locked by another process on the same port
// In this case, we see the process as having failed, but the event watcher chimes in a split-second later with the 'Started' event.
// This runs the risk of transitioning us from Stopped -> Starting -> Stopepd -> Running, which is bad news for everyone
// So, get around this by enforcing strict state transitions.
if (this.State == SyncThingState.Stopped && state == SyncThingState.Running)
return;

var oldState = this.State;
this.State = state;

Expand Down
39 changes: 13 additions & 26 deletions src/SyncTrayzor/SyncThing/SyncThingProcessRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public interface ISyncThingProcessRunner : IDisposable
public class SyncThingProcessRunner : ISyncThingProcessRunner
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
private static readonly string[] defaultArguments = new[] { "-no-browser" };
private static readonly string[] defaultArguments = new[] { "-no-browser", "-no-restart" };

private Process process;

Expand Down Expand Up @@ -102,8 +102,7 @@ private void KillInternal()
{
if (this.process != null)
{
KillProcessAndChildren(this.process.Id);
this.process = null;
this.process.Kill();
}
}

Expand All @@ -130,9 +129,17 @@ private void OnProcessStopped()
{
SyncThingExitStatus exitStatus = this.process == null ? SyncThingExitStatus.Success : (SyncThingExitStatus)this.process.ExitCode;
logger.Info("Syncthing process stopped with exit status {0}", exitStatus);
var handler = this.ProcessStopped;
if (handler != null)
handler(this, new ProcessStoppedEventArgs(exitStatus));
if (exitStatus == SyncThingExitStatus.Restarting || exitStatus == SyncThingExitStatus.Upgrading)
{
logger.Info("Syncthing process requested restart, so restarting");
this.Start();
}
else
{
var handler = this.ProcessStopped;
if (handler != null)
handler(this, new ProcessStoppedEventArgs(exitStatus));
}
}

private void OnMessageLogged(string logMessage)
Expand All @@ -143,26 +150,6 @@ private void OnMessageLogged(string logMessage)
handler(this, new MessageLoggedEventArgs(logMessage));
}

// http://stackoverflow.com/questions/5901679/kill-process-tree-programatically-in-c-sharp
private static void KillProcessAndChildren(int pid)
{
var searcher = new ManagementObjectSearcher("Select * From Win32_Process Where ParentProcessID=" + pid);
var managementObjectCollection = searcher.Get();
foreach (var managementObject in managementObjectCollection)
{
KillProcessAndChildren(Convert.ToInt32(managementObject["ProcessID"]));
}
try
{
Process proc = Process.GetProcessById(pid);
proc.Kill();
}
catch (ArgumentException)
{
// Process already exited.
}
}

public void KillAllSyncthingProcesses()
{
foreach (var process in Process.GetProcessesByName("syncthing"))
Expand Down
5 changes: 3 additions & 2 deletions src/SyncTrayzor/SyncTrayzor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@
<Reference Include="Refit">
<HintPath>..\packages\refit.2.2.0\lib\Net45\Refit.dll</HintPath>
</Reference>
<Reference Include="Stylet, Version=1.1.3.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="Stylet, Version=1.1.4.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Stylet.1.1.3\lib\net45\Stylet.dll</HintPath>
<HintPath>..\packages\Stylet.1.1.4\lib\net45\Stylet.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
Expand Down Expand Up @@ -178,6 +178,7 @@
<Compile Include="SyncThing\SyncThingProcessRunner.cs" />
<Compile Include="SyncThing\SyncThingState.cs" />
<Compile Include="SyncThing\SyncThingStateChangedEventArgs.cs" />
<Compile Include="Utils\CefSharpHelper.cs" />
<Compile Include="Utils\ObservableQueue.cs" />
<Compile Include="Utils\SynchronizedEventDispatcher.cs" />
<Compile Include="Utils\UriExtensions.cs" />
Expand Down
Loading

0 comments on commit 2b37034

Please sign in to comment.