Skip to content

Commit 990c0c5

Browse files
committed
reorganize the browser exit code into the WebBrowserMode class
1 parent 781feb0 commit 990c0c5

2 files changed

Lines changed: 23 additions & 25 deletions

File tree

FlashpointSecurePlayer/FlashpointSecurePlayerGUI.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public partial class FlashpointSecurePlayerGUI : Form {
4040
private readonly bool oldWindowsVersion = Environment.OSVersion.Version < new Version(6, 1);
4141

4242
private bool activeX = false;
43-
private bool webBrowserModeExiting = false;
4443
private ProcessStartInfo softwareProcessStartInfo = null;
4544
private bool softwareIsOldCPUSimulator = false;
4645

@@ -810,15 +809,7 @@ private void DeactivateMode(TemplateElement templateElement, ErrorDelegate error
810809
}
811810

812811
try {
813-
webBrowserModeExiting = true;
814-
815-
IList<WebBrowserMode> webBrowserModes = WebBrowserMode.WebBrowserModes;
816-
817-
if (webBrowserModes != null) {
818-
for (int i = 0; i < webBrowserModes.Count; i++) {
819-
webBrowserModes[i].Close();
820-
}
821-
}
812+
WebBrowserMode.DeactivateMode();
822813
} finally {
823814
modeMutex.ReleaseMutex();
824815
}
@@ -1255,12 +1246,6 @@ private void ImportStop(object sender, EventArgs e) {
12551246
}
12561247

12571248
private void WebBrowserModeExit(object sender, EventArgs e) {
1258-
if (webBrowserModeExiting) {
1259-
return;
1260-
}
1261-
1262-
webBrowserModeExiting = true;
1263-
12641249
// Set Current Directory
12651250
try {
12661251
Directory.SetCurrentDirectory(Application.StartupPath);

FlashpointSecurePlayer/WebBrowserMode.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -382,15 +382,6 @@ protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e) {
382382

383383
static private List<WebBrowserMode> webBrowserModes = new List<WebBrowserMode>() { };
384384

385-
static public IList<WebBrowserMode> WebBrowserModes {
386-
get {
387-
if (webBrowserModes == null) {
388-
return null;
389-
}
390-
return webBrowserModes.AsReadOnly();
391-
}
392-
}
393-
394385
private readonly EventHandler webBrowserModeExit;
395386

396387
private Uri WebBrowserURL { get; set; } = null;
@@ -443,6 +434,21 @@ private void OnWebBrowserModeExit(EventArgs e) {
443434
eventHandler(this, e);
444435
}
445436

437+
static private bool exiting = false;
438+
439+
static public void DeactivateMode() {
440+
// if we are here, we don't want the OnWebBrowserModeExit event to fire
441+
// that would cause recursion, because the mode would be deactivated again
442+
// instead, we handle the exit ourselves
443+
exiting = true;
444+
445+
if (webBrowserModes != null) {
446+
for (int i = 0; i < webBrowserModes.Count; i++) {
447+
webBrowserModes[i].Close();
448+
}
449+
}
450+
}
451+
446452
private bool addressToolStripSpringTextBoxEntered = false;
447453

448454
public void AddressInvalid() {
@@ -666,6 +672,13 @@ private void WebBrowserMode_FormClosing(object sender, FormClosingEventArgs e) {
666672
return;
667673
}
668674

675+
// code beyond this point is single shot
676+
if (exiting) {
677+
return;
678+
}
679+
680+
exiting = true;
681+
669682
// stop form closing recursion
670683
FormClosing -= WebBrowserMode_FormClosing;
671684

0 commit comments

Comments
 (0)