Skip to content

Commit 04072f0

Browse files
committed
Integrate "Ignore for this session" better with config system
Because of the previous commit, this is needed to stop DolphinQt from forgetting that the user pressed ignore whenever any part of the config is changed. This commit also changes the behavior a bit on DolphinQt: "Ignore for this session" now applies to the current emulation session instead of the current Dolphin launch. This matches how it already worked on Android, and is in my opinion better because it means the user won't lose out on important panic alerts in a game becase they played another game first that had repeated panic alerts that they wanted to ignore. For Android, this commit isn't necessary, but it makes the code cleaner.
1 parent 16c71b9 commit 04072f0

9 files changed

Lines changed: 65 additions & 59 deletions

File tree

Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -511,59 +511,54 @@ public static boolean displayAlertMsg(final String caption, final String text,
511511
Log.error("[NativeLibrary] Alert: " + text);
512512
final EmulationActivity emulationActivity = sEmulationActivity.get();
513513
boolean result = false;
514-
if (isWarning && emulationActivity != null && emulationActivity.isIgnoringWarnings())
514+
515+
// We can't use AlertMessages unless we have a non-null activity reference
516+
// and are allowed to block. As a fallback, we can use toasts.
517+
if (emulationActivity == null || nonBlocking)
515518
{
516-
return true;
519+
new Handler(Looper.getMainLooper()).post(
520+
() -> Toast.makeText(DolphinApplication.getAppContext(), text, Toast.LENGTH_LONG)
521+
.show());
517522
}
518523
else
519524
{
520-
// We can't use AlertMessages unless we have a non-null activity reference
521-
// and are allowed to block. As a fallback, we can use toasts.
522-
if (emulationActivity == null || nonBlocking)
523-
{
524-
new Handler(Looper.getMainLooper()).post(
525-
() -> Toast.makeText(DolphinApplication.getAppContext(), text, Toast.LENGTH_LONG)
526-
.show());
527-
}
528-
else
529-
{
530-
sIsShowingAlertMessage = true;
525+
sIsShowingAlertMessage = true;
531526

532-
emulationActivity.runOnUiThread(() ->
527+
emulationActivity.runOnUiThread(() ->
528+
{
529+
FragmentManager fragmentManager = emulationActivity.getSupportFragmentManager();
530+
if (fragmentManager.isStateSaved())
533531
{
534-
FragmentManager fragmentManager = emulationActivity.getSupportFragmentManager();
535-
if (fragmentManager.isStateSaved())
536-
{
537-
// The activity is being destroyed, so we can't use it to display an AlertMessage.
538-
// Fall back to a toast.
539-
Toast.makeText(emulationActivity, text, Toast.LENGTH_LONG).show();
540-
NotifyAlertMessageLock();
541-
}
542-
else
543-
{
544-
AlertMessage.newInstance(caption, text, yesNo, isWarning)
545-
.show(fragmentManager, "AlertMessage");
546-
}
547-
});
548-
549-
// Wait for the lock to notify that it is complete.
550-
synchronized (sAlertMessageLock)
532+
// The activity is being destroyed, so we can't use it to display an AlertMessage.
533+
// Fall back to a toast.
534+
Toast.makeText(emulationActivity, text, Toast.LENGTH_LONG).show();
535+
NotifyAlertMessageLock();
536+
}
537+
else
551538
{
552-
try
553-
{
554-
sAlertMessageLock.wait();
555-
}
556-
catch (Exception ignored)
557-
{
558-
}
539+
AlertMessage.newInstance(caption, text, yesNo, isWarning)
540+
.show(fragmentManager, "AlertMessage");
559541
}
542+
});
560543

561-
if (yesNo)
544+
// Wait for the lock to notify that it is complete.
545+
synchronized (sAlertMessageLock)
546+
{
547+
try
562548
{
563-
result = AlertMessage.getAlertResult();
549+
sAlertMessageLock.wait();
564550
}
551+
catch (Exception ignored)
552+
{
553+
}
554+
}
555+
556+
if (yesNo)
557+
{
558+
result = AlertMessage.getAlertResult();
565559
}
566560
}
561+
567562
sIsShowingAlertMessage = false;
568563
return result;
569564
}

Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,12 @@ public final class EmulationActivity extends AppCompatActivity implements ThemeP
8888
private String[] mPaths;
8989
private boolean mRiivolution;
9090
private boolean mLaunchSystemMenu;
91-
private boolean mIgnoreWarnings;
9291
private static boolean sUserPausedEmulation;
9392
private boolean mMenuToastShown;
9493

9594
public static final String EXTRA_SELECTED_GAMES = "SelectedGames";
9695
public static final String EXTRA_RIIVOLUTION = "Riivolution";
9796
public static final String EXTRA_SYSTEM_MENU = "SystemMenu";
98-
public static final String EXTRA_IGNORE_WARNINGS = "IgnoreWarnings";
9997
public static final String EXTRA_USER_PAUSED_EMULATION = "sUserPausedEmulation";
10098
public static final String EXTRA_MENU_TOAST_SHOWN = "MenuToastShown";
10199

@@ -316,7 +314,6 @@ protected void onCreate(Bundle savedInstanceState)
316314
mPaths = gameToEmulate.getStringArrayExtra(EXTRA_SELECTED_GAMES);
317315
mRiivolution = gameToEmulate.getBooleanExtra(EXTRA_RIIVOLUTION, false);
318316
mLaunchSystemMenu = gameToEmulate.getBooleanExtra(EXTRA_SYSTEM_MENU, false);
319-
mIgnoreWarnings = gameToEmulate.getBooleanExtra(EXTRA_IGNORE_WARNINGS, false);
320317
sUserPausedEmulation = gameToEmulate.getBooleanExtra(EXTRA_USER_PAUSED_EMULATION, false);
321318
mMenuToastShown = false;
322319
activityRecreated = false;
@@ -366,7 +363,6 @@ protected void onSaveInstanceState(@NonNull Bundle outState)
366363
mEmulationFragment.saveTemporaryState();
367364
}
368365
outState.putStringArray(EXTRA_SELECTED_GAMES, mPaths);
369-
outState.putBoolean(EXTRA_IGNORE_WARNINGS, mIgnoreWarnings);
370366
outState.putBoolean(EXTRA_USER_PAUSED_EMULATION, sUserPausedEmulation);
371367
outState.putBoolean(EXTRA_MENU_TOAST_SHOWN, mMenuToastShown);
372368
super.onSaveInstanceState(outState);
@@ -375,7 +371,6 @@ protected void onSaveInstanceState(@NonNull Bundle outState)
375371
protected void restoreState(Bundle savedInstanceState)
376372
{
377373
mPaths = savedInstanceState.getStringArray(EXTRA_SELECTED_GAMES);
378-
mIgnoreWarnings = savedInstanceState.getBoolean(EXTRA_IGNORE_WARNINGS);
379374
sUserPausedEmulation = savedInstanceState.getBoolean(EXTRA_USER_PAUSED_EMULATION);
380375
mMenuToastShown = savedInstanceState.getBoolean(EXTRA_MENU_TOAST_SHOWN);
381376
}
@@ -754,16 +749,6 @@ public void handleMenuAction(@MenuAction int menuAction)
754749
}
755750
}
756751

757-
public boolean isIgnoringWarnings()
758-
{
759-
return mIgnoreWarnings;
760-
}
761-
762-
public void setIgnoreWarnings(boolean value)
763-
{
764-
mIgnoreWarnings = value;
765-
}
766-
767752
public static boolean getHasUserPausedEmulation()
768753
{
769754
return sUserPausedEmulation;

Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/AlertMessage.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import org.dolphinemu.dolphinemu.NativeLibrary;
1414
import org.dolphinemu.dolphinemu.R;
1515
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
16+
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
17+
import org.dolphinemu.dolphinemu.features.settings.model.NativeConfig;
1618

1719
public final class AlertMessage extends DialogFragment
1820
{
@@ -82,7 +84,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState)
8284
{
8385
builder.setNeutralButton(R.string.ignore_warning_alert_messages, (dialog, which) ->
8486
{
85-
emulationActivity.setIgnoreWarnings(true);
87+
BooleanSetting.MAIN_USE_PANIC_HANDLERS.setBoolean(NativeConfig.LAYER_CURRENT, false);
8688
dialog.dismiss();
8789
NativeLibrary.NotifyAlertMessageLock();
8890
});

Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,18 @@ public void setBoolean(Settings settings, boolean newValue)
329329
}
330330
}
331331

332+
public void setBoolean(int layerType, boolean newValue)
333+
{
334+
if (NativeConfig.isSettingSaveable(mFile, mSection, mKey))
335+
{
336+
NativeConfig.setBoolean(layerType, mFile, mSection, mKey, newValue);
337+
}
338+
else
339+
{
340+
throw new UnsupportedOperationException("The old config system doesn't support layers");
341+
}
342+
}
343+
332344
public boolean getBooleanGlobal()
333345
{
334346
return NativeConfig.getBoolean(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);

Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/NativeConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class NativeConfig
88
public static final int LAYER_BASE = 1;
99
public static final int LAYER_LOCAL_GAME = 2;
1010
public static final int LAYER_ACTIVE = 3;
11+
public static final int LAYER_CURRENT = 4;
1112

1213
public static native boolean isSettingSaveable(String file, String section, String key);
1314

Source/Android/jni/Config/NativeConfig.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ constexpr jint LAYER_BASE_OR_CURRENT = 0;
1616
constexpr jint LAYER_BASE = 1;
1717
constexpr jint LAYER_LOCAL_GAME = 2;
1818
constexpr jint LAYER_ACTIVE = 3;
19+
constexpr jint LAYER_CURRENT = 4;
1920

2021
static Config::Location GetLocation(JNIEnv* env, jstring file, jstring section, jstring key)
2122
{
@@ -76,6 +77,10 @@ static std::shared_ptr<Config::Layer> GetLayer(jint layer, const Config::Locatio
7677
layer_type = Config::GetActiveLayerForConfig(location);
7778
break;
7879

80+
case LAYER_CURRENT:
81+
layer_type = Config::LayerType::CurrentRun;
82+
break;
83+
7984
default:
8085
ASSERT(false);
8186
return nullptr;

Source/Core/Common/Config/Config.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ void SetBaseOrCurrent(const Info<T>& info, const std::common_type_t<T>& value)
120120
Set<T>(LayerType::CurrentRun, info, value);
121121
}
122122

123+
template <typename T>
124+
void DeleteKey(LayerType layer, const Info<T>& info)
125+
{
126+
if (GetLayer(layer)->DeleteKey(info.GetLocation()))
127+
OnConfigChanged();
128+
}
129+
123130
// Used to defer OnConfigChanged until after the completion of many config changes.
124131
class ConfigChangeCallbackGuard
125132
{

Source/Core/DolphinQt/Main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static bool QtMsgAlertHandler(const char* caption, const char* text, bool yes_no
9292

9393
if (button == QMessageBox::Ignore)
9494
{
95-
Common::SetEnableAlert(false);
95+
Config::SetCurrent(Config::MAIN_USE_PANIC_HANDLERS, false);
9696
return true;
9797
}
9898

Source/Core/DolphinQt/MenuBar.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,7 @@ void MenuBar::AddOptionsMenu()
548548
m_reset_ignore_panic_handler = options_menu->addAction(tr("Reset Ignore Panic Handler"));
549549

550550
connect(m_reset_ignore_panic_handler, &QAction::triggered, this, []() {
551-
if (Config::Get(Config::MAIN_USE_PANIC_HANDLERS))
552-
Common::SetEnableAlert(true);
551+
Config::DeleteKey(Config::LayerType::CurrentRun, Config::MAIN_USE_PANIC_HANDLERS);
553552
});
554553

555554
m_change_font = options_menu->addAction(tr("&Font..."), this, &MenuBar::ChangeDebugFont);

0 commit comments

Comments
 (0)