Sfoglia il codice sorgente

Add option to run Syncthing as a low-priority process

Fixes #24
Antony Male 10 anni fa
parent
commit
fdfc41ce0d

+ 2 - 0
.gitattributes

@@ -3,3 +3,5 @@
 *.sln		eol=crlf
 *.csproj	eol=crlf
 *.resx 		eol=crlf
+*.settings 	eol=crlf
+*.config	eol=crlf

+ 2 - 1
src/SyncTrayzor/App.config

@@ -42,8 +42,9 @@
                         <ShowDeviceConnectivityBalloons>true</ShowDeviceConnectivityBalloons>
                         <SyncthingAddress>http://localhost:8384</SyncthingAddress>
                         <StartSyncthingAutomatically>true</StartSyncthingAutomatically>
-                        <SyncthingUseCustomHome>false</SyncthingUseCustomHome>
+                        <SyncthingUseCustomHome xsi:nil="true" />
                         <SyncthingDenyUpgrade>false</SyncthingDenyUpgrade>
+                        <SyncthingRunLowPriority>false</SyncthingRunLowPriority>
                         <Folders />
                         <NotifyOfNewVersions>true</NotifyOfNewVersions>
                         <ObfuscateDeviceIDs>true</ObfuscateDeviceIDs>

+ 1 - 0
src/SyncTrayzor/Pages/SettingsView.xaml

@@ -82,6 +82,7 @@
                             </DockPanel.Resources>
 
                             <CheckBox DockPanel.Dock="Top" IsChecked="{Binding StartSyncThingAutomatically}" Content="{l:Loc SettingsView_StartSyncthingAutomatically}"/>
+                            <CheckBox DockPanel.Dock="Top" IsChecked="{Binding SyncthingRunLowPriority}" Content="{l:Loc SettingsView_SyncthingRunLowPriority}"/>
 
                             <Label DockPanel.Dock="Top" Target="{Binding ElementName=SyncThingAddress}" Content="{l:Loc SettingsView_SyncthingAddress}" ToolTip="{StaticResource AddressOverride}"/>
                             <TextBox DockPanel.Dock="Top" x:Name="SyncThingAddress" ToolTip="{StaticResource AddressOverride}" Text="{Binding SyncThingAddress, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,40,0"/>

+ 3 - 0
src/SyncTrayzor/Pages/SettingsViewModel.cs

@@ -50,6 +50,7 @@ namespace SyncTrayzor.Pages
         public bool ShowDeviceConnectivityBalloons { get; set; }
 
         public bool StartSyncThingAutomatically { get; set; }
+        public bool SyncthingRunLowPriority { get; set; }
         public string SyncThingAddress { get; set; }
         public string SyncThingApiKey { get; set; }
 
@@ -97,6 +98,7 @@ namespace SyncTrayzor.Pages
             this.ShowDeviceConnectivityBalloons = configuration.ShowDeviceConnectivityBalloons;
 
             this.StartSyncThingAutomatically = configuration.StartSyncthingAutomatically;
+            this.SyncthingRunLowPriority = configuration.SyncthingRunLowPriority;
             this.SyncThingAddress = configuration.SyncthingAddress;
             this.SyncThingApiKey = configuration.SyncthingApiKey;
 
@@ -143,6 +145,7 @@ namespace SyncTrayzor.Pages
             configuration.ShowDeviceConnectivityBalloons = this.ShowDeviceConnectivityBalloons;
 
             configuration.StartSyncthingAutomatically = this.StartSyncThingAutomatically;
+            configuration.SyncthingRunLowPriority = this.SyncthingRunLowPriority;
             configuration.SyncthingAddress = this.SyncThingAddress;
             configuration.SyncthingApiKey = this.SyncThingApiKey;
 

+ 3 - 2
src/SyncTrayzor/Properties/Settings.Designer.cs

@@ -1,7 +1,7 @@
 //------------------------------------------------------------------------------
 // <auto-generated>
 //     This code was generated by a tool.
-//     Runtime Version:4.0.30319.0
+//     Runtime Version:4.0.30319.18444
 //
 //     Changes to this file may cause incorrect behavior and will be lost if
 //     the code is regenerated.
@@ -88,8 +88,9 @@ namespace SyncTrayzor.Properties {
   <ShowDeviceConnectivityBalloons>true</ShowDeviceConnectivityBalloons>
   <SyncthingAddress>http://localhost:8384</SyncthingAddress>
   <StartSyncthingAutomatically>true</StartSyncthingAutomatically>
-  <SyncthingUseCustomHome>false</SyncthingUseCustomHome>
+  <SyncthingUseCustomHome xsi:nil=""true"" />
   <SyncthingDenyUpgrade>false</SyncthingDenyUpgrade>
+  <SyncthingRunLowPriority>false</SyncthingRunLowPriority>
   <Folders />
   <NotifyOfNewVersions>true</NotifyOfNewVersions>
   <ObfuscateDeviceIDs>true</ObfuscateDeviceIDs>

+ 2 - 1
src/SyncTrayzor/Properties/Settings.settings

@@ -30,8 +30,9 @@
   &lt;ShowDeviceConnectivityBalloons&gt;true&lt;/ShowDeviceConnectivityBalloons&gt;
   &lt;SyncthingAddress&gt;http://localhost:8384&lt;/SyncthingAddress&gt;
   &lt;StartSyncthingAutomatically&gt;true&lt;/StartSyncthingAutomatically&gt;
-  &lt;SyncthingUseCustomHome&gt;false&lt;/SyncthingUseCustomHome&gt;
+  &lt;SyncthingUseCustomHome xsi:nil="true" /&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;

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

@@ -531,6 +531,15 @@ namespace SyncTrayzor.Properties.Strings {
             }
         }
         
+        /// <summary>
+        ///   Looks up a localized string similar to Run Syncthing as a low-priority process.
+        /// </summary>
+        public static string SettingsView_SyncthingRunLowPriority {
+            get {
+                return ResourceManager.GetString("SettingsView_SyncthingRunLowPriority", resourceCulture);
+            }
+        }
+        
         /// <summary>
         ///   Looks up a localized string similar to Use custom home directory for Syncthing..
         /// </summary>

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

@@ -519,6 +519,9 @@ SyncTrayzor is going to have to close. Sorry about that</value>
   <data name="SettingsView_SyncthingDenyUpgrade_ToolTip" xml:space="preserve">
     <value>Stop Syncthing from auto-upgrading. This is useful if a new version of Syncthing breaks compatibility with SyncTrayzor. You will need to downgrade the syncthing.exe file in SyncTrayzor's config folder</value>
   </data>
+  <data name="SettingsView_SyncthingRunLowPriority" xml:space="preserve">
+    <value>Run Syncthing as a low-priority process</value>
+  </data>
   <data name="TrayIcon_Menu_OpenFolder" xml:space="preserve">
     <value>_Open Folder</value>
     <comment>Menu option available when right-clicking the tray icon. Is a header for a list of folders, each of which can be clicked to open it in Explorer</comment>

+ 7 - 4
src/SyncTrayzor/Services/Configuration.cs

@@ -58,6 +58,7 @@ namespace SyncTrayzor.Services
         public bool? SyncthingUseCustomHomeRaw { get; set; }
         
         public bool SyncthingDenyUpgrade { get; set; }
+        public bool SyncthingRunLowPriority { get; set; }
         [XmlArrayItem("Folder")]
         public List<FolderConfiguration> Folders { get; set; }
         public bool NotifyOfNewVersions { get; set; }
@@ -85,6 +86,7 @@ namespace SyncTrayzor.Services
             this.SyncthingTraceFacilities = null;
             this.SyncthingUseCustomHomeRaw = null;
             this.SyncthingDenyUpgrade = false;
+            this.SyncthingRunLowPriority = false;
             this.Folders = new List<FolderConfiguration>();
             this.NotifyOfNewVersions = true;
             this.ObfuscateDeviceIDs = true;
@@ -104,6 +106,7 @@ namespace SyncTrayzor.Services
             this.SyncthingTraceFacilities = other.SyncthingTraceFacilities;
             this.SyncthingUseCustomHome = other.SyncthingUseCustomHome;
             this.SyncthingDenyUpgrade = other.SyncthingDenyUpgrade;
+            this.SyncthingRunLowPriority = other.SyncthingRunLowPriority;
             this.Folders = other.Folders.Select(x => new FolderConfiguration(x)).ToList();
             this.NotifyOfNewVersions = other.NotifyOfNewVersions;
             this.ObfuscateDeviceIDs = other.ObfuscateDeviceIDs;
@@ -114,12 +117,12 @@ namespace SyncTrayzor.Services
         {
             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} Folders=[{11}] NotifyOfNewVersions={12} LastNotifiedVersion={13} " +
-                "ObfuscateDeviceIDs={14}>",
+                "SyncthingUseCustomHome={9} SyncthingDenyUpgrade={10} SyncthingRunLowPriority={11} Folders=[{12}] NotifyOfNewVersions={13} " +
+                "LastNotifiedVersion={14} ObfuscateDeviceIDs={15}>",
                 this.ShowTrayIconOnlyOnClose, this.MinimizeToTray, this.CloseToTray, this.ShowSynchronizedBalloon, this.ShowDeviceConnectivityBalloons,
                 this.SyncthingAddress, this.StartSyncthingAutomatically, this.SyncthingApiKey, this.SyncthingTraceFacilities,
-                this.SyncthingUseCustomHome, this.SyncthingDenyUpgrade, String.Join(", ", this.Folders), this.NotifyOfNewVersions,
-                this.LatestNotifiedVersion, this.ObfuscateDeviceIDs);
+                this.SyncthingUseCustomHome, this.SyncthingDenyUpgrade, this.SyncthingRunLowPriority, String.Join(", ", this.Folders),
+                this.NotifyOfNewVersions, this.LatestNotifiedVersion, this.ObfuscateDeviceIDs);
         }
     }
 }

+ 1 - 0
src/SyncTrayzor/Services/ConfigurationApplicator.cs

@@ -72,6 +72,7 @@ namespace SyncTrayzor.Services
             this.syncThingManager.SyncthingTraceFacilities = configuration.SyncthingTraceFacilities;
             this.syncThingManager.SyncthingCustomHomeDir = configuration.SyncthingUseCustomHome ? this.configurationProvider.SyncthingCustomHomePath : null;
             this.syncThingManager.SyncthingDenyUpgrade = configuration.SyncthingDenyUpgrade;
+            this.syncThingManager.SyncthingRunLowPriority = configuration.SyncthingRunLowPriority;
 
             this.watchedFolderMonitor.WatchedFolderIDs = configuration.Folders.Where(x => x.IsWatched).Select(x => x.ID);
 

+ 3 - 0
src/SyncTrayzor/SyncThing/SyncThingManager.cs

@@ -35,6 +35,7 @@ namespace SyncTrayzor.SyncThing
         string SyncthingTraceFacilities { get; set; }
         string SyncthingCustomHomeDir { get; set; }
         bool SyncthingDenyUpgrade { get; set; }
+        bool SyncthingRunLowPriority { get; set; }
         DateTime StartedTime { get; }
         DateTime LastConnectivityEventTime { get; }
         SyncthingVersion Version { get; }
@@ -114,6 +115,7 @@ namespace SyncTrayzor.SyncThing
         public string SyncthingCustomHomeDir { get; set; }
         public string SyncthingTraceFacilities { get; set; }
         public bool SyncthingDenyUpgrade { get; set; }
+        public bool SyncthingRunLowPriority { get; set; }
 
         // Folders is a ConcurrentDictionary, which suffices for most access
         // However, it is sometimes set outright (in the case of an initial load or refresh), so we need this lock
@@ -164,6 +166,7 @@ namespace SyncTrayzor.SyncThing
                 this.processRunner.CustomHomeDir = this.SyncthingCustomHomeDir;
                 this.processRunner.Traces = this.SyncthingTraceFacilities;
                 this.processRunner.DenyUpgrade = this.SyncthingDenyUpgrade;
+                this.processRunner.RunLowPriority = this.SyncthingRunLowPriority;
 
                 this.SetState(SyncThingState.Starting);
             };

+ 5 - 0
src/SyncTrayzor/SyncThing/SyncThingProcessRunner.cs

@@ -40,6 +40,7 @@ namespace SyncTrayzor.SyncThing
         string CustomHomeDir { get; set; }
         string Traces { get; set; }
         bool DenyUpgrade { get; set; }
+        bool RunLowPriority { get; set; }
 
         event EventHandler Starting;
         event EventHandler<MessageLoggedEventArgs> MessageLogged;
@@ -64,6 +65,7 @@ namespace SyncTrayzor.SyncThing
         public string CustomHomeDir { get; set; }
         public string Traces { get; set; }
         public bool DenyUpgrade { get; set; }
+        public bool RunLowPriority { get; set; }
 
         public event EventHandler Starting;
         public event EventHandler<MessageLoggedEventArgs> MessageLogged;
@@ -105,6 +107,9 @@ namespace SyncTrayzor.SyncThing
 
                 this.process = Process.Start(processStartInfo);
 
+                if (this.RunLowPriority)
+                    this.process.PriorityClass = ProcessPriorityClass.BelowNormal;
+
                 this.process.EnableRaisingEvents = true;
                 this.process.OutputDataReceived += (o, e) => this.DataReceived(e.Data);
                 this.process.ErrorDataReceived += (o, e) => this.DataReceived(e.Data);