Skip to content

Commit

Permalink
通知領域アイコン設定, 自動終了実装
Browse files Browse the repository at this point in the history
  • Loading branch information
nnm-t committed Jun 11, 2019
1 parent d8042d0 commit 57164d3
Show file tree
Hide file tree
Showing 8 changed files with 338 additions and 212 deletions.
16 changes: 10 additions & 6 deletions PowerCfgToggle/App.xaml.cs
@@ -1,26 +1,30 @@
using System.Threading;
using System;
using System.Threading.Tasks;
using System.Windows;

namespace PowerCfgToggle
{
using System.Windows;

/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App
{
private NotifyIcon notifyIcon = new NotifyIcon();
private readonly NotifyIcon notifyIcon = new NotifyIcon();

protected override void OnStartup(StartupEventArgs e)
protected override async void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

ShutdownMode = ShutdownMode.OnExplicitShutdown;

var powerConfig = new PowerConfig();

notifyIcon.Popup("Power Config Toggle", powerConfig.Execute());

notifyIcon.Popup("電源設定", powerConfig.Execute());

await Task.Delay(TimeSpan.FromSeconds(5));

Current.Shutdown();
}

protected override void OnExit(ExitEventArgs e)
Expand Down
16 changes: 9 additions & 7 deletions PowerCfgToggle/NotifyIcon.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions PowerCfgToggle/NotifyIcon.cs
@@ -1,5 +1,4 @@
using System.ComponentModel;
using PowerCfgToggle.Properties;

namespace PowerCfgToggle
{
Expand All @@ -11,7 +10,10 @@ public NotifyIcon()
{
InitializeComponent();

this.toolStripMenuItemExitApp.Click += (sender, e) => { Application.Current.Shutdown(); };
toolStripMenuItemExitApp.Click += Shutdown;

myNotifyIcon.BalloonTipClicked += Shutdown;
myNotifyIcon.BalloonTipClosed += Shutdown;
}

public NotifyIcon(IContainer container)
Expand All @@ -28,5 +30,10 @@ public void Popup(string title, string text)

myNotifyIcon.ShowBalloonTip(1000);
}

private void Shutdown<T>(object sender, T e)
{
Application.Current.Shutdown();
}
}
}
303 changes: 299 additions & 4 deletions PowerCfgToggle/NotifyIcon.resx

Large diffs are not rendered by default.

16 changes: 7 additions & 9 deletions PowerCfgToggle/PowerCfgToggle.csproj
Expand Up @@ -69,21 +69,19 @@
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<EmbeddedResource Include="NotifyIcon.resx">
<DependentUpon>NotifyIcon.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\battery-16.png" />
<None Include="Resources\battery-24.png" />
<None Include="Resources\battery-32.png" />
<None Include="Resources\battery-48.png" />
<Resource Include="Resources\battery.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
8 changes: 4 additions & 4 deletions PowerCfgToggle/Properties/AssemblyInfo.cs
Expand Up @@ -8,11 +8,11 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PowerCfgToggle")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("powercfg.exe Toggle Application.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PowerCfgToggle")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyCompany("Hon Nam Yuu Tee Nai")]
[assembly: AssemblyProduct("Power Config Toggle")]
[assembly: AssemblyCopyright("Copyright © 2019 Noname Kamisawa")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
63 changes: 0 additions & 63 deletions PowerCfgToggle/Properties/Resources.Designer.cs

This file was deleted.

117 changes: 0 additions & 117 deletions PowerCfgToggle/Properties/Resources.resx

This file was deleted.

0 comments on commit 57164d3

Please sign in to comment.