Skip to content

Commit 881fae5

Browse files
committed
Only initialize Gtk once
1 parent 6a1834d commit 881fae5

File tree

6 files changed

+22
-7
lines changed

6 files changed

+22
-7
lines changed

AssetRipper.NativeDialogs/ConfirmationDialog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public Options(string message, Type type = Type.OkCancel)
116116
if (Gtk.Global.IsSupported)
117117
{
118118
bool? result;
119-
Gtk.Application.Init();
119+
GtkHelper.EnsureInitialized();
120120

121121
using Gtk.MessageDialog md = new(
122122
null,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace AssetRipper.NativeDialogs;
2+
3+
internal static class GtkHelper
4+
{
5+
private static bool isInitialized;
6+
7+
public static void EnsureInitialized()
8+
{
9+
if (!isInitialized)
10+
{
11+
Gtk.Application.Init();
12+
isInitialized = true;
13+
}
14+
}
15+
}

AssetRipper.NativeDialogs/MessageDialog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private static Task MessageLinux(Options options)
8383
{
8484
if (Gtk.Global.IsSupported)
8585
{
86-
Gtk.Application.Init();
86+
GtkHelper.EnsureInitialized();
8787

8888
using Gtk.MessageDialog md = new(
8989
null,

AssetRipper.NativeDialogs/OpenFileDialog.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static class OpenFileDialog
7474
if (Gtk.Global.IsSupported)
7575
{
7676
string? result;
77-
Gtk.Application.Init();
77+
GtkHelper.EnsureInitialized();
7878

7979
using Gtk.FileChooserNative dlg = new(
8080
"Open a file", null,
@@ -197,7 +197,7 @@ public static class OpenFileDialog
197197
if (Gtk.Global.IsSupported)
198198
{
199199
string[]? result;
200-
Gtk.Application.Init();
200+
GtkHelper.EnsureInitialized();
201201

202202
using Gtk.FileChooserNative dlg = new(
203203
"Open files", null,

AssetRipper.NativeDialogs/OpenFolderDialog.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public static class OpenFolderDialog
123123
if (Gtk.Global.IsSupported)
124124
{
125125
string? result;
126-
Gtk.Application.Init();
126+
GtkHelper.EnsureInitialized();
127127

128128
using Gtk.FileChooserNative dlg = new(
129129
"Open a folder", null,
@@ -206,7 +206,7 @@ public static class OpenFolderDialog
206206
if (Gtk.Global.IsSupported)
207207
{
208208
string[]? result;
209-
Gtk.Application.Init();
209+
GtkHelper.EnsureInitialized();
210210

211211
using Gtk.FileChooserNative dlg = new(
212212
"Open folders", null,

AssetRipper.NativeDialogs/SaveFileDialog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static class SaveFileDialog
7676
if (Gtk.Global.IsSupported)
7777
{
7878
string? result;
79-
Gtk.Application.Init();
79+
GtkHelper.EnsureInitialized();
8080

8181
using Gtk.FileChooserNative dlg = new(
8282
"Save a file", null,

0 commit comments

Comments
 (0)