Skip to content
This repository has been archived by the owner on Nov 13, 2020. It is now read-only.

Commit

Permalink
Fix issue #29
Browse files Browse the repository at this point in the history
  • Loading branch information
etnguyen03 committed Nov 27, 2017
1 parent cbf0f9e commit 195f38c
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions LaptopAlarm/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public partial class Form1 : Form
private Form2 alarmForm = new Form2("There is no alarm. Something has gone wrong. Please file a bug report at https://github.com/etnguyen03/LaptopAlarm/issues. Thanks!");
public CoreAudioDevice playbackDevice = new CoreAudioController().DefaultPlaybackDevice;
private RegistryKey regKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
private bool initAlarmChecked = false; // variable that stores if the restartalarm check was carried out or not

// arm keyboard shortcut variables
Keys arm_key = Keys.A;
Expand Down Expand Up @@ -101,6 +102,24 @@ private void Form1_Load(object sender, EventArgs e)
}

protected override void SetVisibleCore(bool value)
{
if (allowVisible == false)
{
value = false;
if (!this.IsHandleCreated)
{
CreateHandle();
}
}
if (initAlarmChecked == false)
{
programLoad();
initAlarmChecked = true;
}
base.SetVisibleCore(value);
}

private void programLoad()
{
// Program load:
myAlarm = new Alarm(Properties.Settings.Default.onalarm_audio, Properties.Settings.Default.onalarm_audio_default, Properties.Settings.Default.CustomAudioFilePath, Properties.Settings.Default.onalarm_audio_volincrease);
Expand All @@ -112,15 +131,6 @@ protected override void SetVisibleCore(bool value)

HotKeyManager.HotKeyPressed += HotKeyManager_HotKeyPressed;

if (allowVisible == false)
{
value = false;
if (!this.IsHandleCreated)
{
CreateHandle();
}
}

workerPowerThread = new Thread(new ThreadStart(monitorPower));
workerVolThread = new Thread(new ThreadStart(setVolume));

Expand All @@ -140,7 +150,7 @@ protected override void SetVisibleCore(bool value)
workerPowerThread.Abort();
}
else
{
{
// Trigger the alarm if alarmarmed.txt exists and the setting is enabled
if (File.Exists(Path.GetDirectoryName(Application.ExecutablePath) + "\\alarmarmed.txt"))
{
Expand All @@ -159,7 +169,7 @@ protected override void SetVisibleCore(bool value)
workerPowerThread.Abort();
}
else
{
{
// arm the alarm
// if changing this area, change it in the keyboard shortcut too
alarmArmed = true;
Expand All @@ -182,12 +192,9 @@ protected override void SetVisibleCore(bool value)
workerBatThread = new Thread(new ThreadStart(monitorBattery));
workerBatThread.Start();
}
}
}
}
}


base.SetVisibleCore(value);
}
}

// hotkey pressed
Expand Down

0 comments on commit 195f38c

Please sign in to comment.