├── LGSTrayBattery_GHUB ├── Resources │ ├── Bat_10.ico │ ├── Bat_100.ico │ ├── Bat_25.ico │ ├── Bat_50.ico │ ├── Bat_75.ico │ ├── Unknown.ico │ ├── Discovery.ico │ └── logo_black.ico ├── FodyWeavers.xml ├── App.xaml.cs ├── App.xaml ├── Properties │ ├── Settings.settings │ ├── Settings.Designer.cs │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── GHUBMsg.cs ├── packages.config ├── App.config ├── BatteryToIcoConverter.cs ├── Device.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── HttpServer.cs ├── MainWindowViewModel.cs ├── FodyWeavers.xsd └── LGSTrayBattery_GHUB.csproj ├── LGSTrayBattery_GHUB.sln ├── readme.md ├── .gitattributes └── .gitignore /LGSTrayBattery_GHUB/Resources/Bat_10.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyvorld/LGSTrayBattery_GHUB/HEAD/LGSTrayBattery_GHUB/Resources/Bat_10.ico -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/Resources/Bat_100.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyvorld/LGSTrayBattery_GHUB/HEAD/LGSTrayBattery_GHUB/Resources/Bat_100.ico -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/Resources/Bat_25.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyvorld/LGSTrayBattery_GHUB/HEAD/LGSTrayBattery_GHUB/Resources/Bat_25.ico -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/Resources/Bat_50.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyvorld/LGSTrayBattery_GHUB/HEAD/LGSTrayBattery_GHUB/Resources/Bat_50.ico -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/Resources/Bat_75.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyvorld/LGSTrayBattery_GHUB/HEAD/LGSTrayBattery_GHUB/Resources/Bat_75.ico -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/Resources/Unknown.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyvorld/LGSTrayBattery_GHUB/HEAD/LGSTrayBattery_GHUB/Resources/Unknown.ico -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/Resources/Discovery.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyvorld/LGSTrayBattery_GHUB/HEAD/LGSTrayBattery_GHUB/Resources/Discovery.ico -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/Resources/logo_black.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyvorld/LGSTrayBattery_GHUB/HEAD/LGSTrayBattery_GHUB/Resources/logo_black.ico -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace LGSTrayBattery_GHUB 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/App.xaml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/GHUBMsg.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Newtonsoft.Json.Linq; 7 | 8 | namespace LGSTrayBattery_GHUB 9 | { 10 | struct GHUBMsg 11 | { 12 | #pragma warning disable 0649 13 | public string msgId; 14 | public string verb; 15 | public string path; 16 | public string origin; 17 | public JObject result; 18 | public JObject payload; 19 | #pragma warning restore 0649 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.1300 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LGSTrayBattery_GHUB", "LGSTrayBattery_GHUB\LGSTrayBattery_GHUB.csproj", "{B801C80E-7D9E-4424-A79C-030252477EE6}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {B801C80E-7D9E-4424-A79C-030252477EE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {B801C80E-7D9E-4424-A79C-030252477EE6}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {B801C80E-7D9E-4424-A79C-030252477EE6}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {B801C80E-7D9E-4424-A79C-030252477EE6}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {5177FA79-7DAC-4952-96F6-49490E4FB271} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/BatteryToIcoConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows.Data; 8 | 9 | namespace LGSTrayBattery_GHUB 10 | { 11 | class BatteryToIcoConverter : IValueConverter 12 | { 13 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 14 | { 15 | double batteryPercent = value is double d ? d : 0; 16 | 17 | if (batteryPercent >= 90) 18 | { 19 | return "/Resources/Bat_100.ico"; 20 | } 21 | else if (batteryPercent >= 65) 22 | { 23 | return "/Resources/Bat_75.ico"; 24 | } 25 | else if (batteryPercent >= 40) 26 | { 27 | return "/Resources/Bat_50.ico"; 28 | } 29 | else if (batteryPercent >= 15) 30 | { 31 | return "/Resources/Bat_25.ico"; 32 | } 33 | else if (batteryPercent < 15) 34 | { 35 | return "/Resources/Bat_10.ico"; 36 | } 37 | 38 | return "/Resources/Unknown.ico"; 39 | } 40 | 41 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 42 | { 43 | throw new NotImplementedException(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace LGSTrayBattery_GHUB.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.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 LastDeviceId { 30 | get { 31 | return ((string)(this["LastDeviceId"])); 32 | } 33 | set { 34 | this["LastDeviceId"] = value; 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## This is now considered depricated, LGSTrayBattery_GHUB has rolled into my other program [LGSTrayBattery](https://github.com/andyvorld/LGSTrayBattery)'s v2, a feature complete v2 release candidate is available. The repository is being archived on the full release of v2. 2 | 3 | --- 4 | 5 | # LGSTRayBattery_GHUB 6 | 7 | A tray app used to track battery levels of wireless Logitech **Gaming** devices. 8 | 9 | Requires Logitech G HUB running in the background. 10 | 11 | Created by reverse-engineering the websocket connection by `lghub_agent.exe`. 12 | 13 | ## Features 14 | ### Tray tooltips 15 | ![https://i.imgur.com/49XFDzb.png](https://i.imgur.com/49XFDzb.png) 16 | 17 | Tray battery level indicator and tooltip showing battery percentage. 18 | 19 | ### "HTTP" API 20 | By default the running of the http server is disabled, to enable modify `HttpConfig.ini` and change `serverEnable = false` to `serverEnable = true`. The IP address and port used for bindings are under `tcpAddr` and `tcpPort` respectively with the defaults being `localhost` and `12321`. 21 | 22 | `tcpAddr` accepts either a hostname (`DESKTOP-1234`) or an IP address (`127.0.0.1`) to bind to, if you are not sure use `localhost` or if you have admin permission `0.0.0.0` to allow for external access to the devices. If an invalid hostname is provided, the server will fall back to binding on `127.0.0.1`. 23 | 24 | ![https://i.imgur.com/haYJ0se.png](https://i.imgur.com/haYJ0se.png) 25 | 26 | Navigate to `{tcpAddr}:{tcpPort}/devices` for a list of connected devices. 27 | 28 | ![https://i.imgur.com/YrTRlYt.png](https://i.imgur.com/YrTRlYt.png) 29 | 30 | `{tcpAddr}:{tcpPort}/device/{device_id}` for an xml data set of the selected device. 31 | 32 | Provides additional info such as mileage (Hours left) and charging status. 33 | 34 | ## Working with 35 | - G403 - Mouse 36 | - G430 - Headset (Detects it properly, no battery) 37 | -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/Device.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using PropertyChanged; 8 | 9 | namespace LGSTrayBattery_GHUB 10 | { 11 | class Device : INotifyPropertyChanged 12 | { 13 | #pragma warning disable 0067 14 | public event PropertyChangedEventHandler PropertyChanged; 15 | #pragma warning restore 0067 16 | 17 | public string DeviceId { get; set; } 18 | public string DisplayName { get; set; } 19 | public double Percentage { get; set; } = double.NaN; 20 | public double Mileage { get; set; } = double.NaN; 21 | public bool Charging { get; set; } = false; 22 | 23 | [DependsOn("DisplayName", "Percentage", "Charging")] 24 | public string ToolTip 25 | { 26 | get 27 | { 28 | string output = $"{DisplayName}, {Percentage:f2}%"; 29 | 30 | if (!double.IsNaN(Percentage)) 31 | { 32 | output += Charging ? ", Charging" : ""; 33 | } 34 | 35 | return output; 36 | } 37 | } 38 | 39 | public bool IsChecked { get; set; } = false; 40 | 41 | public string ToXml() 42 | { 43 | string output = ""; 44 | output += "\n"; 45 | output += "\n"; 46 | output += $"{DeviceId}\n"; 47 | output += $"{DisplayName}\n"; 48 | output += $"{Percentage:f2}\n"; 49 | output += $"{Mileage:f2}\n"; 50 | output += $"{Charging}\n"; 51 | output += ""; 52 | 53 | return output; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/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 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | [assembly: AssemblyTitle("LGSTrayBattery_GHUB")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("")] 14 | [assembly: AssemblyProduct("LGSTrayBattery_GHUB")] 15 | [assembly: AssemblyCopyright("Copyright © 2020")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // Setting ComVisible to false makes the types in this assembly not visible 20 | // to COM components. If you need to access a type in this assembly from 21 | // COM, set the ComVisible attribute to true on that type. 22 | [assembly: ComVisible(false)] 23 | 24 | //In order to begin building localizable applications, set 25 | //CultureYouAreCodingWith in your .csproj file 26 | //inside a . For example, if you are using US english 27 | //in your source files, set the to en-US. Then uncomment 28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 29 | //the line below to match the UICulture setting in the project file. 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 36 | //(used if a resource is not found in the page, 37 | // or application resource dictionaries) 38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 39 | //(used if a resource is not found in the page, 40 | // app, or any theme specific resource dictionaries) 41 | )] 42 | 43 | 44 | // Version information for an assembly consists of the following four values: 45 | // 46 | // Major Version 47 | // Minor Version 48 | // Build Number 49 | // Revision 50 | // 51 | // You can specify all the values or you can default the Build and Revision Numbers 52 | // by using the '*' as shown below: 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.0.0")] 55 | [assembly: AssemblyFileVersion("1.0.0.0")] 56 | -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/MainWindow.xaml: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Globalization; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows; 10 | using System.Windows.Controls; 11 | using System.Windows.Data; 12 | using System.Windows.Documents; 13 | using System.Windows.Input; 14 | using System.Windows.Media; 15 | using System.Windows.Media.Imaging; 16 | using System.Windows.Navigation; 17 | using System.Windows.Shapes; 18 | 19 | namespace LGSTrayBattery_GHUB 20 | { 21 | /// 22 | /// Interaction logic for MainWindow.xaml 23 | /// 24 | public partial class MainWindow : Window 25 | { 26 | private readonly MainWindowViewModel _viewModel; 27 | 28 | public MainWindow() 29 | { 30 | InitializeComponent(); 31 | _viewModel = new MainWindowViewModel(); 32 | this.DataContext = _viewModel; 33 | 34 | this.TrayIcon.Icon = Properties.Resources.Discovery; 35 | 36 | #if !DEBUG 37 | AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; 38 | #endif 39 | } 40 | 41 | private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs msg) 42 | { 43 | Exception ex = msg.ExceptionObject as Exception; 44 | string crashFileName = "./CrashLog_" + DateTime.Now.ToString("yyyyMMddHHmmss"); 45 | using (StreamWriter writer = new StreamWriter(crashFileName, false)) 46 | { 47 | writer.WriteLine("-----------------------------------------------------------------------------"); 48 | writer.WriteLine("Date : " + DateTime.Now.ToString(CultureInfo.InvariantCulture)); 49 | 50 | while (ex != null) 51 | { 52 | writer.WriteLine("-----------------------------------------------------------------------------"); 53 | writer.WriteLine(ex.GetType().FullName); 54 | writer.WriteLine("Message :"); 55 | writer.WriteLine(ex.Message); 56 | writer.WriteLine("StackTrace :"); 57 | writer.WriteLine(ex.StackTrace); 58 | writer.WriteLine(); 59 | 60 | ex = ex.InnerException; 61 | } 62 | } 63 | } 64 | 65 | private void DeviceSelect_OnClick(object sender, RoutedEventArgs e) 66 | { 67 | MenuItem menuItem = (MenuItem)sender; 68 | 69 | _viewModel.UpdateSelectedDevice((Device)menuItem.DataContext); 70 | } 71 | 72 | private void RescanDevices(object sender, RoutedEventArgs e) 73 | { 74 | _viewModel.ScanDevices(); 75 | } 76 | 77 | private void ExitButton_OnClick(object sender, RoutedEventArgs e) 78 | { 79 | Environment.Exit(0); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace LGSTrayBattery_GHUB.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | public 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 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | public 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("LGSTrayBattery_GHUB.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | public static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). 65 | /// 66 | public static System.Drawing.Icon Bat_10 { 67 | get { 68 | object obj = ResourceManager.GetObject("Bat_10", resourceCulture); 69 | return ((System.Drawing.Icon)(obj)); 70 | } 71 | } 72 | 73 | /// 74 | /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). 75 | /// 76 | public static System.Drawing.Icon Bat_100 { 77 | get { 78 | object obj = ResourceManager.GetObject("Bat_100", resourceCulture); 79 | return ((System.Drawing.Icon)(obj)); 80 | } 81 | } 82 | 83 | /// 84 | /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). 85 | /// 86 | public static System.Drawing.Icon Bat_25 { 87 | get { 88 | object obj = ResourceManager.GetObject("Bat_25", resourceCulture); 89 | return ((System.Drawing.Icon)(obj)); 90 | } 91 | } 92 | 93 | /// 94 | /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). 95 | /// 96 | public static System.Drawing.Icon Bat_50 { 97 | get { 98 | object obj = ResourceManager.GetObject("Bat_50", resourceCulture); 99 | return ((System.Drawing.Icon)(obj)); 100 | } 101 | } 102 | 103 | /// 104 | /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). 105 | /// 106 | public static System.Drawing.Icon Bat_75 { 107 | get { 108 | object obj = ResourceManager.GetObject("Bat_75", resourceCulture); 109 | return ((System.Drawing.Icon)(obj)); 110 | } 111 | } 112 | 113 | /// 114 | /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). 115 | /// 116 | public static System.Drawing.Icon Discovery { 117 | get { 118 | object obj = ResourceManager.GetObject("Discovery", resourceCulture); 119 | return ((System.Drawing.Icon)(obj)); 120 | } 121 | } 122 | 123 | /// 124 | /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). 125 | /// 126 | public static System.Drawing.Icon logo_black { 127 | get { 128 | object obj = ResourceManager.GetObject("logo_black", resourceCulture); 129 | return ((System.Drawing.Icon)(obj)); 130 | } 131 | } 132 | 133 | /// 134 | /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). 135 | /// 136 | public static System.Drawing.Icon Unknown { 137 | get { 138 | object obj = ResourceManager.GetObject("Unknown", resourceCulture); 139 | return ((System.Drawing.Icon)(obj)); 140 | } 141 | } 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/HttpServer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Net; 7 | using System.Net.Sockets; 8 | using System.Text; 9 | using System.Text.RegularExpressions; 10 | using System.Threading.Tasks; 11 | using IniParser; 12 | using IniParser.Model; 13 | 14 | namespace LGSTrayBattery_GHUB 15 | { 16 | class HttpServer 17 | { 18 | public static bool ServerEnabled; 19 | private static string _tcpAddr; 20 | private static int _tcpPort; 21 | private static bool _loaded = false; 22 | 23 | public static void LoadConfig() 24 | { 25 | var parser = new FileIniDataParser(); 26 | 27 | if (!File.Exists("./HttpConfig.ini")) 28 | { 29 | File.Create("./HttpConfig.ini").Close(); 30 | } 31 | 32 | IniData data = parser.ReadFile("./HttpConfig.ini"); 33 | 34 | if (!bool.TryParse(data["HTTPServer"]["serverEnable"], out ServerEnabled)) 35 | { 36 | data["HTTPServer"]["serverEnable"] = "false"; 37 | } 38 | 39 | if (!int.TryParse(data["HTTPServer"]["tcpPort"], out _tcpPort)) 40 | { 41 | data["HTTPServer"]["tcpPort"] = "12321"; 42 | } 43 | 44 | _tcpAddr = data["HTTPServer"]["tcpAddr"]; 45 | if (_tcpAddr == null) 46 | { 47 | data["HTTPServer"]["tcpAddr"] = "localhost"; 48 | } 49 | 50 | parser.WriteFile("./HttpConfig.ini", data); 51 | } 52 | 53 | public static void ServerLoop(MainWindowViewModel viewModel) 54 | { 55 | if (!_loaded) 56 | { 57 | LoadConfig(); 58 | } 59 | 60 | if (!ServerEnabled) 61 | { 62 | return; 63 | } 64 | 65 | Debug.WriteLine("\nHttp Server starting"); 66 | 67 | IPAddress ipAddress; 68 | if (!IPAddress.TryParse(_tcpAddr, out ipAddress)) 69 | { 70 | try 71 | { 72 | IPHostEntry host = Dns.GetHostEntry(_tcpAddr); 73 | ipAddress = host.AddressList[0]; 74 | } 75 | catch (SocketException) 76 | { 77 | Debug.WriteLine("Invalid hostname, defaulting to loopback"); 78 | ipAddress = IPAddress.Loopback; 79 | } 80 | 81 | } 82 | 83 | IPEndPoint localEndPoint = new IPEndPoint(ipAddress, _tcpPort); 84 | 85 | Socket listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); 86 | listener.Bind(localEndPoint); 87 | listener.Listen(10); 88 | 89 | Debug.WriteLine($"Http Server listening on {localEndPoint}\n"); 90 | 91 | while (true) 92 | { 93 | using (Socket client = listener.Accept()) 94 | { 95 | try 96 | { 97 | var bytes = new byte[1024]; 98 | var bytesRec = client.Receive(bytes); 99 | 100 | string httpRequest = Encoding.ASCII.GetString(bytes, 0, bytesRec); 101 | 102 | var matches = Regex.Match(httpRequest, @"GET (.+?) HTTP\/[0-9\.]+"); 103 | if (matches.Groups.Count > 0) 104 | { 105 | int statusCode = 400; 106 | string contentType = "text"; 107 | string content = ""; 108 | 109 | string[] request = matches.Groups[1].ToString() 110 | .Split(new string[] {"/"}, StringSplitOptions.RemoveEmptyEntries); 111 | string rootRequest = request.Length > 0 ? request[0] : ""; 112 | 113 | if (rootRequest == "devices") 114 | { 115 | statusCode = 200; 116 | contentType = "text/html"; 117 | content = ""; 118 | 119 | foreach (var device in viewModel.DeviceList) 120 | { 121 | content += 122 | $"{device.DisplayName} : {device.DeviceId}
"; 123 | } 124 | 125 | content += ""; 126 | } 127 | else if (rootRequest == "device") 128 | { 129 | string deviceId = request.Length > 1 ? request[1] : ""; 130 | Device targetDevice = viewModel.DeviceList.FirstOrDefault(x => x.DeviceId == deviceId); 131 | 132 | if (targetDevice == null) 133 | { 134 | statusCode = 404; 135 | content = $"Device not found, ID = {request[1]}"; 136 | } 137 | else 138 | { 139 | statusCode = 200; 140 | content = targetDevice.ToXml(); 141 | contentType = "text/xml"; 142 | } 143 | } 144 | 145 | string response = $"HTTP/1.1 {statusCode}\r\n" + 146 | $"Content-Type: {contentType}\r\n" + 147 | $"Access-Control-Allow-Origin: *\r\n" + 148 | $"Cache-Control: no-store, must-revalidate\r\n" + 149 | $"Pragma: no-cache\r\n" + 150 | $"Expires: 0\r\n" + 151 | $"\r\n{content}"; 152 | 153 | client.Send(Encoding.ASCII.GetBytes(response)); 154 | } 155 | } 156 | catch (Exception ex) 157 | { 158 | #if DEBUG 159 | throw ex; 160 | #endif 161 | 162 | StringBuilder sb = new StringBuilder(); 163 | 164 | while (ex != null) 165 | { 166 | sb.AppendLine("-----------------------------------------------------------------------------"); 167 | sb.AppendLine(ex.GetType().FullName); 168 | sb.AppendLine("Message :"); 169 | sb.AppendLine(ex.Message); 170 | sb.AppendLine("StackTrace :"); 171 | sb.AppendLine(ex.StackTrace); 172 | sb.AppendLine(); 173 | 174 | ex = ex.InnerException; 175 | } 176 | 177 | string response = $"HTTP/1.1 400\r\n" + 178 | $"Content-Type: text\r\n" + 179 | $"Access-Control-Allow-Origin: *\r\n" + 180 | $"Cache-Control: no-store, must-revalidate\r\n" + 181 | $"Pragma: no-cache\r\n" + 182 | $"Expires: 0\r\n" + 183 | $"\r\n{sb}"; 184 | 185 | client.Send(Encoding.ASCII.GetBytes(response)); 186 | } 187 | } 188 | } 189 | // ReSharper disable once FunctionNeverReturns 190 | } 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/MainWindowViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | using System.Collections.Specialized; 5 | using System.ComponentModel; 6 | using System.Diagnostics; 7 | using System.Linq; 8 | using System.Net.WebSockets; 9 | using System.Reflection; 10 | using System.Text; 11 | using System.Text.RegularExpressions; 12 | using System.Threading; 13 | using System.Threading.Tasks; 14 | using LGSTrayBattery_GHUB.Properties; 15 | using Microsoft.Win32; 16 | using Newtonsoft.Json; 17 | using Newtonsoft.Json.Linq; 18 | using Websocket.Client; 19 | using Websocket.Client.Exceptions; 20 | 21 | namespace LGSTrayBattery_GHUB 22 | { 23 | class MainWindowViewModel : INotifyPropertyChanged, INotifyCollectionChanged 24 | { 25 | public event PropertyChangedEventHandler PropertyChanged; 26 | public event NotifyCollectionChangedEventHandler CollectionChanged; 27 | 28 | private WebsocketClient _ws = null; 29 | 30 | public Device SelectedDevice { get; set; } = null; 31 | 32 | private Dictionary _devIdNameMap; 33 | public List DeviceList { get; private set; } 34 | 35 | private Thread _httpServer; 36 | 37 | private bool? _autoStart = null; 38 | public bool AutoStart 39 | { 40 | get 41 | { 42 | if (_autoStart == null) 43 | { 44 | RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); 45 | _autoStart = registryKey?.GetValue("LGSTrayBattery_GHUB") != null; 46 | } 47 | 48 | return _autoStart ?? false; 49 | } 50 | set 51 | { 52 | RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); 53 | 54 | if (value) 55 | { 56 | registryKey.SetValue("LGSTrayBattery_GHUB", Assembly.GetEntryAssembly().Location); 57 | } 58 | else 59 | { 60 | registryKey.DeleteValue("LGSTrayBattery_GHUB", false); 61 | } 62 | 63 | _autoStart = value; 64 | } 65 | } 66 | 67 | public MainWindowViewModel() 68 | { 69 | ConnectToGHUB_async(); 70 | 71 | _httpServer = new Thread(() => HttpServer.ServerLoop(this)); 72 | _httpServer.Start(); 73 | } 74 | 75 | public async void ConnectToGHUB_async() 76 | { 77 | var url = new Uri("ws://localhost:9010"); 78 | 79 | var factory = new Func(() => 80 | { 81 | var client = new ClientWebSocket(); 82 | client.Options.UseDefaultCredentials = false; 83 | client.Options.SetRequestHeader("Origin", "file://"); 84 | client.Options.SetRequestHeader("Pragma", "no-cache"); 85 | client.Options.SetRequestHeader("Cache-Control", "no-cache"); 86 | client.Options.SetRequestHeader("Sec-WebSocket-Extensions", "permessage-deflate; client_max_window_bits"); 87 | client.Options.SetRequestHeader("Sec-WebSocket-Protocol", "json"); 88 | return client; 89 | }); 90 | 91 | _ws?.Dispose(); 92 | _ws = new WebsocketClient(url, factory); 93 | _ws.MessageReceived.Subscribe(ParseSocketMsg); 94 | _ws.ErrorReconnectTimeout = TimeSpan.FromMilliseconds(500); 95 | _ws.ReconnectTimeout = null; 96 | 97 | Console.WriteLine($"Trying to connect to LGHUB_agent, at {url}"); 98 | 99 | while (!_ws.IsRunning) 100 | { 101 | await _ws.Start(); 102 | } 103 | 104 | Console.WriteLine($"Connected to LGHUB_agent"); 105 | 106 | _ws.Send(JsonConvert.SerializeObject(new 107 | { 108 | msgId = "", 109 | verb = "SUBSCRIBE", 110 | path = "/devices/state/changed" 111 | })); 112 | 113 | _ws.Send(JsonConvert.SerializeObject(new 114 | { 115 | msgId = "", 116 | verb = "SUBSCRIBE", 117 | path = "/battery/state/changed" 118 | })); 119 | 120 | ScanDevices(); 121 | } 122 | 123 | public void UpdateSelectedDevice(Device selectedDevice) 124 | { 125 | foreach (var device in DeviceList) 126 | { 127 | device.IsChecked = false; 128 | } 129 | 130 | SelectedDevice = selectedDevice; 131 | SelectedDevice.IsChecked = true; 132 | 133 | Settings.Default.LastDeviceId = SelectedDevice.DeviceId; 134 | Settings.Default.Save(); 135 | } 136 | 137 | public void ScanDevices() 138 | { 139 | _ws.Send(JsonConvert.SerializeObject(new 140 | { 141 | msgId = "", 142 | verb = "GET", 143 | path = "/devices/list" 144 | })); 145 | } 146 | 147 | private void ParseSocketMsg(ResponseMessage msg) 148 | { 149 | GHUBMsg ghubmsg = JsonConvert.DeserializeObject(msg.Text); 150 | 151 | if (ghubmsg.path == "/devices/state/changed") 152 | { 153 | ScanDevices(); 154 | } 155 | else if (ghubmsg.path == "/devices/list") 156 | { 157 | LoadDevices(ghubmsg.payload); 158 | } 159 | //else if (ghubmsg.path.StartsWith("/battery_state/")) 160 | else if (Regex.IsMatch(ghubmsg.path, @"\/battery\/dev[0-9]+\/state")) 161 | { 162 | if (ghubmsg.result["code"]?.ToString() == "SUCCESS") 163 | { 164 | UpdateBattery(ghubmsg.payload); 165 | } 166 | } 167 | else if (ghubmsg.path == "/battery/state/changed") 168 | { 169 | UpdateBattery(ghubmsg.payload); 170 | } 171 | else 172 | { 173 | } 174 | Debug.WriteLine(msg); 175 | } 176 | 177 | private void LoadDevices(JObject payload) 178 | { 179 | _devIdNameMap = new Dictionary(); 180 | List temp = new List(); 181 | 182 | foreach (var deviceToken in payload["deviceInfos"]) 183 | { 184 | Device device = new Device() 185 | { 186 | DeviceId = deviceToken["id"].ToString(), 187 | DisplayName = deviceToken["extendedDisplayName"].ToString() 188 | }; 189 | 190 | _devIdNameMap.Add(deviceToken["id"].ToString(), device); 191 | temp.Add(device); 192 | } 193 | 194 | DeviceList = temp; 195 | 196 | RefreshBattery(); 197 | 198 | SelectedDevice = DeviceList.SingleOrDefault(x => x.DeviceId == Settings.Default.LastDeviceId) ?? DeviceList.First(); 199 | 200 | SelectedDevice.IsChecked = true; 201 | } 202 | 203 | private void RefreshBattery() 204 | { 205 | foreach (var device in DeviceList) 206 | { 207 | _ws.Send(JsonConvert.SerializeObject(new 208 | { 209 | msgId = "", 210 | verb = "GET", 211 | path = $"/battery/{device.DeviceId}/state" 212 | })); 213 | } 214 | } 215 | 216 | private void UpdateBattery(JObject payload) 217 | { 218 | var device = _devIdNameMap[payload["deviceId"].ToString()]; 219 | 220 | device.Percentage = payload["percentage"].ToObject(); 221 | device.Mileage = payload["mileage"].ToObject(); 222 | device.Charging = payload["charging"].ToObject(); 223 | } 224 | } 225 | } 226 | -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/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\Bat_10.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 123 | 124 | 125 | ..\Resources\Bat_100.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 126 | 127 | 128 | ..\Resources\Bat_25.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 129 | 130 | 131 | ..\Resources\Bat_50.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 132 | 133 | 134 | ..\Resources\Bat_75.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 135 | 136 | 137 | ..\Resources\Discovery.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 138 | 139 | 140 | ..\Resources\logo_black.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 141 | 142 | 143 | ..\Resources\Unknown.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 144 | 145 | -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/FodyWeavers.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Used to control if the On_PropertyName_Changed feature is enabled. 12 | 13 | 14 | 15 | 16 | Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form. 17 | 18 | 19 | 20 | 21 | Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project. 22 | 23 | 24 | 25 | 26 | Used to control if equality checks should use the Equals method resolved from the base class. 27 | 28 | 29 | 30 | 31 | Used to control if equality checks should use the static Equals method resolved from the base class. 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks 42 | 43 | 44 | 45 | 46 | A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks. 47 | 48 | 49 | 50 | 51 | A list of unmanaged 32 bit assembly names to include, delimited with line breaks. 52 | 53 | 54 | 55 | 56 | A list of unmanaged 64 bit assembly names to include, delimited with line breaks. 57 | 58 | 59 | 60 | 61 | The order of preloaded assemblies, delimited with line breaks. 62 | 63 | 64 | 65 | 66 | 67 | This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file. 68 | 69 | 70 | 71 | 72 | Controls if .pdbs for reference assemblies are also embedded. 73 | 74 | 75 | 76 | 77 | Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option. 78 | 79 | 80 | 81 | 82 | As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off. 83 | 84 | 85 | 86 | 87 | Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code. 88 | 89 | 90 | 91 | 92 | Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior. 93 | 94 | 95 | 96 | 97 | A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with | 98 | 99 | 100 | 101 | 102 | A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |. 103 | 104 | 105 | 106 | 107 | A list of unmanaged 32 bit assembly names to include, delimited with |. 108 | 109 | 110 | 111 | 112 | A list of unmanaged 64 bit assembly names to include, delimited with |. 113 | 114 | 115 | 116 | 117 | The order of preloaded assemblies, delimited with |. 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. 126 | 127 | 128 | 129 | 130 | A comma-separated list of error codes that can be safely ignored in assembly verification. 131 | 132 | 133 | 134 | 135 | 'false' to turn off automatic generation of the XML Schema file. 136 | 137 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /LGSTrayBattery_GHUB/LGSTrayBattery_GHUB.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Debug 8 | AnyCPU 9 | {B801C80E-7D9E-4424-A79C-030252477EE6} 10 | WinExe 11 | LGSTrayBattery_GHUB 12 | LGSTrayBattery_GHUB 13 | v4.7.2 14 | 512 15 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 16 | 4 17 | true 18 | true 19 | 20 | 21 | 22 | 23 | AnyCPU 24 | true 25 | full 26 | false 27 | bin\Debug\ 28 | DEBUG;TRACE 29 | prompt 30 | 4 31 | 32 | 33 | AnyCPU 34 | pdbonly 35 | true 36 | bin\Release\ 37 | TRACE 38 | prompt 39 | 4 40 | 41 | 42 | 43 | 44 | 45 | Resources\logo_black.ico 46 | 47 | 48 | 49 | ..\packages\Costura.Fody.3.3.3\lib\net40\Costura.dll 50 | 51 | 52 | ..\packages\Hardcodet.NotifyIcon.Wpf.1.0.8\lib\net451\Hardcodet.Wpf.TaskbarNotification.dll 53 | 54 | 55 | ..\packages\ini-parser.2.5.2\lib\net20\INIFileParser.dll 56 | 57 | 58 | ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll 59 | 60 | 61 | ..\packages\PropertyChanged.Fody.2.6.1\lib\net452\PropertyChanged.dll 62 | 63 | 64 | 65 | 66 | 67 | ..\packages\System.Reactive.4.3.2\lib\net46\System.Reactive.dll 68 | 69 | 70 | ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll 71 | 72 | 73 | ..\packages\System.Threading.Channels.4.7.0\lib\netstandard2.0\System.Threading.Channels.dll 74 | 75 | 76 | ..\packages\System.Threading.Tasks.Extensions.4.5.3\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll 77 | 78 | 79 | ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 4.0 91 | 92 | 93 | ..\packages\Websocket.Client.4.3.21\lib\netstandard2.0\Websocket.Client.dll 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | MSBuild:Compile 102 | Designer 103 | 104 | 105 | MSBuild:Compile 106 | Designer 107 | 108 | 109 | App.xaml 110 | Code 111 | 112 | 113 | 114 | 115 | 116 | 117 | MainWindow.xaml 118 | Code 119 | 120 | 121 | 122 | 123 | 124 | Code 125 | 126 | 127 | True 128 | True 129 | Resources.resx 130 | 131 | 132 | True 133 | Settings.settings 134 | True 135 | 136 | 137 | PublicResXFileCodeGenerator 138 | Resources.Designer.cs 139 | 140 | 141 | 142 | SettingsSingleFileGenerator 143 | Settings.Designer.cs 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | PreserveNewest 155 | 156 | 157 | 158 | 159 | PreserveNewest 160 | 161 | 162 | 163 | 164 | PreserveNewest 165 | 166 | 167 | 168 | 169 | PreserveNewest 170 | 171 | 172 | 173 | 174 | PreserveNewest 175 | 176 | 177 | 178 | 179 | PreserveNewest 180 | 181 | 182 | 183 | 184 | PreserveNewest 185 | 186 | 187 | 188 | 189 | PreserveNewest 190 | 191 | 192 | 193 | 194 | 195 | 196 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 197 | 198 | 199 | 200 | 201 | 202 | 203 | cd$(OutDir) 204 | del *.xml 205 | 206 | --------------------------------------------------------------------------------