Skip to content

Commit

Permalink
improve statusBackgroundApps detection
Browse files Browse the repository at this point in the history
  • Loading branch information
melo936 committed Oct 6, 2024
1 parent 497e1d1 commit fb20839
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 43 deletions.
20 changes: 15 additions & 5 deletions common/lib/src/services/performance_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,20 @@ class PerformanceService implements SetupService {

bool get statusBackgroundApps {
return WinRegistryService.readInt(
RegistryHive.localMachine,
r'Software\Policies\Microsoft\Windows\AppPrivacy',
'LetAppsRunInBackground') !=
2;
RegistryHive.localMachine,
r'Software\Policies\Microsoft\Windows\AppPrivacy',
'LetAppsRunInBackground') !=
2 &&
WinRegistryService.readInt(
RegistryHive.currentUser,
r'Software\Microsoft\Windows\CurrentVersion\Search',
'BackgroundAppGlobalToggle') !=
0 &&
WinRegistryService.readInt(
RegistryHive.currentUser,
r'Software\Microsoft\Windows\CurrentVersion\BackgroundAccessApplications',
'GlobalUserDisabled') !=
1;
}

void enableBackgroundApps() {
Expand All @@ -224,7 +234,7 @@ class PerformanceService implements SetupService {

void disableBackgroundApps() {
WinRegistryService.writeDword(
Registry.localMachine,
Registry.currentUser,
r'Software\Microsoft\Windows\CurrentVersion\Search',
'BackgroundAppGlobalToggle',
0);
Expand Down
51 changes: 13 additions & 38 deletions common/lib/src/services/win_registry_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,10 @@ class WinRegistryService {

static Future<void> writeDword(
RegistryKey key, String path, String name, int value) async {
final regKey = key;
var regPath = path;
final subKey = regKey.createKey(regPath);

var dword = RegistryValue(name, RegistryValueType.int32, value);

try {
subKey.createValue(dword);
key
.createKey(path)
.createValue(RegistryValue(name, RegistryValueType.int32, value));
logger.i('Added $name with $value to $path');
} catch (e) {
logger.w('Error writing $name - $e');
Expand All @@ -116,14 +112,10 @@ class WinRegistryService {

static void writeString(
RegistryKey key, String path, String name, String value) {
final regKey = key;
var regPath = path;
final subKey = regKey.createKey(regPath);

var string = RegistryValue(name, RegistryValueType.string, value);

try {
subKey.createValue(string);
key
.createKey(path)
.createValue(RegistryValue(name, RegistryValueType.string, value));
logger.i('Added $name with $value to $path');
} catch (e) {
logger.w('Error writing $name - $e');
Expand All @@ -132,14 +124,9 @@ class WinRegistryService {

static void writeStringMultiSZ(
RegistryKey key, String path, String name, String value) {
final regKey = key;
var regPath = path;
final subKey = regKey.createKey(regPath);

var string = RegistryValue(name, RegistryValueType.stringArray, value);

try {
subKey.createValue(string);
key.createKey(path).createValue(
RegistryValue(name, RegistryValueType.stringArray, value));
logger.i('Added $name with $value to $path');
} catch (e) {
logger.w('Error writing $name - $e');
Expand All @@ -148,47 +135,35 @@ class WinRegistryService {

static void writeBinary(
RegistryKey key, String path, String name, List<int> value) {
final regKey = key;
var regPath = path;
final subKey = regKey.createKey(regPath);

var bin = RegistryValue(name, RegistryValueType.binary, value);
try {
subKey.createValue(bin);
key.createKey(path).createValue(RegistryValue(
name, RegistryValueType.binary, Uint8List.fromList(value)));
} catch (e) {
logger.w('Error writing $name - $e');
}
}

static void deleteValue(RegistryKey key, String path, String name) {
final regKey = key;
var regPath = path;
final subKey = regKey.createKey(regPath);

try {
subKey.deleteValue(name);
key.createKey(path).deleteValue(name);
logger.i('Deleted $name from $path');
} catch (_) {
logger.w('Error deleting $name from $path');
}
}

static void deleteKey(RegistryKey key, String path) {
final regKey = key;
var regPath = path;
try {
regKey.deleteKey(regPath);
key.deleteKey(path);
logger.i('Deleted $path');
} catch (e) {
logger.w('Error deleting $path');
}
}

static void createKey(RegistryKey key, String path) {
final regKey = key;
var regPath = path;
try {
regKey.createKey(regPath);
key.createKey(path);
logger.i('Created $path');
} catch (_) {
logger.w('Error creating $path');
Expand Down

0 comments on commit fb20839

Please sign in to comment.