@@ -2,12 +2,17 @@ import 'dart:async';
22import 'dart:io' ;
33
44import 'package:args/command_runner.dart' ;
5+ import 'package:process_run/shell_run.dart' ;
6+ import 'package:revitool/core/ms_store/ms_store_command.dart' ;
57import 'package:revitool/core/security/security_service.dart' ;
68import 'package:revitool/core/winsxs/win_package_service.dart' ;
9+ import 'package:revitool/shared/win_registry_service.dart' ;
710
811class WindowsPackageCommand extends Command <String > {
912 static final _winPackageService = WinPackageService ();
13+ static final _msStoreCommand = MSStoreCommand ();
1014 static final _securityService = SecurityService ();
15+ static final _shell = Shell ();
1116
1217 static const tag = "[Windows Package]" ;
1318
@@ -21,12 +26,20 @@ class WindowsPackageCommand extends Command<String> {
2126 argParser.addOption (
2227 'install' ,
2328 help: 'Install a package' ,
24- allowed: const ['system-components-removal' , 'defender-removal' ],
29+ allowed: const [
30+ 'system-components-removal' ,
31+ 'defender-removal' ,
32+ 'ai-removal' ,
33+ ],
2534 );
2635 argParser.addOption (
2736 'uninstall' ,
2837 help: 'Uninstall a package' ,
29- allowed: const ['system-components-removal' , 'defender-removal' ],
38+ allowed: const [
39+ 'system-components-removal' ,
40+ 'defender-removal' ,
41+ 'ai-removal' ,
42+ ],
3043 );
3144 }
3245
@@ -51,6 +64,8 @@ class WindowsPackageCommand extends Command<String> {
5164 return WinPackageType .systemComponentsRemoval;
5265 case 'defender-removal' :
5366 return WinPackageType .defenderRemoval;
67+ case 'ai-removal' :
68+ return WinPackageType .aiRemoval;
5469 default :
5570 throw Exception ('Invalid package: $package ' );
5671 }
@@ -66,19 +81,41 @@ class WindowsPackageCommand extends Command<String> {
6681 }
6782
6883 stdout.writeln ('$tag Downloading package: ${mode .packageName }' );
69- await _winPackageService.downloadPackage (mode);
84+ final packagePath = await _winPackageService.downloadPackage (mode);
7085
7186 stdout.writeln ('$tag Installing package: ${mode .packageName }' );
72- await _winPackageService.installPackage (mode);
87+ await _winPackageService.installPackage (packagePath);
88+
89+ if (mode == WinPackageType .aiRemoval) {
90+ WinRegistryService .hidePageVisibilitySettings ("aicomponents" );
91+ WinRegistryService .hidePageVisibilitySettings ("privacy-systemaimodels" );
92+ await _shell.run (
93+ 'PowerShell -EP Unrestricted -NonInteractive -NoLogo -NoP -C "Disable-WindowsOptionalFeature -Online -FeatureName Recall -NoRestart"' ,
94+ );
95+ await _shell.run (
96+ 'PowerShell -EP Unrestricted -NonInteractive -NoLogo -NoP -C "Get-AppxPackage -AllUsers Microsoft.Copilot* | Remove-AppxPackage"' ,
97+ );
98+ }
7399 } catch (e) {
74100 stderr.writeln ('$tag $e ' );
75101 }
76102 }
77103
78104 Future <void > _uninstallPackage (final WinPackageType packageType) async {
79105 stdout.writeln ('$tag Uninstalling package: ${packageType .packageName }' );
80- if (packageType == WinPackageType .defenderRemoval) {
81- await _securityService.enableDefender ();
106+
107+ if (packageType == WinPackageType .aiRemoval) {
108+ WinRegistryService .unhidePageVisibilitySettings ("aicomponents" );
109+ WinRegistryService .unhidePageVisibilitySettings ("privacy-systemaimodels" );
110+ await _shell.run (
111+ 'PowerShell -EP Unrestricted -NonInteractive -NoLogo -NoP -C "Enable-WindowsOptionalFeature -Online -FeatureName Recall -NoRestart"' ,
112+ );
113+ await _msStoreCommand.installPackage (
114+ id: "9nht9rb2f4hd" ,
115+ ring: "Retail" ,
116+ arch: "auto" ,
117+ downloadOnly: false ,
118+ );
82119 }
83120 await _winPackageService.uninstallPackage (packageType);
84121 }
0 commit comments