Skip to content

Commit 2a52aa1

Browse files
committed
Fix logoff sound not playing
SystemEvents.SessionEnded is too late. FormClosing seems to work a lot better. Unsubscribe SystemEvents.SessionSwitch since the documentation states that one should do so. Give the form an icon and a title bar text so when the shutdown block reason is shown, the user sees what program it's from.
1 parent 259e422 commit 2a52aa1

File tree

4 files changed

+424
-23
lines changed

4 files changed

+424
-23
lines changed

src/soundrestore/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
[assembly: AssemblyCopyright("Copyright © TAKEMURA Kiriko 2020")]
1111
[assembly: ComVisible(false)]
1212
[assembly: Guid("b3839d3a-3aec-4b0f-bad1-587d521bbf8e")]
13-
[assembly: AssemblyVersion("1.0.0.0")]
14-
[assembly: AssemblyFileVersion("1.0.0.0")]
13+
[assembly: AssemblyVersion("1.1.0.0")]
14+
[assembly: AssemblyFileVersion("1.1.0.0")]

src/soundrestore/DummyForm.Designer.cs

Lines changed: 4 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/soundrestore/DummyForm.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,23 @@ public DummyForm()
7171
{
7272
InitializeComponent();
7373

74-
SystemEvents.SessionEnded += new SessionEndedEventHandler(SystemEvents_SessionEnded);
7574
SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch);
7675
}
7776

78-
private void DummyForm_Shown(object sender, EventArgs e)
77+
protected override void Dispose(bool disposing)
7978
{
80-
Hide();
81-
Play(Sound.Logon);
79+
if (disposing && (components != null))
80+
{
81+
SystemEvents.SessionSwitch -= SystemEvents_SessionSwitch;
82+
components.Dispose();
83+
}
84+
base.Dispose(disposing);
8285
}
8386

84-
private void SystemEvents_SessionEnded(object sender, SessionEndedEventArgs e)
87+
private void DummyForm_Shown(object sender, EventArgs e)
8588
{
86-
ShutdownBlockReasonCreate(this.Handle, "Playing shutdown sound");
87-
Play(Sound.Logoff);
88-
ShutdownBlockReasonDestroy(this.Handle);
89+
Hide();
90+
Play(Sound.Logon);
8991
}
9092

9193
private void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
@@ -138,5 +140,15 @@ private void Play(Sound what)
138140
"Cannot play system sound: {0}", e), EventLogEntryType.Error);
139141
}
140142
}
143+
144+
private void DummyForm_FormClosing(object sender, FormClosingEventArgs e)
145+
{
146+
if (e.CloseReason != CloseReason.WindowsShutDown)
147+
return;
148+
149+
ShutdownBlockReasonCreate(this.Handle, "Playing shutdown sound");
150+
Play(Sound.Logoff);
151+
ShutdownBlockReasonDestroy(this.Handle);
152+
}
141153
}
142154
}

0 commit comments

Comments
 (0)