├── .editorconfig
├── redshift-tray
├── redshift-tray.ico
├── Resources
│ ├── AboutIcon.png
│ ├── TrayIconAuto.ico
│ └── TrayIconOff.ico
├── packages.config
├── App.xaml
├── App.xaml.cs
├── DebugConsole.xaml
├── Settings.cs
├── About.xaml.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Settings.settings
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ └── Settings.Designer.cs
├── DebugConsole.xaml.cs
├── App.config
├── About.xaml
├── TrayIcon.cs
├── Main.cs
├── Common.cs
├── redshift-tray.csproj
├── SettingsWindow.xaml
├── redshift.cs
└── SettingsWindow.xaml.cs
├── extend_windows_temperature_range.reg
├── .gitignore
├── redshift-tray.Test
├── CommonTests.cs
├── Properties
│ └── AssemblyInfo.cs
└── redshift-tray.Test.csproj
├── readme.md
├── LICENSE.txt
└── redshift-tray.sln
/.editorconfig:
--------------------------------------------------------------------------------
1 | # 2 space indentation
2 | [*.cs]
3 | indent_style = space
4 | indent_size = 2
--------------------------------------------------------------------------------
/redshift-tray/redshift-tray.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nepochal/redshift-tray/HEAD/redshift-tray/redshift-tray.ico
--------------------------------------------------------------------------------
/redshift-tray/Resources/AboutIcon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nepochal/redshift-tray/HEAD/redshift-tray/Resources/AboutIcon.png
--------------------------------------------------------------------------------
/redshift-tray/Resources/TrayIconAuto.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nepochal/redshift-tray/HEAD/redshift-tray/Resources/TrayIconAuto.ico
--------------------------------------------------------------------------------
/redshift-tray/Resources/TrayIconOff.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nepochal/redshift-tray/HEAD/redshift-tray/Resources/TrayIconOff.ico
--------------------------------------------------------------------------------
/extend_windows_temperature_range.reg:
--------------------------------------------------------------------------------
1 | Windows Registry Editor Version 5.00
2 |
3 | [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ICM]
4 | "GdiIcmGammaRange"=dword:00000100
--------------------------------------------------------------------------------
/redshift-tray/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #ignore thumbnails created by windows
2 | Thumbs.db
3 | #Ignore files build by Visual Studio
4 | *.obj
5 | *.exe
6 | *.pdb
7 | *.user
8 | *.aps
9 | *.pch
10 | *.vspscc
11 | *_i.c
12 | *_p.c
13 | *.ncb
14 | *.suo
15 | *.tlb
16 | *.tlh
17 | *.bak
18 | *.cache
19 | *.ilk
20 | *.log
21 | [Bb]in
22 | [Dd]ebug*/
23 | *.lib
24 | *.sbr
25 | obj/
26 | [Rr]elease*/
27 | _ReSharper*/
28 | [Tt]est[Rr]esult*
29 | /packages
30 |
--------------------------------------------------------------------------------
/redshift-tray/App.xaml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/redshift-tray.Test/CommonTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
3 |
4 | namespace redshift_tray.Test
5 | {
6 | [TestClass]
7 | public class CommonTests
8 | {
9 | [TestMethod]
10 | public void LocationCanBeParsed()
11 | {
12 | AutoLocation autoLocation = Common.ParseLocation("50.8476", "4.3428");
13 | Assert.AreEqual(50.8476M, autoLocation.Latitude);
14 | Assert.AreEqual(4.3428M, autoLocation.Longitude);
15 | }
16 |
17 | [TestMethod]
18 | public void LocationCanBeDetermined()
19 | {
20 | AutoLocation autoLocation = Common.DetectLocation();
21 | Assert.IsTrue(autoLocation.Success);
22 | }
23 |
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | Redshift Tray
2 | =============
3 | Redshift Tray is a convenient tool for configuring and using [Redshift](http://jonls.dk/redshift/) on Windows. It completely works in the background and is controllable through a tray icon.
4 |
5 | ---
6 |
7 | **How to install and configure**
8 |
9 | 1. Download the [latest version](https://github.com/Nepochal/redshift-tray/releases) from the release page
10 | 2. Unzip the file
11 | 3. Download [Redshift](https://github.com/jonls/redshift/releases)
12 | 4. Start the program and fill in the redshift.exe in the settings dialog
13 |
14 | ---
15 |
16 | **How to build**
17 |
18 | Use Microsoft Visual Studio 2013 or above to load the project. You should be able to compile the sources without additional dependencies.
--------------------------------------------------------------------------------
/redshift-tray/App.xaml.cs:
--------------------------------------------------------------------------------
1 | /* This file is part of redshift-tray.
2 | Copyright (c) Michael Scholz
3 | */
4 | using System.Diagnostics;
5 | using System.Linq;
6 | using System.Windows;
7 |
8 | namespace redshift_tray
9 | {
10 | public partial class App : Application
11 | {
12 |
13 | void Main(object sender, StartupEventArgs e)
14 | {
15 | if(Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Count() > 1)
16 | {
17 | Application.Current.Shutdown(0);
18 | }
19 | else
20 | {
21 | bool dummyMethod = e.Args.Any(arg => (arg.ToLower() == "/dummy"));
22 | Main main = new Main(dummyMethod);
23 |
24 | if(!main.Initialize())
25 | {
26 | Application.Current.Shutdown(-1);
27 | }
28 | }
29 | }
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/redshift-tray/DebugConsole.xaml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Michael Scholz (Nepochal)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/redshift-tray/Settings.cs:
--------------------------------------------------------------------------------
1 | namespace redshift_tray.Properties {
2 |
3 |
4 | // Diese Klasse ermöglicht die Behandlung bestimmter Ereignisse der Einstellungsklasse:
5 | // Das SettingChanging-Ereignis wird ausgelöst, bevor der Wert einer Einstellung geändert wird.
6 | // Das PropertyChanged-Ereignis wird ausgelöst, nachdem der Wert einer Einstellung geändert wurde.
7 | // Das SettingsLoaded-Ereignis wird ausgelöst, nachdem die Einstellungswerte geladen wurden.
8 | // Das SettingsSaving-Ereignis wird ausgelöst, bevor die Einstellungswerte gespeichert werden.
9 | internal sealed partial class Settings {
10 |
11 | public Settings() {
12 | // // Heben Sie die Auskommentierung der unten angezeigten Zeilen auf, um Ereignishandler zum Speichern und Ändern von Einstellungen hinzuzufügen:
13 | //
14 | // this.SettingChanging += this.SettingChangingEventHandler;
15 | //
16 | // this.SettingsSaving += this.SettingsSavingEventHandler;
17 | //
18 | }
19 |
20 | private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
21 | // Fügen Sie hier Code zum Behandeln des SettingChangingEvent-Ereignisses hinzu.
22 | }
23 |
24 | private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
25 | // Fügen Sie hier Code zum Behandeln des SettingsSaving-Ereignisses hinzu.
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/redshift-tray.Test/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("redshift-tray.Test")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("redshift-tray.Test")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("ce4499d3-8240-40fe-a283-dc20eeb2006a")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/redshift-tray.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "redshift-tray", "redshift-tray\redshift-tray.csproj", "{86F28B6B-3141-4010-96CD-43AA7E0E0ABD}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "redshift-tray.Test", "redshift-tray.Test\redshift-tray.Test.csproj", "{CE4499D3-8240-40FE-A283-DC20EEB2006A}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {86F28B6B-3141-4010-96CD-43AA7E0E0ABD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {86F28B6B-3141-4010-96CD-43AA7E0E0ABD}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {86F28B6B-3141-4010-96CD-43AA7E0E0ABD}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {86F28B6B-3141-4010-96CD-43AA7E0E0ABD}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {CE4499D3-8240-40FE-A283-DC20EEB2006A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {CE4499D3-8240-40FE-A283-DC20EEB2006A}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {CE4499D3-8240-40FE-A283-DC20EEB2006A}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {CE4499D3-8240-40FE-A283-DC20EEB2006A}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/redshift-tray/About.xaml.cs:
--------------------------------------------------------------------------------
1 | /* This file is part of redshift-tray.
2 | Copyright (c) Michael Scholz
3 | */
4 | using redshift_tray.Properties;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Diagnostics;
8 | using System.Linq;
9 | using System.Text;
10 | using System.Threading.Tasks;
11 | using System.Windows;
12 | using System.Windows.Controls;
13 | using System.Windows.Data;
14 | using System.Windows.Documents;
15 | using System.Windows.Input;
16 | using System.Windows.Media;
17 | using System.Windows.Media.Imaging;
18 | using System.Windows.Shapes;
19 |
20 | namespace redshift_tray
21 | {
22 | public partial class About : Window
23 | {
24 |
25 | private string VersionText
26 | {
27 | set { Version.Text = string.Format("Version: {0}", value); }
28 | }
29 |
30 | public About()
31 | {
32 | InitializeComponent();
33 | LoadPosition();
34 | VersionText = Main.VERSION;
35 | }
36 |
37 | private void SavePosition()
38 | {
39 | Settings settings = Settings.Default;
40 |
41 | settings.AboutLeft = this.Left;
42 | settings.AboutTop = this.Top;
43 |
44 | settings.Save();
45 | }
46 |
47 | private void LoadPosition()
48 | {
49 | Settings settings = Settings.Default;
50 |
51 | if(Common.isOutOfBounds(settings.AboutLeft, settings.AboutTop))
52 | {
53 | return;
54 | }
55 |
56 | this.WindowStartupLocation = WindowStartupLocation.Manual;
57 | this.Left = settings.AboutLeft;
58 | this.Top = settings.AboutTop;
59 | }
60 |
61 | private void RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
62 | {
63 | Process.Start(e.Uri.ToString());
64 | }
65 |
66 | private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
67 | {
68 | SavePosition();
69 | }
70 |
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/redshift-tray/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // Allgemeine Informationen über eine Assembly werden über die folgenden
8 | // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
9 | // die mit einer Assembly verknüpft sind.
10 | [assembly: AssemblyTitle("Redshift Tray")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("mischolz.de")]
14 | [assembly: AssemblyProduct("Redshift Tray")]
15 | [assembly: AssemblyCopyright("Copyright © Michael Scholz 2017")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
20 | // für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
21 | // COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest.
22 | [assembly: ComVisible(false)]
23 |
24 | //Um mit dem Erstellen lokalisierbarer Anwendungen zu beginnen, legen Sie
25 | //ImCodeVerwendeteKultur in der .csproj-Datei
26 | //in einer fest. Wenn Sie in den Quelldateien beispielsweise Deutsch
27 | //(Deutschland) verwenden, legen Sie auf \"de-DE\" fest. Heben Sie dann die Auskommentierung
28 | //des nachstehenden NeutralResourceLanguage-Attributs auf. Aktualisieren Sie "en-US" in der nachstehenden Zeile,
29 | //sodass es mit der UICulture-Einstellung in der Projektdatei übereinstimmt.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //Speicherort der designspezifischen Ressourcenwörterbücher
36 | //(wird verwendet, wenn eine Ressource auf der Seite
37 | // oder in den Anwendungsressourcen-Wörterbüchern nicht gefunden werden kann.)
38 | ResourceDictionaryLocation.SourceAssembly //Speicherort des generischen Ressourcenwörterbuchs
39 | //(wird verwendet, wenn eine Ressource auf der Seite, in der Anwendung oder einem
40 | // designspezifischen Ressourcenwörterbuch nicht gefunden werden kann.)
41 | )]
42 |
43 |
44 | // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
45 | //
46 | // Hauptversion
47 | // Nebenversion
48 | // Buildnummer
49 | // Revision
50 | //
51 | // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
52 | // übernehmen, indem Sie "*" eingeben:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0")]
55 | //[assembly: AssemblyFileVersion("1.0.0.0")]
56 | [assembly: InternalsVisibleTo("redshift-tray.Test")]
--------------------------------------------------------------------------------
/redshift-tray/DebugConsole.xaml.cs:
--------------------------------------------------------------------------------
1 | /* This file is part of redshift-tray.
2 | Copyright (c) Michael Scholz
3 | */
4 | using redshift_tray.Properties;
5 | using System;
6 | using System.Windows;
7 |
8 | namespace redshift_tray
9 | {
10 | public partial class DebugConsole : Window
11 | {
12 | private bool isShown = false;
13 |
14 | public DebugConsole()
15 | {
16 | InitializeComponent();
17 | LoadPosition();
18 | }
19 |
20 | private void SavePosition()
21 | {
22 | Settings settings = Settings.Default;
23 |
24 | if(this.WindowState == WindowState.Maximized)
25 | {
26 | settings.DebugConsoleWindowState = this.WindowState;
27 | }
28 | else
29 | {
30 | settings.DebugConsoleLeft = this.Left;
31 | settings.DebugConsoleTop = this.Top;
32 | settings.DebugConsoleWidth = this.Width;
33 | settings.DebugConsoleHeight = this.Height;
34 | }
35 | settings.Save();
36 | }
37 |
38 | private void LoadPosition()
39 | {
40 | Settings settings = Settings.Default;
41 |
42 | if(Common.isOutOfBounds(settings.DebugConsoleLeft, settings.DebugConsoleTop))
43 | {
44 | return;
45 | }
46 |
47 | this.WindowStartupLocation = WindowStartupLocation.Manual;
48 |
49 | if(settings.DebugConsoleWindowState == WindowState.Maximized)
50 | {
51 | this.WindowState = settings.DebugConsoleWindowState;
52 | return;
53 | }
54 |
55 | this.Left = settings.DebugConsoleLeft;
56 | this.Top = settings.DebugConsoleTop;
57 | this.Width = settings.DebugConsoleWidth;
58 | this.Height = settings.DebugConsoleHeight;
59 | }
60 |
61 | public void ShowOrUnhide()
62 | {
63 | if(isShown)
64 | {
65 | Visibility = System.Windows.Visibility.Visible;
66 | }
67 | else
68 | {
69 | Show();
70 | isShown = true;
71 | }
72 | }
73 |
74 | public new void Hide()
75 | {
76 | Visibility = System.Windows.Visibility.Hidden;
77 | }
78 |
79 | private void ButtonClipboard_Click(object sender, RoutedEventArgs e)
80 | {
81 | Clipboard.SetText(Output.Text);
82 | }
83 |
84 | private void ButtonClose_Click(object sender, RoutedEventArgs e)
85 | {
86 | Close();
87 | }
88 |
89 | private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
90 | {
91 | Hide();
92 | SavePosition();
93 | e.Cancel = true;
94 | }
95 |
96 | public void WriteLog(string message, LogType logType)
97 | {
98 | if(message.Length == 0)
99 | {
100 | return;
101 | }
102 |
103 | Output.Dispatcher.Invoke(() =>
104 | {
105 | string log = string.Format("{0} {1}: {2}", DateTime.Now.ToString("HH:mm:ss"), logType.ToString(), message);
106 | Output.Text += log + Environment.NewLine;
107 | });
108 | }
109 |
110 | private void Output_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
111 | {
112 | Output.ScrollToEnd();
113 | }
114 |
115 | public enum LogType
116 | {
117 | Info,
118 | Error,
119 | Redshift
120 | }
121 |
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/redshift-tray/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | 0
10 |
11 |
12 | 0
13 |
14 |
15 | 5500
16 |
17 |
18 | 3500
19 |
20 |
21 | True
22 |
23 |
24 | -10000
25 |
26 |
27 | -10000
28 |
29 |
30 | -10000
31 |
32 |
33 | -10000
34 |
35 |
36 | Normal
37 |
38 |
39 | -10000
40 |
41 |
42 | -10000
43 |
44 |
45 | -10000
46 |
47 |
48 | -10000
49 |
50 |
51 | True
52 |
53 |
54 | 1
55 |
56 |
57 | 1
58 |
59 |
60 | 1
61 |
62 |
63 | 1
64 |
65 |
66 | 1
67 |
68 |
69 | False
70 |
71 |
72 |
--------------------------------------------------------------------------------
/redshift-tray/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | 0
18 |
19 |
20 | 0
21 |
22 |
23 | 5500
24 |
25 |
26 | 3500
27 |
28 |
29 | True
30 |
31 |
32 | -10000
33 |
34 |
35 | -10000
36 |
37 |
38 | -10000
39 |
40 |
41 | -10000
42 |
43 |
44 | Normal
45 |
46 |
47 | -10000
48 |
49 |
50 | -10000
51 |
52 |
53 | -10000
54 |
55 |
56 | -10000
57 |
58 |
59 | True
60 |
61 |
62 | 1
63 |
64 |
65 | 1
66 |
67 |
68 | 1
69 |
70 |
71 | 1
72 |
73 |
74 | 1
75 |
76 |
77 | False
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/redshift-tray/About.xaml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | Redshift Tray
14 |
15 | © 2016-2017 by Michael Scholz
16 | https://mischolz.de
17 |
18 | Redshift tray is licensed under the MIT.
19 | The source code can be found on GitHub.
20 | Please use the issues system on GitHub to report bugs.
21 |
22 |
23 |
24 |
25 |
26 |
27 | Icons
28 | Most icons are part of the redshift project.
29 | © 2009-2017 by Jon Lund Steffensen
30 | Redshift is licensed under the GPLv3.
31 | Website | Sources
32 |
33 | Redshift
34 | © 2009-2017 by Jon Lund Steffensen
35 | Redshift is licensed under the GPLv3.
36 | Website | Sources
37 |
38 | WPF NotifyIcon
39 | © 2009-2017 by Philipp Sumi
40 | Website | Sources
41 |
42 | Extended WPF Toolkit
43 | © 2007-2017 Xceed Software Inc.
44 | Extended WPF Toolkit is licensed under the Ms-PL.
45 | Website | Sources
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/redshift-tray/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // Dieser Code wurde von einem Tool generiert.
4 | // Laufzeitversion:4.0.30319.42000
5 | //
6 | // Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
7 | // der Code erneut generiert wird.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace redshift_tray.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
17 | ///
18 | // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert
19 | // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert.
20 | // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen
21 | // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("redshift_tray.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
51 | /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Bitmap.
65 | ///
66 | internal static System.Drawing.Bitmap AboutIcon {
67 | get {
68 | object obj = ResourceManager.GetObject("AboutIcon", resourceCulture);
69 | return ((System.Drawing.Bitmap)(obj));
70 | }
71 | }
72 |
73 | ///
74 | /// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol).
75 | ///
76 | internal static System.Drawing.Icon TrayIconAuto {
77 | get {
78 | object obj = ResourceManager.GetObject("TrayIconAuto", resourceCulture);
79 | return ((System.Drawing.Icon)(obj));
80 | }
81 | }
82 |
83 | ///
84 | /// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol).
85 | ///
86 | internal static System.Drawing.Icon TrayIconOff {
87 | get {
88 | object obj = ResourceManager.GetObject("TrayIconOff", resourceCulture);
89 | return ((System.Drawing.Icon)(obj));
90 | }
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/redshift-tray.Test/redshift-tray.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | {CE4499D3-8240-40FE-A283-DC20EEB2006A}
7 | Library
8 | Properties
9 | redshift_tray.Test
10 | redshift-tray.Test
11 | v4.5
12 | 512
13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
14 | 10.0
15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
17 | False
18 | UnitTest
19 |
20 |
21 |
22 | true
23 | full
24 | false
25 | bin\Debug\
26 | DEBUG;TRACE
27 | prompt
28 | 4
29 |
30 |
31 | pdbonly
32 | true
33 | bin\Release\
34 | TRACE
35 | prompt
36 | 4
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | {86f28b6b-3141-4010-96cd-43aa7e0e0abd}
64 | redshift-tray
65 |
66 |
67 |
68 |
69 |
70 |
71 | False
72 |
73 |
74 | False
75 |
76 |
77 | False
78 |
79 |
80 | False
81 |
82 |
83 |
84 |
85 |
86 |
87 |
94 |
--------------------------------------------------------------------------------
/redshift-tray/TrayIcon.cs:
--------------------------------------------------------------------------------
1 | /* This file is part of redshift-tray.
2 | Copyright (c) Michael Scholz
3 | */
4 | using Hardcodet.Wpf.TaskbarNotification;
5 | using System.Windows.Controls;
6 | using System.Windows;
7 | using System;
8 | using System.Windows.Input;
9 |
10 | namespace redshift_tray
11 | {
12 | class TrayIcon
13 | {
14 |
15 | private static TrayIcon TrayIconInstance;
16 |
17 | private TaskbarIcon TaskbarIconInstance;
18 |
19 | public event RoutedEventHandler OnTrayIconLeftClick;
20 | private void TrayIconLeftClick(RoutedEventArgs e)
21 | {
22 | if(OnTrayIconLeftClick != null)
23 | {
24 | OnTrayIconLeftClick(this, e);
25 | }
26 | }
27 |
28 | public event RoutedEventHandler OnMenuItemExitClicked;
29 | private void MenuItemExitClicked(RoutedEventArgs e)
30 | {
31 | if(OnMenuItemExitClicked != null)
32 | {
33 | OnMenuItemExitClicked(this, e);
34 | }
35 | }
36 |
37 | public event RoutedEventHandler OnMenuItemLogClicked;
38 | private void MenuItemLogClicked(RoutedEventArgs e)
39 | {
40 | if(OnMenuItemLogClicked != null)
41 | {
42 | OnMenuItemLogClicked(this, e);
43 | }
44 | }
45 |
46 | public event RoutedEventHandler OnMenuItemSettingsClicked;
47 | private void MenuItemSettingsClicked(RoutedEventArgs e)
48 | {
49 | if(OnMenuItemSettingsClicked != null)
50 | {
51 | OnMenuItemSettingsClicked(this, e);
52 | }
53 | }
54 |
55 | public Status TrayStatus
56 | {
57 | set
58 | {
59 | switch(value)
60 | {
61 | case Status.Automatic:
62 | TaskbarIconInstance.Icon = Properties.Resources.TrayIconAuto;
63 | TaskbarIconInstance.ToolTipText = "Redshift Tray";
64 | break;
65 | case Status.Off:
66 | TaskbarIconInstance.Icon = Properties.Resources.TrayIconOff;
67 | TaskbarIconInstance.ToolTipText = "Redshift Tray (disabled)";
68 | break;
69 | }
70 | }
71 | }
72 |
73 | private TrayIcon(Status initialStatus)
74 | {
75 | if(TrayIconInstance != null)
76 | {
77 | TrayIconInstance.TaskbarIconInstance.Dispose();
78 | }
79 |
80 | TaskbarIconInstance = new TaskbarIcon();
81 | TrayStatus = initialStatus;
82 | TaskbarIconInstance.ContextMenu = getContextMenu();
83 |
84 | TaskbarIconInstance.TrayLeftMouseUp += TaskbarIconInstance_TrayLeftMouseUp;
85 | }
86 |
87 | public static TrayIcon Create(Status initialStatus)
88 | {
89 | TrayIconInstance = new TrayIcon(initialStatus);
90 | return TrayIconInstance;
91 | }
92 |
93 | public static TrayIcon CreateOrGet(Status initialStatus)
94 | {
95 | if(TrayIconInstance == null)
96 | {
97 | return Create(initialStatus);
98 | }
99 | return TrayIconInstance;
100 | }
101 |
102 | private ContextMenu getContextMenu()
103 | {
104 | ContextMenu contextMenu = new ContextMenu();
105 |
106 | MenuItem menuItemSettings = new MenuItem();
107 | menuItemSettings.Header = "Settings";
108 | menuItemSettings.Click += menuItemSettings_Click;
109 | contextMenu.Items.Add(menuItemSettings);
110 |
111 | MenuItem menuItemLog = new MenuItem();
112 | menuItemLog.Header = "Show log";
113 | menuItemLog.Click += menuItemLog_Click;
114 | contextMenu.Items.Add(menuItemLog);
115 |
116 | MenuItem menuItemAbout = new MenuItem();
117 | menuItemAbout.Header = "About";
118 | menuItemAbout.Click += menuItemAbout_Click;
119 | contextMenu.Items.Add(menuItemAbout);
120 |
121 | contextMenu.Items.Add(new Separator());
122 |
123 | MenuItem menuItemExit = new MenuItem();
124 | menuItemExit.Header = "Exit";
125 | menuItemExit.Click += menuItemExit_Click;
126 | contextMenu.Items.Add(menuItemExit);
127 |
128 | return contextMenu;
129 | }
130 |
131 | private void TaskbarIconInstance_TrayLeftMouseUp(object sender, RoutedEventArgs e)
132 | {
133 | if(Common.WindowExists())
134 | {
135 | return;
136 | }
137 | TrayIconLeftClick(e);
138 | }
139 |
140 | private void menuItemSettings_Click(object sender, RoutedEventArgs e)
141 | {
142 | MenuItemSettingsClicked(e);
143 | }
144 |
145 | private void menuItemLog_Click(object sender, RoutedEventArgs e)
146 | {
147 | MenuItemLogClicked(e);
148 | }
149 |
150 | private void menuItemAbout_Click(object sender, RoutedEventArgs e)
151 | {
152 | About aboutDialog;
153 | if(!Common.WindowExistsFocus(out aboutDialog))
154 | {
155 | aboutDialog = new About();
156 | aboutDialog.ShowDialog();
157 | }
158 | }
159 |
160 | private void menuItemExit_Click(object sender, RoutedEventArgs e)
161 | {
162 | MenuItemExitClicked(e);
163 | }
164 |
165 | }
166 | }
167 |
--------------------------------------------------------------------------------
/redshift-tray/Main.cs:
--------------------------------------------------------------------------------
1 | /* This file is part of redshift-tray.
2 | Copyright (c) Michael Scholz
3 | */
4 | using System.Windows;
5 | using redshift_tray.Properties;
6 | using System;
7 |
8 | namespace redshift_tray
9 | {
10 | class Main
11 | {
12 |
13 | public const string VERSION = "1.0.0";
14 |
15 | public const string RELEASES_PAGE = "https://github.com/jonls/redshift/releases";
16 |
17 | public const string GEO_API_DOMAIN = "ip-api.com";
18 | public const string GEO_API_TARGET = "http://ip-api.com/line/?fields=16576";
19 |
20 | private static DebugConsole debugConsole;
21 |
22 | private Status _ProgramStatus;
23 | private Redshift RedshiftInstance;
24 | private TrayIcon TrayIconInstance;
25 | private string RedshiftPath;
26 | private Settings Settings;
27 | private bool DummyMethod;
28 |
29 | private Status ProgramStatus
30 | {
31 | get { return _ProgramStatus; }
32 | set
33 | {
34 | switch(value)
35 | {
36 | case Status.Automatic:
37 | WriteLogMessage("Switching to automatic mode.", DebugConsole.LogType.Info);
38 | StartRedshiftAutomatic();
39 | break;
40 | case Status.Off:
41 | WriteLogMessage("Switching to off mode.", DebugConsole.LogType.Info);
42 | StopRedshift();
43 | break;
44 | }
45 | if(TrayIconInstance != null)
46 | {
47 | TrayIconInstance.TrayStatus = value;
48 | }
49 | _ProgramStatus = value;
50 | }
51 | }
52 |
53 | public static void WriteLogMessage(string message, DebugConsole.LogType logType)
54 | {
55 | if(debugConsole != null)
56 | {
57 | debugConsole.WriteLog(message, logType);
58 | }
59 | }
60 |
61 | public Main(bool dummyMethod)
62 | {
63 | debugConsole = new DebugConsole();
64 | DummyMethod = dummyMethod;
65 | }
66 |
67 | public bool Initialize()
68 | {
69 | LoadSettings();
70 | if(!CheckSettings())
71 | {
72 | return false;
73 | }
74 | if(Settings.Default.RedshiftLocateOnStart)
75 | {
76 | UpdateAutoLocation();
77 | }
78 |
79 | Redshift.KillAllRunningInstances();
80 |
81 | ProgramStatus = Settings.RedshiftEnabledOnStart ? Status.Automatic : Status.Off;
82 | StartTrayIcon();
83 |
84 | return true;
85 | }
86 |
87 | private void LoadSettings()
88 | {
89 | RedshiftPath = Settings.Default.RedshiftAppPath;
90 | Settings = Settings.Default;
91 | }
92 |
93 | private bool CheckSettings()
94 | {
95 | Redshift.ExecutableError exeError = Redshift.CheckExecutable(RedshiftPath);
96 |
97 | if(exeError != Redshift.ExecutableError.Ok)
98 | {
99 | SettingsWindow settingsWindow;
100 | if(!Common.WindowExistsFocus(out settingsWindow))
101 | {
102 | settingsWindow = new SettingsWindow();
103 | if((bool)settingsWindow.ShowDialog())
104 | {
105 | LoadSettings();
106 | return true;
107 | }
108 | return false;
109 | }
110 | }
111 | return true;
112 | }
113 |
114 | private bool UpdateAutoLocation()
115 | {
116 | AutoLocation autoLocation = Common.DetectLocation();
117 |
118 | if(autoLocation.Success)
119 | {
120 | Settings.Default.RedshiftLatitude = autoLocation.Latitude;
121 | Settings.Default.RedshiftLongitude = autoLocation.Longitude;
122 | Settings.Default.Save();
123 | return true;
124 | }
125 |
126 | return false;
127 | }
128 |
129 | private void StartRedshiftAutomatic()
130 | {
131 | string[] args = Redshift.GetArgsBySettings(DummyMethod);
132 | RedshiftInstance = Redshift.StartContinuous(RedshiftPath, RedshiftInstance_OnRedshiftQuit, args);
133 | }
134 |
135 | private bool StopRedshift()
136 | {
137 | if(RedshiftInstance != null && RedshiftInstance.isRunning)
138 | {
139 | RedshiftInstance.Stop();
140 | ResetScreen();
141 | return true;
142 | }
143 | return false;
144 | }
145 |
146 | private void ResetScreen()
147 | {
148 | string[] args = { string.Format("-m {0}", DummyMethod ? Redshift.METHOD_DUMMY : Redshift.METHOD_WINGDI), "-x" };
149 | Redshift.StartAndWaitForOutput(RedshiftPath, args);
150 | }
151 |
152 | private void StartTrayIcon()
153 | {
154 | TrayIconInstance = TrayIcon.Create(ProgramStatus);
155 |
156 | TrayIconInstance.OnTrayIconLeftClick += (sender, e) =>
157 | {
158 | switch(ProgramStatus)
159 | {
160 | case Status.Automatic:
161 | ProgramStatus = Status.Off;
162 | break;
163 | case Status.Off:
164 | ProgramStatus = Status.Automatic;
165 | break;
166 | }
167 | };
168 |
169 | TrayIconInstance.OnMenuItemExitClicked += (sender, e) =>
170 | {
171 | StopRedshift();
172 | Application.Current.Shutdown(0);
173 | };
174 |
175 | TrayIconInstance.OnMenuItemLogClicked += (sender, e) =>
176 | {
177 | debugConsole.ShowOrUnhide();
178 | };
179 |
180 | TrayIconInstance.OnMenuItemSettingsClicked += (sender, e) =>
181 | {
182 | SettingsWindow settingsWindow;
183 | if(!Common.WindowExistsFocus(out settingsWindow))
184 | {
185 | settingsWindow = new SettingsWindow();
186 | if((bool)settingsWindow.ShowDialog())
187 | {
188 | LoadSettings();
189 | if(ProgramStatus == Status.Automatic)
190 | {
191 | StartRedshiftAutomatic();
192 | }
193 | }
194 | }
195 | };
196 | }
197 |
198 | private void RedshiftInstance_OnRedshiftQuit(object sender, RedshiftQuitArgs e)
199 | {
200 | if(!e.ManualKill)
201 | {
202 | Application.Current.Dispatcher.Invoke(() =>
203 | {
204 | MessageBox.Show(string.Format("Redshift crashed with the following output:{0}{0}{1}", Environment.NewLine, e.ErrorOutput), "Redshift Tray", MessageBoxButton.OK, MessageBoxImage.Error);
205 |
206 | SettingsWindow settingsWindow;
207 | if(!Common.WindowExistsFocus(out settingsWindow))
208 | {
209 | settingsWindow = new SettingsWindow();
210 | if((bool)settingsWindow.ShowDialog())
211 | {
212 | LoadSettings();
213 | StartRedshiftAutomatic();
214 | }
215 | else
216 | {
217 | Application.Current.Shutdown(-1);
218 | }
219 | }
220 | });
221 | }
222 | }
223 | }
224 | }
225 |
--------------------------------------------------------------------------------
/redshift-tray/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 |
122 | ..\Resources\AboutIcon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
123 |
124 |
125 | ..\resources\trayiconauto.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
126 |
127 |
128 | ..\Resources\TrayIconOff.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
129 |
130 |
--------------------------------------------------------------------------------
/redshift-tray/Common.cs:
--------------------------------------------------------------------------------
1 | /* This file is part of redshift-tray.
2 | Copyright (c) Michael Scholz
3 | */
4 | using Microsoft.Win32;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Globalization;
8 | using System.IO;
9 | using System.Linq;
10 | using System.Net;
11 | using System.Net.NetworkInformation;
12 | using System.Text;
13 | using System.Threading.Tasks;
14 | using System.Windows;
15 |
16 | namespace redshift_tray
17 | {
18 |
19 | static class Common
20 | {
21 |
22 | public static bool Autostart
23 | {
24 | get
25 | {
26 | using (RegistryKey regPath = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", false))
27 | {
28 | return regPath.GetValue("Redshift Tray") != null;
29 | }
30 | }
31 | set
32 | {
33 | if(Autostart == value)
34 | {
35 | return;
36 | }
37 |
38 | using (RegistryKey regPath = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) {
39 | switch(value)
40 | {
41 | case true:
42 | regPath.SetValue("Redshift Tray",
43 | Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, System.AppDomain.CurrentDomain.FriendlyName));
44 | break;
45 | case false:
46 | regPath.DeleteValue("Redshift Tray");
47 | break;
48 | }
49 | }
50 | }
51 | }
52 |
53 | public static AutoLocation DetectLocation()
54 | {
55 | Main.WriteLogMessage("Detecting location via API.", DebugConsole.LogType.Info);
56 |
57 | AutoLocation returnValue = new AutoLocation();
58 |
59 | try
60 | {
61 | Main.WriteLogMessage(string.Format("Pinging {0}", Main.GEO_API_DOMAIN), DebugConsole.LogType.Info);
62 | using(Ping ping = new Ping()) {
63 | PingReply pingReply = ping.Send(Main.GEO_API_DOMAIN, 5000);
64 | if(pingReply.Status != IPStatus.Success)
65 | {
66 | Main.WriteLogMessage("API is not reachable.", DebugConsole.LogType.Error);
67 | returnValue.Success = false;
68 | returnValue.Errortext = string.Format("Location provider is not reachable.{0}Please make sure that your internet connection works properly and try again in a few minutes.", Environment.NewLine);
69 | return returnValue;
70 | }
71 | if(IPAddress.IsLoopback(pingReply.Address) || pingReply.Address.Equals(IPAddress.Any))
72 | {
73 | Main.WriteLogMessage("API is routed to localhost.", DebugConsole.LogType.Error);
74 | returnValue.Success = false;
75 | returnValue.Errortext = string.Format("The location provider is blocked by your proxy or hosts-file.{0}Please insert your location manually or allow connections to {1}.", Environment.NewLine, Main.GEO_API_DOMAIN);
76 | return returnValue;
77 | }
78 | }
79 | }
80 | catch(PingException)
81 | {
82 | Main.WriteLogMessage("API is not reachable.", DebugConsole.LogType.Error);
83 | returnValue.Success = false;
84 | returnValue.Errortext = string.Format("Location provider is not reachable.{0}Please make sure that your internet connection works properly and try again in a few minutes.", Environment.NewLine);
85 | return returnValue;
86 | }
87 |
88 |
89 | string latitude;
90 | string longitude;
91 |
92 | try
93 | {
94 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Main.GEO_API_TARGET);
95 | request.Proxy = null;
96 |
97 | using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
98 | {
99 | if(response.StatusCode != HttpStatusCode.OK)
100 | {
101 | Main.WriteLogMessage("A server side error occured.", DebugConsole.LogType.Error);
102 | returnValue.Success = false;
103 | returnValue.Errortext = string.Format("An error on the server side of the location provider occured.{0}Please try again later.", Environment.NewLine);
104 | return returnValue;
105 | }
106 |
107 | using (StreamReader reader = new StreamReader(response.GetResponseStream())) {
108 | if (reader.EndOfStream || reader.ReadLine() != "success")
109 | {
110 | Main.WriteLogMessage("A server side error occured.", DebugConsole.LogType.Error);
111 | returnValue.Success = false;
112 | returnValue.Errortext = string.Format("An error on the server side of the location provider occured.{0}Please try again later.", Environment.NewLine);
113 | return returnValue;
114 | }
115 |
116 | latitude = reader.ReadLine();
117 | longitude = reader.ReadLine();
118 | }
119 | }
120 | }
121 | catch(WebException)
122 | {
123 | Main.WriteLogMessage("A server side error occured.", DebugConsole.LogType.Error);
124 | returnValue.Success = false;
125 | returnValue.Errortext = string.Format("An error on the server side of the location provider occured.{0}Please try again later.", Environment.NewLine);
126 | return returnValue;
127 | }
128 |
129 | Main.WriteLogMessage("Location detected", DebugConsole.LogType.Info);
130 | returnValue = ParseLocation(latitude, longitude);
131 |
132 | return returnValue;
133 | }
134 |
135 | public static AutoLocation ParseLocation(string latitude, string longitude)
136 | {
137 | AutoLocation returnValue = new AutoLocation();
138 | returnValue.Success = true;
139 | returnValue.Latitude = decimal.Parse(latitude, NumberStyles.Float, CultureInfo.InvariantCulture);
140 | returnValue.Longitude = decimal.Parse(longitude, NumberStyles.Float, CultureInfo.InvariantCulture);
141 | return returnValue;
142 | }
143 |
144 | public static bool isOutOfBounds(double x, double y)
145 | {
146 | if(x <= SystemParameters.VirtualScreenLeft) return true;
147 | if(y <= SystemParameters.VirtualScreenTop) return true;
148 | if(x >= SystemParameters.VirtualScreenLeft + SystemParameters.VirtualScreenWidth) return true;
149 | if(y >= SystemParameters.VirtualScreenTop + SystemParameters.VirtualScreenHeight) return true;
150 | return false;
151 | }
152 |
153 | public static bool WindowExistsFocus(out T windowInstance) where T : Window
154 | {
155 | bool returnValue;
156 | if(returnValue = WindowExists(out windowInstance))
157 | {
158 | windowInstance.Focus();
159 | }
160 | return returnValue;
161 | }
162 |
163 | public static bool WindowExists(out T windowInstance) where T : Window
164 | {
165 | windowInstance = Application.Current.Windows.OfType().FirstOrDefault();
166 | return (windowInstance != null);
167 | }
168 |
169 | public static bool WindowExists() where T : Window
170 | {
171 | return Application.Current.Windows.OfType().Any();
172 | }
173 |
174 | }
175 |
176 | public struct AutoLocation
177 | {
178 | public bool Success;
179 | public decimal Latitude;
180 | public decimal Longitude;
181 | public string Errortext;
182 | }
183 |
184 | public enum Status
185 | {
186 | Automatic,
187 | Off
188 | }
189 |
190 | }
--------------------------------------------------------------------------------
/redshift-tray/redshift-tray.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {86F28B6B-3141-4010-96CD-43AA7E0E0ABD}
8 | WinExe
9 | Properties
10 | redshift_tray
11 | redshift-tray
12 | v4.5
13 | 512
14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
15 | 4
16 | publish\
17 | true
18 | Disk
19 | false
20 | Foreground
21 | 7
22 | Days
23 | false
24 | false
25 | true
26 | 0
27 | 1.0.0.%2a
28 | false
29 | false
30 | true
31 |
32 |
33 | AnyCPU
34 | true
35 | full
36 | false
37 | bin\Debug\
38 | DEBUG;TRACE
39 | prompt
40 | 4
41 |
42 |
43 | AnyCPU
44 | pdbonly
45 | true
46 | bin\Release\
47 | TRACE
48 | prompt
49 | 4
50 |
51 |
52 | redshift-tray.ico
53 |
54 |
55 |
56 | ..\packages\Hardcodet.NotifyIcon.Wpf.1.0.5\lib\net45\Hardcodet.Wpf.TaskbarNotification.dll
57 | True
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 | 4.0
69 |
70 |
71 |
72 |
73 |
74 | ..\packages\Extended.Wpf.Toolkit.2.9\lib\net40\Xceed.Wpf.Toolkit.dll
75 | True
76 |
77 |
78 |
79 |
80 | MSBuild:Compile
81 | Designer
82 |
83 |
84 | About.xaml
85 |
86 |
87 | App.xaml
88 | Code
89 |
90 |
91 |
92 | DebugConsole.xaml
93 |
94 |
95 |
96 |
97 |
98 | SettingsWindow.xaml
99 |
100 |
101 |
102 |
103 |
104 | Code
105 |
106 |
107 | True
108 | True
109 | Resources.resx
110 |
111 |
112 | True
113 | Settings.settings
114 | True
115 |
116 |
117 | ResXFileCodeGenerator
118 | Resources.Designer.cs
119 |
120 |
121 |
122 | SettingsSingleFileGenerator
123 | Settings.Designer.cs
124 |
125 |
126 |
127 |
128 |
129 | Designer
130 |
131 |
132 |
133 |
134 | Designer
135 | MSBuild:Compile
136 |
137 |
138 | Designer
139 | MSBuild:Compile
140 |
141 |
142 | Designer
143 | MSBuild:Compile
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 | False
160 | Microsoft .NET Framework 4.5 %28x86 and x64%29
161 | true
162 |
163 |
164 | False
165 | .NET Framework 3.5 SP1 Client Profile
166 | false
167 |
168 |
169 | False
170 | .NET Framework 3.5 SP1
171 | false
172 |
173 |
174 |
175 |
182 |
--------------------------------------------------------------------------------
/redshift-tray/SettingsWindow.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
12 |
16 |
20 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/redshift-tray/redshift.cs:
--------------------------------------------------------------------------------
1 | /* This file is part of redshift-tray.
2 | Copyright (c) Michael Scholz
3 | */
4 | using Microsoft.Win32;
5 | using redshift_tray.Properties;
6 | using System;
7 | using System.Collections.Generic;
8 | using System.Diagnostics;
9 | using System.IO;
10 | using System.Threading;
11 |
12 | namespace redshift_tray
13 | {
14 | public class Redshift
15 | {
16 | public readonly static int[] MIN_REDSHIFT_VERSION = { 1, 10 };
17 |
18 | public const string METHOD_WINGDI = "wingdi";
19 | public const string METHOD_DUMMY = "dummy";
20 |
21 | private static Redshift Instance;
22 |
23 | private Process RedshiftProcess;
24 |
25 | public delegate void RedshiftQuitHandler(object sender, RedshiftQuitArgs e);
26 | public event RedshiftQuitHandler OnRedshiftQuit;
27 | private void RedshiftQuit(bool manualKill)
28 | {
29 | if(OnRedshiftQuit != null)
30 | {
31 | RedshiftQuitArgs e = new RedshiftQuitArgs();
32 | e.ManualKill = manualKill;
33 | e.StandardOutput = GetStandardOutput();
34 | e.ErrorOutput = GetErrorOutput();
35 |
36 | OnRedshiftQuit(this, e);
37 | }
38 | }
39 |
40 | public bool isRunning
41 | {
42 | get { return !RedshiftProcess.HasExited; }
43 | }
44 |
45 | public static string[] GetArgsBySettings(bool useDummyMethod)
46 | {
47 | Settings settings = Settings.Default;
48 | List returnValue = new List();
49 |
50 | //Method
51 | returnValue.Add(string.Format("-m {0}", useDummyMethod ? METHOD_DUMMY : METHOD_WINGDI));
52 |
53 | //Location
54 | returnValue.Add(string.Format("-l {0}:{1}", settings.RedshiftLatitude.ToString().Replace(',', '.'), settings.RedshiftLongitude.ToString().Replace(',', '.')));
55 |
56 | //Temperature
57 | returnValue.Add(string.Format("-t {0}:{1}", settings.RedshiftTemperatureDay, settings.RedshiftTemperatureNight));
58 |
59 | //Transition
60 | if(!settings.RedshiftTransition)
61 | {
62 | returnValue.Add("-r");
63 | }
64 |
65 | //Brightness
66 | returnValue.Add(string.Format("-b {0}:{1}", settings.RedshiftBrightnessDay.ToString().Replace(',', '.'), settings.RedshiftBrightnessNight.ToString().Replace(',', '.')));
67 |
68 | //Gamma Correction
69 | returnValue.Add(string.Format("-g {0}:{1}:{2}", settings.RedshiftGammaRed.ToString().Replace(',', '.'), settings.RedshiftGammaGreen.ToString().Replace(',', '.'), settings.RedshiftGammaBlue.ToString().Replace(',', '.')));
70 |
71 | return returnValue.ToArray();
72 | }
73 |
74 | public static ExecutableError CheckExecutable(string path)
75 | {
76 | Main.WriteLogMessage("Checking redshift executable", DebugConsole.LogType.Info);
77 |
78 | if(path == string.Empty)
79 | {
80 | Main.WriteLogMessage("No redshift path set", DebugConsole.LogType.Info);
81 | return ExecutableError.MissingPath;
82 | }
83 |
84 | if(!File.Exists(path))
85 | {
86 | Main.WriteLogMessage("Redshift executable not found", DebugConsole.LogType.Error);
87 | return ExecutableError.NotFound;
88 | }
89 |
90 | string[] version = StartAndWaitForOutput(path, "-V").Split(' ');
91 |
92 | if(version.Length < 2 || version[0] != "redshift")
93 | {
94 | Main.WriteLogMessage("Redshift executable is not a valid redshift binary", DebugConsole.LogType.Error);
95 | return ExecutableError.WrongApplication;
96 | }
97 |
98 | Main.WriteLogMessage(string.Format("Checking redshift version >= {0}.{1}", MIN_REDSHIFT_VERSION[0], MIN_REDSHIFT_VERSION[1]), DebugConsole.LogType.Info);
99 |
100 | if(!CheckExecutableVersion(version[1]))
101 | {
102 | Main.WriteLogMessage("Redshift version is too low", DebugConsole.LogType.Error);
103 | return ExecutableError.WrongVersion;
104 | }
105 |
106 | return ExecutableError.Ok;
107 | }
108 |
109 | private static bool CheckExecutableVersion(string version)
110 | {
111 | string[] versionnr = version.Split('.');
112 | if(versionnr.Length < 2)
113 | {
114 | return false;
115 | }
116 |
117 | int majorversion = 0;
118 | int minorVersion = 0;
119 | int.TryParse(versionnr[0], out majorversion);
120 | int.TryParse(versionnr[1], out minorVersion);
121 |
122 | if(majorversion > MIN_REDSHIFT_VERSION[0])
123 | {
124 | return true;
125 | }
126 |
127 | return (majorversion == MIN_REDSHIFT_VERSION[0] && minorVersion >= MIN_REDSHIFT_VERSION[1]);
128 | }
129 |
130 | public static void KillAllRunningInstances()
131 | {
132 | Main.WriteLogMessage("Looking for running redshift instances.", DebugConsole.LogType.Info);
133 | foreach(Process redshift in Process.GetProcessesByName("redshift"))
134 | {
135 | if(!redshift.HasExited)
136 | {
137 | try
138 | {
139 | redshift.Kill();
140 | Main.WriteLogMessage("Killed previous redshift process.", DebugConsole.LogType.Info);
141 | }
142 | catch
143 | {
144 | Main.WriteLogMessage("Was not able to kill redshift process.", DebugConsole.LogType.Error);
145 | }
146 | }
147 | }
148 | }
149 |
150 | public static Redshift StartContinuous(string path, RedshiftQuitHandler onRedshiftQuit = null, params string[] Args)
151 | {
152 | InitializeContinuousStart(path, Args);
153 | if(onRedshiftQuit != null)
154 | {
155 | Instance.OnRedshiftQuit += onRedshiftQuit;
156 | }
157 |
158 | SystemEvents.SessionEnding -= Instance.SystemEvents_SessionEnding;
159 | Instance.Start();
160 | SystemEvents.SessionEnding += Instance.SystemEvents_SessionEnding;
161 |
162 | return Instance;
163 | }
164 |
165 | private static Redshift InitializeContinuousStart(string path, params string[] Args)
166 | {
167 | if(CheckExecutable(path) != ExecutableError.Ok)
168 | throw new Exception("Invalid redshift start.");
169 |
170 | if(Instance != null && !Instance.RedshiftProcess.HasExited)
171 | {
172 | Instance.RedshiftProcess.Exited -= Instance.RedshiftProcess_Crashed;
173 | Instance.RedshiftProcess.Kill();
174 | Instance.RedshiftQuit(true);
175 | }
176 | Instance = new Redshift(path, Args);
177 |
178 | return Instance;
179 | }
180 |
181 | public static string StartAndWaitForOutput(string path, params string[] Args)
182 | {
183 | Redshift redshift = new Redshift(path, Args);
184 | redshift.Start();
185 | redshift.RedshiftProcess.WaitForExit();
186 |
187 | return redshift.GetStandardOutput();
188 | }
189 |
190 | private Redshift(string path, params string[] Args)
191 | {
192 | string arglist = string.Join(" ", Args);
193 |
194 | Main.WriteLogMessage(string.Format("Starting redshift with args '{0}'", arglist), DebugConsole.LogType.Info);
195 |
196 | RedshiftProcess = new Process();
197 | RedshiftProcess.StartInfo.FileName = path;
198 | RedshiftProcess.StartInfo.Arguments = arglist;
199 | RedshiftProcess.StartInfo.UseShellExecute = false;
200 | RedshiftProcess.StartInfo.CreateNoWindow = true;
201 | RedshiftProcess.StartInfo.RedirectStandardOutput = true;
202 | RedshiftProcess.StartInfo.RedirectStandardError = true;
203 | RedshiftProcess.EnableRaisingEvents = true;
204 | RedshiftProcess.Exited += RedshiftProcess_Crashed;
205 | }
206 |
207 | private void Start()
208 | {
209 | RedshiftProcess.Start();
210 | }
211 |
212 | public void Stop()
213 | {
214 | if(isRunning)
215 | {
216 | Main.WriteLogMessage("Stopped redshift instance.", DebugConsole.LogType.Info);
217 | SystemEvents.SessionEnding -= SystemEvents_SessionEnding;
218 | RedshiftProcess.Exited -= RedshiftProcess_Crashed;
219 | RedshiftProcess.Kill();
220 | RedshiftQuit(true);
221 | }
222 | }
223 |
224 | public string GetStandardOutput()
225 | {
226 | if(RedshiftProcess == null || isRunning)
227 | {
228 | return string.Empty;
229 | }
230 |
231 | string output = RedshiftProcess.StandardOutput.ReadToEnd();
232 | Main.WriteLogMessage(output, DebugConsole.LogType.Redshift);
233 |
234 | return output;
235 | }
236 |
237 | public string GetErrorOutput()
238 | {
239 | if(RedshiftProcess == null || isRunning)
240 | {
241 | return string.Empty;
242 | }
243 |
244 | string output = RedshiftProcess.StandardError.ReadToEnd();
245 | Main.WriteLogMessage(output, DebugConsole.LogType.Redshift);
246 |
247 | return output;
248 | }
249 |
250 | void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
251 | {
252 | RedshiftProcess.Exited -= RedshiftProcess_Crashed;
253 | }
254 |
255 | void RedshiftProcess_Crashed(object sender, EventArgs e)
256 | {
257 | RedshiftQuit(false);
258 | }
259 |
260 | public enum ExecutableError
261 | {
262 | Ok,
263 | NotFound,
264 | WrongVersion,
265 | WrongApplication,
266 | MissingPath
267 | }
268 |
269 | }
270 |
271 | public class RedshiftQuitArgs : EventArgs
272 | {
273 | public bool ManualKill { get; set; }
274 | public string StandardOutput { get; set; }
275 | public string ErrorOutput { get; set; }
276 | }
277 | }
278 |
--------------------------------------------------------------------------------
/redshift-tray/SettingsWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | /* This file is part of redshift-tray.
2 | Copyright (c) Michael Scholz
3 | */
4 | using Microsoft.Win32;
5 | using redshift_tray.Properties;
6 | using System.Globalization;
7 | using System.IO;
8 | using System.Windows;
9 | using System.Windows.Documents;
10 | using System.Windows.Media;
11 | using Xceed.Wpf.Toolkit;
12 | using Xceed.Wpf.Toolkit.Core.Input;
13 | using System.Linq;
14 | using System.Windows.Input;
15 |
16 | namespace redshift_tray
17 | {
18 | public partial class SettingsWindow : Window
19 | {
20 |
21 | private Redshift.ExecutableError _ExecutableErrorState;
22 |
23 | private Redshift.ExecutableError ExecutableErrorState
24 | {
25 | get { return _ExecutableErrorState; }
26 | set
27 | {
28 | _ExecutableErrorState = value;
29 | switch(value)
30 | {
31 | case Redshift.ExecutableError.MissingPath:
32 | Run run;
33 | RedshiftInfo.Foreground = Brushes.Black;
34 | RedshiftInfo.Inlines.Clear();
35 |
36 | run = new Run("The required Redshift executable can be downloaded ");
37 | RedshiftInfo.Inlines.Add(run);
38 |
39 | run = new Run("here on Github");
40 | Hyperlink github = new Hyperlink(run);
41 | github.NavigateUri = new System.Uri(Main.RELEASES_PAGE);
42 | github.RequestNavigate += Hyperlink_RequestNavigate;
43 | RedshiftInfo.Inlines.Add(github);
44 |
45 | run = new Run(".");
46 | RedshiftInfo.Inlines.Add(run);
47 | break;
48 | case Redshift.ExecutableError.NotFound:
49 | RedshiftInfo.Foreground = Brushes.Red;
50 | RedshiftInfo.Text = "Invalid path to Redshift executable.";
51 | break;
52 | case Redshift.ExecutableError.WrongApplication:
53 | RedshiftInfo.Foreground = Brushes.Red;
54 | RedshiftInfo.Text = "Executable seems not to be a valid Redshift binary.";
55 | break;
56 | case Redshift.ExecutableError.WrongVersion:
57 | RedshiftInfo.Foreground = Brushes.Red;
58 | RedshiftInfo.Text = string.Format("The Redshift version is be too old. Please use at least version {0}.{1}.", Redshift.MIN_REDSHIFT_VERSION[0], Redshift.MIN_REDSHIFT_VERSION[1]);
59 | break;
60 | case Redshift.ExecutableError.Ok:
61 | RedshiftInfo.Foreground = Brushes.Green;
62 | RedshiftInfo.Text = "Redshift executable is suitable.";
63 | break;
64 | }
65 | SetOkButtonEnabled();
66 | }
67 | }
68 |
69 | public SettingsWindow()
70 | {
71 | InitializeComponent();
72 | LoadPosition();
73 | LoadConfig();
74 | ExecutableErrorState = Redshift.CheckExecutable(RedshiftPath.Text);
75 | SetOkButtonEnabled();
76 | }
77 |
78 | public SettingsWindow(Redshift.ExecutableError initialRedshiftErrorNote)
79 | {
80 | InitializeComponent();
81 | LoadPosition();
82 | LoadConfig();
83 | ExecutableErrorState = initialRedshiftErrorNote;
84 | }
85 |
86 | private void SavePosition()
87 | {
88 | Settings settings = Settings.Default;
89 |
90 | settings.SettingsWindowLeft = this.Left;
91 | settings.SettingsWindowTop = this.Top;
92 |
93 | settings.Save();
94 | }
95 |
96 | private void LoadPosition()
97 | {
98 | Settings settings = Settings.Default;
99 |
100 | if(Common.isOutOfBounds(settings.SettingsWindowLeft, settings.SettingsWindowTop))
101 | {
102 | return;
103 | }
104 |
105 | this.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
106 | this.Left = settings.SettingsWindowLeft;
107 | this.Top = settings.SettingsWindowTop;
108 | }
109 |
110 | private void SaveConfig()
111 | {
112 | Common.Autostart = (bool)Autostart.IsChecked;
113 |
114 | Settings.Default.Save();
115 | }
116 |
117 | private void LoadConfig()
118 | {
119 | DataContext = Settings.Default;
120 | Autostart.IsChecked = Common.Autostart;
121 | }
122 |
123 | private bool CheckConfig()
124 | {
125 | return (_ExecutableErrorState == Redshift.ExecutableError.Ok);
126 | }
127 |
128 | private void ImportConfig(string file)
129 | {
130 | string[] config = File.ReadAllLines(file);
131 |
132 | var items = (
133 | from s in config
134 | where !s.StartsWith(";") && s.Contains("=")
135 | select s.Split('=')
136 | ).Select(s => new { key = s[0], value = s[1].Split(';')[0] });
137 |
138 | foreach(var item in items)
139 | {
140 | switch(item.key)
141 | {
142 | case "lat":
143 | decimal latitude;
144 |
145 | if(decimal.TryParse(item.value, System.Globalization.NumberStyles.Float, new CultureInfo("en-US"), out latitude))
146 | {
147 | Latitude.Value = (decimal)latitude;
148 | }
149 | break;
150 | case "lon":
151 | decimal longitude;
152 |
153 | if(decimal.TryParse(item.value, System.Globalization.NumberStyles.Float, new CultureInfo("en-US"), out longitude))
154 | {
155 | Longitude.Value = (decimal)longitude;
156 | }
157 | break;
158 | case "temp-day":
159 | int tempDay;
160 |
161 | if(int.TryParse(item.value, System.Globalization.NumberStyles.Float, new CultureInfo("en-US"), out tempDay))
162 | {
163 | TemperatureDay.Value = (int)tempDay;
164 | }
165 | break;
166 | case "temp-night":
167 | int tempNight;
168 |
169 | if(int.TryParse(item.value, System.Globalization.NumberStyles.Float, new CultureInfo("en-US"), out tempNight))
170 | {
171 | TemperatureNight.Value = (int)tempNight;
172 | }
173 | break;
174 | case "transition":
175 | Transition.IsChecked = (item.value == "1");
176 | break;
177 | case "brightness":
178 | decimal brightness;
179 |
180 | if(decimal.TryParse(item.value, System.Globalization.NumberStyles.Float, new CultureInfo("en-US"), out brightness))
181 | {
182 | BrightnessDay.Value = (decimal)brightness;
183 | BrightnessNight.Value = (decimal)brightness;
184 | }
185 | break;
186 | case "brightness-day":
187 | decimal brightnessDay;
188 |
189 | if(decimal.TryParse(item.value, System.Globalization.NumberStyles.Float, new CultureInfo("en-US"), out brightnessDay))
190 | {
191 | BrightnessDay.Value = (decimal)brightnessDay;
192 | }
193 | break;
194 | case "brightness-night":
195 | decimal brightnessNight;
196 |
197 | if(decimal.TryParse(item.value, System.Globalization.NumberStyles.Float, new CultureInfo("en-US"), out brightnessNight))
198 | {
199 | BrightnessNight.Value = (decimal)brightnessNight;
200 | }
201 | break;
202 | case "gamma":
203 | case "gamma-day":
204 | string[] gammaS = item.value.Split(':');
205 | decimal[] gammaD = new decimal[gammaS.Length];
206 | for(int i = 0; i < gammaS.Length; i++)
207 | {
208 | if(!decimal.TryParse(gammaS[i], System.Globalization.NumberStyles.Float, new CultureInfo("en-US"), out gammaD[i]))
209 | {
210 | break;
211 | }
212 | }
213 |
214 | if(gammaD.Length == 1)
215 | {
216 | GammaRed.Value = gammaD[0];
217 | GammaGreen.Value = gammaD[0];
218 | GammaBlue.Value = gammaD[0];
219 | }
220 | else if(gammaD.Length == 3)
221 | {
222 | GammaRed.Value = gammaD[0];
223 | GammaGreen.Value = gammaD[1];
224 | GammaBlue.Value = gammaD[2];
225 | }
226 |
227 | break;
228 | }
229 | }
230 | }
231 |
232 | private void SetOkButtonEnabled()
233 | {
234 | OkButton.IsEnabled = CheckConfig();
235 | }
236 |
237 | private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
238 | {
239 | System.Diagnostics.Process.Start("https://github.com/jonls/redshift/releases");
240 | }
241 |
242 | private void redshiftPath_LostFocus(object sender, RoutedEventArgs e)
243 | {
244 | ExecutableErrorState = Redshift.CheckExecutable(RedshiftPath.Text);
245 | }
246 |
247 | private void ButtonRedshift_Click(object sender, RoutedEventArgs e)
248 | {
249 | OpenFileDialog openFileDialog = new OpenFileDialog();
250 | openFileDialog.Title = "Redshift path";
251 | openFileDialog.Filter = "Redshift|redshift.exe|All executables|*.exe";
252 | openFileDialog.CheckFileExists = true;
253 |
254 | if(File.Exists(RedshiftPath.Text))
255 | {
256 | openFileDialog.InitialDirectory = Path.GetDirectoryName(RedshiftPath.Text);
257 | }
258 |
259 | if((bool)openFileDialog.ShowDialog())
260 | {
261 | Settings.Default.RedshiftAppPath = openFileDialog.FileName;
262 |
263 | ExecutableErrorState = Redshift.CheckExecutable(RedshiftPath.Text);
264 | }
265 | }
266 |
267 | private void DetectLocationButton_Click(object sender, RoutedEventArgs e)
268 | {
269 | Mouse.OverrideCursor = Cursors.Wait;
270 |
271 | AutoLocation autoLocation = Common.DetectLocation();
272 |
273 | if(!autoLocation.Success)
274 | {
275 | System.Windows.MessageBox.Show(autoLocation.Errortext, "Error while detecting location", MessageBoxButton.OK, MessageBoxImage.Error);
276 | }
277 | else
278 | {
279 | Settings.Default.RedshiftLatitude = autoLocation.Latitude;
280 | Settings.Default.RedshiftLongitude = autoLocation.Longitude;
281 | }
282 |
283 | Mouse.OverrideCursor = null;
284 | }
285 |
286 | private void ImportButton_Click(object sender, RoutedEventArgs e)
287 | {
288 | OpenFileDialog openFileDialog = new OpenFileDialog();
289 | openFileDialog.Title = "Import redshift config";
290 | openFileDialog.Filter = "redshift.conf|redshift.conf|All files|*.*";
291 | openFileDialog.CheckFileExists = true;
292 |
293 | if((bool)openFileDialog.ShowDialog())
294 | {
295 | ImportConfig(openFileDialog.FileName);
296 | }
297 | }
298 |
299 | private void OkButton_Click(object sender, RoutedEventArgs e)
300 | {
301 | SaveConfig();
302 | DialogResult = true;
303 | Close();
304 | }
305 |
306 | private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
307 | {
308 | SavePosition();
309 | }
310 |
311 | private void Decimal_InputValidationError(object sender, InputValidationErrorEventArgs e)
312 | {
313 | DecimalUpDown dSender = (DecimalUpDown)sender;
314 |
315 | string value = dSender.Text;
316 | value = value.Replace(',', '.');
317 |
318 | decimal parseValue;
319 | if(decimal.TryParse(value, System.Globalization.NumberStyles.Float, new CultureInfo("en-US"), out parseValue))
320 | {
321 | if(parseValue > dSender.Maximum)
322 | {
323 | dSender.Value = dSender.Maximum;
324 | }
325 | else if(parseValue < dSender.Minimum)
326 | {
327 | dSender.Value = dSender.Minimum;
328 | }
329 | else
330 | {
331 | dSender.Value = parseValue;
332 | }
333 | }
334 | }
335 |
336 | }
337 | }
338 |
--------------------------------------------------------------------------------
/redshift-tray/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // Dieser Code wurde von einem Tool generiert.
4 | // Laufzeitversion:4.0.30319.42000
5 | //
6 | // Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
7 | // der Code erneut generiert wird.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace redshift_tray.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 |
26 | [global::System.Configuration.UserScopedSettingAttribute()]
27 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
28 | [global::System.Configuration.DefaultSettingValueAttribute("")]
29 | public string RedshiftAppPath {
30 | get {
31 | return ((string)(this["RedshiftAppPath"]));
32 | }
33 | set {
34 | this["RedshiftAppPath"] = value;
35 | }
36 | }
37 |
38 | [global::System.Configuration.UserScopedSettingAttribute()]
39 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
40 | [global::System.Configuration.DefaultSettingValueAttribute("0")]
41 | public decimal RedshiftLatitude {
42 | get {
43 | return ((decimal)(this["RedshiftLatitude"]));
44 | }
45 | set {
46 | this["RedshiftLatitude"] = value;
47 | }
48 | }
49 |
50 | [global::System.Configuration.UserScopedSettingAttribute()]
51 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
52 | [global::System.Configuration.DefaultSettingValueAttribute("0")]
53 | public decimal RedshiftLongitude {
54 | get {
55 | return ((decimal)(this["RedshiftLongitude"]));
56 | }
57 | set {
58 | this["RedshiftLongitude"] = value;
59 | }
60 | }
61 |
62 | [global::System.Configuration.UserScopedSettingAttribute()]
63 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
64 | [global::System.Configuration.DefaultSettingValueAttribute("5500")]
65 | public int RedshiftTemperatureDay {
66 | get {
67 | return ((int)(this["RedshiftTemperatureDay"]));
68 | }
69 | set {
70 | this["RedshiftTemperatureDay"] = value;
71 | }
72 | }
73 |
74 | [global::System.Configuration.UserScopedSettingAttribute()]
75 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
76 | [global::System.Configuration.DefaultSettingValueAttribute("3500")]
77 | public int RedshiftTemperatureNight {
78 | get {
79 | return ((int)(this["RedshiftTemperatureNight"]));
80 | }
81 | set {
82 | this["RedshiftTemperatureNight"] = value;
83 | }
84 | }
85 |
86 | [global::System.Configuration.UserScopedSettingAttribute()]
87 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
88 | [global::System.Configuration.DefaultSettingValueAttribute("True")]
89 | public bool RedshiftTransition {
90 | get {
91 | return ((bool)(this["RedshiftTransition"]));
92 | }
93 | set {
94 | this["RedshiftTransition"] = value;
95 | }
96 | }
97 |
98 | [global::System.Configuration.UserScopedSettingAttribute()]
99 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
100 | [global::System.Configuration.DefaultSettingValueAttribute("-10000")]
101 | public double DebugConsoleLeft {
102 | get {
103 | return ((double)(this["DebugConsoleLeft"]));
104 | }
105 | set {
106 | this["DebugConsoleLeft"] = value;
107 | }
108 | }
109 |
110 | [global::System.Configuration.UserScopedSettingAttribute()]
111 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
112 | [global::System.Configuration.DefaultSettingValueAttribute("-10000")]
113 | public double DebugConsoleTop {
114 | get {
115 | return ((double)(this["DebugConsoleTop"]));
116 | }
117 | set {
118 | this["DebugConsoleTop"] = value;
119 | }
120 | }
121 |
122 | [global::System.Configuration.UserScopedSettingAttribute()]
123 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
124 | [global::System.Configuration.DefaultSettingValueAttribute("-10000")]
125 | public double DebugConsoleWidth {
126 | get {
127 | return ((double)(this["DebugConsoleWidth"]));
128 | }
129 | set {
130 | this["DebugConsoleWidth"] = value;
131 | }
132 | }
133 |
134 | [global::System.Configuration.UserScopedSettingAttribute()]
135 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
136 | [global::System.Configuration.DefaultSettingValueAttribute("-10000")]
137 | public double DebugConsoleHeight {
138 | get {
139 | return ((double)(this["DebugConsoleHeight"]));
140 | }
141 | set {
142 | this["DebugConsoleHeight"] = value;
143 | }
144 | }
145 |
146 | [global::System.Configuration.UserScopedSettingAttribute()]
147 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
148 | [global::System.Configuration.DefaultSettingValueAttribute("Normal")]
149 | public global::System.Windows.WindowState DebugConsoleWindowState {
150 | get {
151 | return ((global::System.Windows.WindowState)(this["DebugConsoleWindowState"]));
152 | }
153 | set {
154 | this["DebugConsoleWindowState"] = value;
155 | }
156 | }
157 |
158 | [global::System.Configuration.UserScopedSettingAttribute()]
159 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
160 | [global::System.Configuration.DefaultSettingValueAttribute("-10000")]
161 | public double AboutLeft {
162 | get {
163 | return ((double)(this["AboutLeft"]));
164 | }
165 | set {
166 | this["AboutLeft"] = value;
167 | }
168 | }
169 |
170 | [global::System.Configuration.UserScopedSettingAttribute()]
171 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
172 | [global::System.Configuration.DefaultSettingValueAttribute("-10000")]
173 | public double AboutTop {
174 | get {
175 | return ((double)(this["AboutTop"]));
176 | }
177 | set {
178 | this["AboutTop"] = value;
179 | }
180 | }
181 |
182 | [global::System.Configuration.UserScopedSettingAttribute()]
183 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
184 | [global::System.Configuration.DefaultSettingValueAttribute("-10000")]
185 | public double SettingsWindowLeft {
186 | get {
187 | return ((double)(this["SettingsWindowLeft"]));
188 | }
189 | set {
190 | this["SettingsWindowLeft"] = value;
191 | }
192 | }
193 |
194 | [global::System.Configuration.UserScopedSettingAttribute()]
195 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
196 | [global::System.Configuration.DefaultSettingValueAttribute("-10000")]
197 | public double SettingsWindowTop {
198 | get {
199 | return ((double)(this["SettingsWindowTop"]));
200 | }
201 | set {
202 | this["SettingsWindowTop"] = value;
203 | }
204 | }
205 |
206 | [global::System.Configuration.UserScopedSettingAttribute()]
207 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
208 | [global::System.Configuration.DefaultSettingValueAttribute("True")]
209 | public bool RedshiftEnabledOnStart {
210 | get {
211 | return ((bool)(this["RedshiftEnabledOnStart"]));
212 | }
213 | set {
214 | this["RedshiftEnabledOnStart"] = value;
215 | }
216 | }
217 |
218 | [global::System.Configuration.UserScopedSettingAttribute()]
219 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
220 | [global::System.Configuration.DefaultSettingValueAttribute("1")]
221 | public decimal RedshiftBrightnessDay {
222 | get {
223 | return ((decimal)(this["RedshiftBrightnessDay"]));
224 | }
225 | set {
226 | this["RedshiftBrightnessDay"] = value;
227 | }
228 | }
229 |
230 | [global::System.Configuration.UserScopedSettingAttribute()]
231 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
232 | [global::System.Configuration.DefaultSettingValueAttribute("1")]
233 | public decimal RedshiftBrightnessNight {
234 | get {
235 | return ((decimal)(this["RedshiftBrightnessNight"]));
236 | }
237 | set {
238 | this["RedshiftBrightnessNight"] = value;
239 | }
240 | }
241 |
242 | [global::System.Configuration.UserScopedSettingAttribute()]
243 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
244 | [global::System.Configuration.DefaultSettingValueAttribute("1")]
245 | public decimal RedshiftGammaRed {
246 | get {
247 | return ((decimal)(this["RedshiftGammaRed"]));
248 | }
249 | set {
250 | this["RedshiftGammaRed"] = value;
251 | }
252 | }
253 |
254 | [global::System.Configuration.UserScopedSettingAttribute()]
255 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
256 | [global::System.Configuration.DefaultSettingValueAttribute("1")]
257 | public decimal RedshiftGammaGreen {
258 | get {
259 | return ((decimal)(this["RedshiftGammaGreen"]));
260 | }
261 | set {
262 | this["RedshiftGammaGreen"] = value;
263 | }
264 | }
265 |
266 | [global::System.Configuration.UserScopedSettingAttribute()]
267 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
268 | [global::System.Configuration.DefaultSettingValueAttribute("1")]
269 | public decimal RedshiftGammaBlue {
270 | get {
271 | return ((decimal)(this["RedshiftGammaBlue"]));
272 | }
273 | set {
274 | this["RedshiftGammaBlue"] = value;
275 | }
276 | }
277 |
278 | [global::System.Configuration.UserScopedSettingAttribute()]
279 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
280 | [global::System.Configuration.DefaultSettingValueAttribute("False")]
281 | public bool RedshiftLocateOnStart {
282 | get {
283 | return ((bool)(this["RedshiftLocateOnStart"]));
284 | }
285 | set {
286 | this["RedshiftLocateOnStart"] = value;
287 | }
288 | }
289 | }
290 | }
291 |
--------------------------------------------------------------------------------