Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtestutil_macos.mm
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include "QtCore/private/qcore_mac_p.h"
7
8#import <AppKit/AppKit.h>
9
11
12namespace QTestPrivate {
13
14 /*! \internal
15
16 Disables restoration of previously saved window state. This causes tests
17 to start with a clean slate and prevents the "previous restore failed"
18 dialog from showing if there was a test crash.
19 */
21 {
22 [NSUserDefaults.standardUserDefaults registerDefaults:@{
23 @"ApplePersistenceIgnoreState" : @YES
24 }];
25 }
26
28 {
29 auto dialogType = QCFType<CFStringRef>(CFPreferencesCopyAppValue(
30 CFSTR("DialogType"), CFSTR("com.apple.CrashReporter")));
31
32 auto stringCompare = [](CFStringRef str1, CFStringRef str2) -> bool {
33 return CFStringCompare(str1, str2, kCFCompareCaseInsensitive) == kCFCompareEqualTo;
34 };
35
36 if (!dialogType || stringCompare(dialogType, CFSTR("basic"))) {
37 // The default (basic) dialog type only shows up if the
38 // application is 'user visible', as indicated by the
39 // activation policy.
40 auto *runningApp = NSRunningApplication.currentApplication;
41 return runningApp && runningApp.activationPolicy == NSApplicationActivationPolicyRegular;
42 } else if (stringCompare(dialogType, CFSTR("developer"))
43 || stringCompare(dialogType, CFSTR("crashreport"))) {
44 // While in developer mode the dialog will show for all
45 // crashed applications, including backgrounded ones.
46 return true;
47 } else {
48 // Finally, 'server' or 'none' will result in no dialog
49 return false;
50 }
51 }
52
53 /*! \internal
54 \class AppNapDisabler
55 \brief Disables App Nap by registering a background activity.
56
57 App Nap remains disabled as long as the AppNapDisabler instance
58 exists.
59 */
60
61 /*! \internal
62 Creates an AppNapDisabler instance and starts a NSActivityBackground activity.
63 */
65 {
66 m_activity = [[NSProcessInfo processInfo] beginActivityWithOptions:NSActivityBackground
67 reason:@"Qt Auto Test"];
68 [m_activity retain];
69 }
70
71 /*! \internal
72 Destroys the AppNapDisabler instance and ends the NSActivityBackground activity.
73 */
75 {
76 [[NSProcessInfo processInfo] endActivity:m_activity];
77 [m_activity release];
78 }
79}
80
81QT_END_NAMESPACE
Disables App Nap by registering a background activity.
Combined button and popup list for selecting options.
void disableWindowRestore()
bool macCrashReporterWillShowDialog()