Browse Source

Add option to hide Syncthing console

Fixes #41
Antony Male 10 years ago
parent
commit
529ba2b835

+ 1 - 0
src/SyncTrayzor/App.config

@@ -52,6 +52,7 @@
                         <NotifyOfNewVersions>true</NotifyOfNewVersions>
                         <ObfuscateDeviceIDs>true</ObfuscateDeviceIDs>
                         <UseComputerCulture>true</UseComputerCulture>
+                        <ShowSyncthingConsole>true</ShowSyncthingConsole>
                     </Configuration>
                 </value>
             </setting>

+ 14 - 3
src/SyncTrayzor/Pages/ShellView.xaml

@@ -25,6 +25,9 @@
                 <MenuItem Header="{l:Loc ShellView_Menu_Syncthing_OpenExternal}" Command="{s:Action OpenBrowser}"/>
                 <MenuItem Header="{l:Loc ShellView_Menu_Syncthing_KillAll}" Command="{s:Action KillAllSyncthingProcesses}"/>
             </MenuItem>
+            <MenuItem Header="{l:Loc ShellView_Menu_View}">
+                <MenuItem Header="{l:Loc ShellView_Menu_View_SyncthingConsole}" IsCheckable="True" IsChecked="{Binding ShowConsole}"/>
+            </MenuItem>
             <MenuItem Header="{l:Loc ShellView_Menu_Help}">
                 <MenuItem Header="{l:Loc ShellView_Menu_Help_About}" Command="{s:Action ShowAbout}"/>
             </MenuItem>
@@ -33,15 +36,23 @@
         <Grid>
             <Grid.RowDefinitions>
                 <RowDefinition Height="5*"/>
-                <RowDefinition Height="5"/>
-                <RowDefinition Height="*" MinHeight="100"/>
+                <RowDefinition>
+                    <i:Interaction.Behaviors>
+                        <xaml:CollapsingRowDefinitionBehaviour Height="5" RowVisibility="{Binding ShowConsole, Converter={x:Static s:BoolToVisibilityConverter.Instance}}"/>
+                    </i:Interaction.Behaviors>
+                </RowDefinition>
+                <RowDefinition>
+                    <i:Interaction.Behaviors>
+                        <xaml:CollapsingRowDefinitionBehaviour Height="*" MinHeight="100" RowVisibility="{Binding ShowConsole, Converter={x:Static s:BoolToVisibilityConverter.Instance}}"/>
+                    </i:Interaction.Behaviors>
+                </RowDefinition>
             </Grid.RowDefinitions>
 
             <ContentControl Grid.Row="0" s:View.Model="{Binding Viewer}"/>
 
             <GridSplitter Grid.Row="1" Height="5" HorizontalAlignment="Stretch" ShowsPreview="True"/>
 
-            <ContentControl Grid.Row="2" s:View.Model="{Binding Console}" MinHeight="100"/>
+            <ContentControl Grid.Row="2" s:View.Model="{Binding Console}"/>
         </Grid>
     </DockPanel>
 </Window>

+ 13 - 0
src/SyncTrayzor/Pages/ShellViewModel.cs

@@ -2,6 +2,7 @@
 using SyncTrayzor.Localization;
 using SyncTrayzor.NotifyIcon;
 using SyncTrayzor.Services;
+using SyncTrayzor.Services.Config;
 using SyncTrayzor.SyncThing;
 using SyncTrayzor.Utils;
 using System;
@@ -19,10 +20,12 @@ namespace SyncTrayzor.Pages
         private readonly IWindowManager windowManager;
         private readonly ISyncThingManager syncThingManager;
         private readonly IApplicationState application;
+        private readonly IConfigurationProvider configurationProvider;
         private readonly Func<SettingsViewModel> settingsViewModelFactory;
         private readonly Func<AboutViewModel> aboutViewModelFactory;
 
         public bool WindowActivated { get; set; }
+        public bool ShowConsole { get; set; }
         public ConsoleViewModel Console { get; private set; }
         public ViewerViewModel Viewer { get; private set; }
 
@@ -32,6 +35,7 @@ namespace SyncTrayzor.Pages
             IWindowManager windowManager,
             ISyncThingManager syncThingManager,
             IApplicationState application,
+            IConfigurationProvider configurationProvider,
             ConsoleViewModel console,
             ViewerViewModel viewer,
             Func<SettingsViewModel> settingsViewModelFactory,
@@ -40,6 +44,7 @@ namespace SyncTrayzor.Pages
             this.windowManager = windowManager;
             this.syncThingManager = syncThingManager;
             this.application = application;
+            this.configurationProvider = configurationProvider;
             this.Console = console;
             this.Viewer = viewer;
             this.settingsViewModelFactory = settingsViewModelFactory;
@@ -50,6 +55,9 @@ namespace SyncTrayzor.Pages
 
             this.syncThingManager.StateChanged += (o, e) => this.SyncThingState = e.NewState;
             this.syncThingManager.ProcessExitedWithError += (o, e) => this.ShowExitedWithError();
+
+            this.ShowConsole = this.configurationProvider.Load().ShowSyncthingConsole;
+            this.Bind(s => s.ShowConsole, (o, e) => this.SetConsoleVisible(e.NewValue));
         }
 
         public bool CanStart
@@ -127,6 +135,11 @@ namespace SyncTrayzor.Pages
             this.windowManager.ShowDialog(vm);
         }
 
+        public void SetConsoleVisible(bool visible)
+        {
+            this.configurationProvider.AtomicLoadAndSave(configuration => configuration.ShowSyncthingConsole = visible);
+        }
+
         public void ShowExitedWithError()
         {
             this.windowManager.ShowMessageBox(

+ 25 - 26
src/SyncTrayzor/Properties/Settings.Designer.cs

@@ -88,24 +88,24 @@ namespace SyncTrayzor.Properties {
         
         [global::System.Configuration.ApplicationScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute(@"
-                    <Configuration xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
-                        <ShowTrayIconOnlyOnClose>false</ShowTrayIconOnlyOnClose>
-                        <MinimizeToTray>false</MinimizeToTray>
-                        <CloseToTray>true</CloseToTray>
-                        <ShowSynchronizedBalloon>true</ShowSynchronizedBalloon>
-                        <ShowDeviceConnectivityBalloons>true</ShowDeviceConnectivityBalloons>
-                        <SyncthingAddress>localhost:8384</SyncthingAddress>
-                        <StartSyncthingAutomatically>true</StartSyncthingAutomatically>
-                        <SyncthingUseCustomHome>true</SyncthingUseCustomHome>
-                        <SyncthingDenyUpgrade>false</SyncthingDenyUpgrade>
-                        <SyncthingRunLowPriority>false</SyncthingRunLowPriority>
-                        <Folders />
-                        <NotifyOfNewVersions>true</NotifyOfNewVersions>
-                        <ObfuscateDeviceIDs>true</ObfuscateDeviceIDs>
-                        <UseComputerCulture>true</UseComputerCulture>
-                    </Configuration>
-                ")]
+        [global::System.Configuration.DefaultSettingValueAttribute(@"<?xml version=""1.0"" encoding=""utf-16""?>
+<Configuration xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
+  <ShowTrayIconOnlyOnClose>false</ShowTrayIconOnlyOnClose>
+  <MinimizeToTray>false</MinimizeToTray>
+  <CloseToTray>true</CloseToTray>
+  <ShowSynchronizedBalloon>true</ShowSynchronizedBalloon>
+  <ShowDeviceConnectivityBalloons>true</ShowDeviceConnectivityBalloons>
+  <SyncthingAddress>localhost:8384</SyncthingAddress>
+  <StartSyncthingAutomatically>true</StartSyncthingAutomatically>
+  <SyncthingUseCustomHome>true</SyncthingUseCustomHome>
+  <SyncthingDenyUpgrade>false</SyncthingDenyUpgrade>
+  <SyncthingRunLowPriority>false</SyncthingRunLowPriority>
+  <Folders />
+  <NotifyOfNewVersions>true</NotifyOfNewVersions>
+  <ObfuscateDeviceIDs>true</ObfuscateDeviceIDs>
+  <UseComputerCulture>true</UseComputerCulture>
+  <ShowSyncthingConsole>true</ShowSyncthingConsole>
+</Configuration>")]
         public global::SyncTrayzor.Services.Config.Configuration DefaultUserConfiguration {
             get {
                 return ((global::SyncTrayzor.Services.Config.Configuration)(this["DefaultUserConfiguration"]));
@@ -114,14 +114,13 @@ namespace SyncTrayzor.Properties {
         
         [global::System.Configuration.ApplicationScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute(@"
-                    <PathConfiguration xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
-                        <LogFilePath>%EXEPATH%\data\logs</LogFilePath>
-                        <SyncthingCustomHomePath>%EXEPATH%\data\syncthing</SyncthingCustomHomePath>
-                        <SyncthingPath>%EXEPATH%\syncthing.exe</SyncthingPath>
-                        <ConfigurationFilePath>%EXEPATH%\data\config.xml</ConfigurationFilePath>
-                    </PathConfiguration>
-                ")]
+        [global::System.Configuration.DefaultSettingValueAttribute(@"<?xml version=""1.0"" encoding=""utf-16""?>
+<PathConfiguration xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
+  <LogFilePath>%EXEPATH%\data\logs</LogFilePath>
+  <SyncthingCustomHomePath>%EXEPATH%\data\syncthing</SyncthingCustomHomePath>
+  <SyncthingPath>%EXEPATH%\syncthing.exe</SyncthingPath>
+  <ConfigurationFilePath>%EXEPATH%\data\config.xml</ConfigurationFilePath>
+</PathConfiguration>")]
         public global::SyncTrayzor.Services.Config.PathConfiguration PathConfiguration {
             get {
                 return ((global::SyncTrayzor.Services.Config.PathConfiguration)(this["PathConfiguration"]));

+ 25 - 26
src/SyncTrayzor/Properties/Settings.settings

@@ -24,34 +24,33 @@
       <Value Profile="(Default)">0</Value>
     </Setting>
     <Setting Name="DefaultUserConfiguration" Type="SyncTrayzor.Services.Config.Configuration" Scope="Application">
-      <Value Profile="(Default)">
-                    &lt;Configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
-                        &lt;ShowTrayIconOnlyOnClose&gt;false&lt;/ShowTrayIconOnlyOnClose&gt;
-                        &lt;MinimizeToTray&gt;false&lt;/MinimizeToTray&gt;
-                        &lt;CloseToTray&gt;true&lt;/CloseToTray&gt;
-                        &lt;ShowSynchronizedBalloon&gt;true&lt;/ShowSynchronizedBalloon&gt;
-                        &lt;ShowDeviceConnectivityBalloons&gt;true&lt;/ShowDeviceConnectivityBalloons&gt;
-                        &lt;SyncthingAddress&gt;localhost:8384&lt;/SyncthingAddress&gt;
-                        &lt;StartSyncthingAutomatically&gt;true&lt;/StartSyncthingAutomatically&gt;
-                        &lt;SyncthingUseCustomHome&gt;true&lt;/SyncthingUseCustomHome&gt;
-                        &lt;SyncthingDenyUpgrade&gt;false&lt;/SyncthingDenyUpgrade&gt;
-                        &lt;SyncthingRunLowPriority&gt;false&lt;/SyncthingRunLowPriority&gt;
-                        &lt;Folders /&gt;
-                        &lt;NotifyOfNewVersions&gt;true&lt;/NotifyOfNewVersions&gt;
-                        &lt;ObfuscateDeviceIDs&gt;true&lt;/ObfuscateDeviceIDs&gt;
-                        &lt;UseComputerCulture&gt;true&lt;/UseComputerCulture&gt;
-                    &lt;/Configuration&gt;
-                </Value>
+      <Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
+&lt;Configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
+  &lt;ShowTrayIconOnlyOnClose&gt;false&lt;/ShowTrayIconOnlyOnClose&gt;
+  &lt;MinimizeToTray&gt;false&lt;/MinimizeToTray&gt;
+  &lt;CloseToTray&gt;true&lt;/CloseToTray&gt;
+  &lt;ShowSynchronizedBalloon&gt;true&lt;/ShowSynchronizedBalloon&gt;
+  &lt;ShowDeviceConnectivityBalloons&gt;true&lt;/ShowDeviceConnectivityBalloons&gt;
+  &lt;SyncthingAddress&gt;localhost:8384&lt;/SyncthingAddress&gt;
+  &lt;StartSyncthingAutomatically&gt;true&lt;/StartSyncthingAutomatically&gt;
+  &lt;SyncthingUseCustomHome&gt;true&lt;/SyncthingUseCustomHome&gt;
+  &lt;SyncthingDenyUpgrade&gt;false&lt;/SyncthingDenyUpgrade&gt;
+  &lt;SyncthingRunLowPriority&gt;false&lt;/SyncthingRunLowPriority&gt;
+  &lt;Folders /&gt;
+  &lt;NotifyOfNewVersions&gt;true&lt;/NotifyOfNewVersions&gt;
+  &lt;ObfuscateDeviceIDs&gt;true&lt;/ObfuscateDeviceIDs&gt;
+  &lt;UseComputerCulture&gt;true&lt;/UseComputerCulture&gt;
+  &lt;ShowSyncthingConsole&gt;true&lt;/ShowSyncthingConsole&gt;
+&lt;/Configuration&gt;</Value>
     </Setting>
     <Setting Name="PathConfiguration" Type="SyncTrayzor.Services.Config.PathConfiguration" Scope="Application">
-      <Value Profile="(Default)">
-                    &lt;PathConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
-                        &lt;LogFilePath&gt;%EXEPATH%\data\logs&lt;/LogFilePath&gt;
-                        &lt;SyncthingCustomHomePath&gt;%EXEPATH%\data\syncthing&lt;/SyncthingCustomHomePath&gt;
-                        &lt;SyncthingPath&gt;%EXEPATH%\syncthing.exe&lt;/SyncthingPath&gt;
-                        &lt;ConfigurationFilePath&gt;%EXEPATH%\data\config.xml&lt;/ConfigurationFilePath&gt;
-                    &lt;/PathConfiguration&gt;
-                </Value>
+      <Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
+&lt;PathConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
+  &lt;LogFilePath&gt;%EXEPATH%\data\logs&lt;/LogFilePath&gt;
+  &lt;SyncthingCustomHomePath&gt;%EXEPATH%\data\syncthing&lt;/SyncthingCustomHomePath&gt;
+  &lt;SyncthingPath&gt;%EXEPATH%\syncthing.exe&lt;/SyncthingPath&gt;
+  &lt;ConfigurationFilePath&gt;%EXEPATH%\data\config.xml&lt;/ConfigurationFilePath&gt;
+&lt;/PathConfiguration&gt;</Value>
     </Setting>
   </Settings>
 </SettingsFile>

+ 18 - 0
src/SyncTrayzor/Properties/Strings/Resources.Designer.cs

@@ -756,6 +756,24 @@ namespace SyncTrayzor.Properties.Strings {
             }
         }
         
+        /// <summary>
+        ///   Looks up a localized string similar to _View.
+        /// </summary>
+        public static string ShellView_Menu_View {
+            get {
+                return ResourceManager.GetString("ShellView_Menu_View", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to Syncthing Console.
+        /// </summary>
+        public static string ShellView_Menu_View_SyncthingConsole {
+            get {
+                return ResourceManager.GetString("ShellView_Menu_View_SyncthingConsole", resourceCulture);
+            }
+        }
+        
         /// <summary>
         ///   Looks up a localized string similar to Description:.
         /// </summary>

+ 6 - 0
src/SyncTrayzor/Properties/Strings/Resources.resx

@@ -537,4 +537,10 @@ SyncTrayzor is going to have to close. Sorry about that</value>
   <data name="SettingsView_UseComputerCulture" xml:space="preserve">
     <value>Use my computer's language, where available. You will need to restart SyncTrayzor for this to take effect</value>
   </data>
+  <data name="ShellView_Menu_View" xml:space="preserve">
+    <value>_View</value>
+  </data>
+  <data name="ShellView_Menu_View_SyncthingConsole" xml:space="preserve">
+    <value>Syncthing Console</value>
+  </data>
 </root>

+ 5 - 2
src/SyncTrayzor/Services/Config/Configuration.cs

@@ -65,6 +65,7 @@ namespace SyncTrayzor.Services.Config
         }
 
         public bool UseComputerCulture { get; set; }
+        public bool ShowSyncthingConsole { get; set; }
 
         public Configuration()
         {
@@ -87,6 +88,7 @@ namespace SyncTrayzor.Services.Config
             this.ObfuscateDeviceIDs = true;
             this.LatestNotifiedVersion = null;
             this.UseComputerCulture = true;
+            this.ShowSyncthingConsole = true;
         }
 
         public Configuration(Configuration other)
@@ -108,6 +110,7 @@ namespace SyncTrayzor.Services.Config
             this.ObfuscateDeviceIDs = other.ObfuscateDeviceIDs;
             this.LatestNotifiedVersion = other.LatestNotifiedVersion;
             this.UseComputerCulture = other.UseComputerCulture;
+            this.ShowSyncthingConsole = other.ShowSyncthingConsole;
         }
 
         public override string ToString()
@@ -115,11 +118,11 @@ namespace SyncTrayzor.Services.Config
             return String.Format("<Configuration ShowTrayIconOnlyOnClose={0} MinimizeToTray={1} CloseToTray={2} ShowSynchronizedBalloon={3} " +
                 "ShowDeviceConnectivityBalloons={4} SyncthingAddress={5} StartSyncthingAutomatically={6} SyncthingApiKey={7} SyncthingTraceFacilities={8} " +
                 "SyncthingUseCustomHome={9} SyncthingDenyUpgrade={10} SyncthingRunLowPriority={11} Folders=[{12}] NotifyOfNewVersions={13} " +
-                "LastNotifiedVersion={14} ObfuscateDeviceIDs={15} UseComputerCulture={16}>",
+                "LastNotifiedVersion={14} ObfuscateDeviceIDs={15} UseComputerCulture={16} ShowSyncthingConsole={17}>",
                 this.ShowTrayIconOnlyOnClose, this.MinimizeToTray, this.CloseToTray, this.ShowSynchronizedBalloon, this.ShowDeviceConnectivityBalloons,
                 this.SyncthingAddress, this.StartSyncthingAutomatically, this.SyncthingApiKey, this.SyncthingTraceFacilities,
                 this.SyncthingUseCustomHome, this.SyncthingDenyUpgrade, this.SyncthingRunLowPriority, String.Join(", ", this.Folders),
-                this.NotifyOfNewVersions, this.LatestNotifiedVersion, this.ObfuscateDeviceIDs, this.UseComputerCulture);
+                this.NotifyOfNewVersions, this.LatestNotifiedVersion, this.ObfuscateDeviceIDs, this.UseComputerCulture, this.ShowSyncthingConsole);
         }
     }
 }

+ 14 - 0
src/SyncTrayzor/Services/Config/ConfigurationProvider.cs

@@ -41,6 +41,7 @@ namespace SyncTrayzor.Services.Config
         void Initialize(PathConfiguration pathConfiguration, Configuration defaultConfiguration);
         Configuration Load();
         void Save(Configuration config);
+        void AtomicLoadAndSave(Action<Configuration> setter);
     }
 
     public class ConfigurationProvider : IConfigurationProvider
@@ -219,6 +220,19 @@ namespace SyncTrayzor.Services.Config
             this.OnConfigurationChanged(config);
         }
 
+        public void AtomicLoadAndSave(Action<Configuration> setter)
+        {
+            // We can just let them modify the current config here - since it's all inside the lock
+            Configuration newConfig;
+            lock (this.currentConfigLock)
+            {
+                setter(this.currentConfig);
+                this.SaveToFile(this.currentConfig);
+                newConfig = this.currentConfig;
+            }
+            this.OnConfigurationChanged(newConfig);
+        }
+
         private void SaveToFile(Configuration config)
         {
             using (var stream = File.Open(this.ConfigurationFilePath, FileMode.Create))

+ 1 - 0
src/SyncTrayzor/SyncTrayzor.csproj

@@ -215,6 +215,7 @@
     <Compile Include="Utils\SemaphoreSlimExtensions.cs" />
     <Compile Include="Utils\SynchronizedEventDispatcher.cs" />
     <Compile Include="Utils\UriExtensions.cs" />
+    <Compile Include="Xaml\CollapsingRowDefinitionBehaviour.cs" />
     <Compile Include="Xaml\DetachingBehaviour.cs" />
     <Compile Include="Xaml\LogMessageListToStringConverter.cs" />
     <Compile Include="Xaml\ScrollToEndBehaviour.cs" />

+ 60 - 0
src/SyncTrayzor/Xaml/CollapsingRowDefinitionBehaviour.cs

@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Interactivity;
+
+namespace SyncTrayzor.Xaml
+{
+    public class CollapsingRowDefinitionBehaviour : Behavior<RowDefinition>
+    {
+        public GridLength Height
+        {
+            get { return (GridLength)GetValue(HeightProperty); }
+            set { SetValue(HeightProperty, value); }
+        }
+        public static readonly DependencyProperty HeightProperty =
+            DependencyProperty.Register("Height", typeof(GridLength), typeof(CollapsingRowDefinitionBehaviour), new PropertyMetadata(GridLength.Auto));
+
+        public double MinHeight
+        {
+            get { return (double)GetValue(MinHeightProperty); }
+            set { SetValue(MinHeightProperty, value); }
+        }
+        public static readonly DependencyProperty MinHeightProperty =
+            DependencyProperty.Register("MinHeight", typeof(double), typeof(CollapsingRowDefinitionBehaviour), new PropertyMetadata(0.0));
+
+        public Visibility RowVisibility
+        {
+            get { return (Visibility)GetValue(RowVisibilityProperty); }
+            set { SetValue(RowVisibilityProperty, value); }
+        }
+        public static readonly DependencyProperty RowVisibilityProperty =
+            DependencyProperty.Register("RowVisibility", typeof(Visibility), typeof(CollapsingRowDefinitionBehaviour), new PropertyMetadata(Visibility.Visible, (d, e) =>
+            {
+                ((CollapsingRowDefinitionBehaviour)d).Refresh();
+            }));
+
+        protected override void OnAttached()
+        {
+            this.Refresh();
+        }
+
+        private void Refresh()
+        {
+            if (this.RowVisibility == Visibility.Collapsed)
+            {
+                this.AssociatedObject.Height = new GridLength(0);
+                this.AssociatedObject.MinHeight = 0;
+            }
+            else
+            {
+                this.AssociatedObject.Height = this.Height;
+                this.AssociatedObject.MinHeight = this.MinHeight;
+            }
+        }
+    }
+}