├── .gitattributes ├── Build.cmd ├── LICENSE ├── WinMain.c └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Build.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | cd "%~dp0" 3 | gcc -Os -s -mwindows -nostdlib WinMain.c -lKernel32 -lOle32 -lShell32 -o AppLifecycleOptOut.exe 4 | upx --best --ultra-brute AppLifecycleOptOut.exe>nul 2>&1 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Aetopia 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /WinMain.c: -------------------------------------------------------------------------------- 1 | #define _WIN32_WINNT _WIN32_WINNT_WIN10 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int WinMainCRTStartup() 8 | { 9 | INT NumArgs = 0; 10 | LPWSTR *ArgvW = CommandLineToArgvW(GetCommandLineW(), &NumArgs); 11 | 12 | CoInitialize(NULL); 13 | IPackageDebugSettings *pPackageDebugSettings = NULL; 14 | CoCreateInstance(&CLSID_PackageDebugSettings, NULL, CLSCTX_INPROC_SERVER, &IID_IPackageDebugSettings, 15 | (LPVOID *)&pPackageDebugSettings); 16 | 17 | for (INT nArg = 0; nArg < NumArgs; nArg++) 18 | { 19 | UINT32 count = 0, bufferLength = 0; 20 | PCWSTR packageFamilyName = ArgvW[nArg]; 21 | 22 | pPackageDebugSettings->lpVtbl->EnableDebugging(pPackageDebugSettings, packageFamilyName, NULL, NULL); 23 | 24 | if (GetPackagesByPackageFamily(packageFamilyName, &count, NULL, &bufferLength, NULL) != 25 | ERROR_INSUFFICIENT_BUFFER) 26 | continue; 27 | 28 | PWSTR *packageFullNames = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PWSTR) * count), 29 | buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR) * bufferLength); 30 | 31 | if (!GetPackagesByPackageFamily(packageFamilyName, &count, packageFullNames, &bufferLength, buffer)) 32 | for (UINT32 nIndex = 0; nIndex < count; nIndex++) 33 | pPackageDebugSettings->lpVtbl->EnableDebugging(pPackageDebugSettings, packageFullNames[nIndex], NULL, 34 | NULL); 35 | } 36 | 37 | ExitProcess(0); 38 | return 0; 39 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > [!WARNING] 2 | > AppLifecycleOptOut has been deprecated in favor of [Stonecutter](https://github.com/Aetopia/Stonecutter).
3 | > AppLifecycleOptOut was originally made to fix issues caused by app suspension in Minecraft: Bedrock Edition.
4 | > Stonecutter focuses on fixing known bugs on Mojang's bug tracker for [Minecraft: Bedrock Edtion](https://bugs.mojang.com/projects/MCPE/summary).
5 | 6 | # AppLifecycleOptOut 7 | A tool to prevent UWP apps from being suspended. 8 | 9 | ## Context 10 | UWP apps are governed by an application model, that defines how their execution states are handled.
11 | The following image showcases the possible app model states, an application may go through.
12 | 13 | 14 | 15 | The main intent of this application model is for power saving and reduction in system usage. 16 | 17 | In certain instances, it might be desirable to prevent an app from suspending, potential reasons include:
18 | 1. For performing prolonged workloads when in the background. 19 | 2. Prevention of undesirable behavior occuring in apps due to UWP app suspension. 20 | 21 | Luckily, a developer may use the following for prolonged workloads that must be done when an UWP app is in the background:
22 | 23 | 1. **[`ExtendedExecutionSession`](https://learn.microsoft.com/en-us/uwp/api/windows.applicationmodel.extendedexecution.extendedexecutionsession)**:
24 | The following may be used to request more time for performing the specified workload before being suspended by the operating system, unfortunately this simply delays suspension doesn't prevent it. 25 | 26 | 2. **[`ExtendedExecutionForegroundSession`](https://learn.microsoft.com/en-us/uwp/api/windows.applicationmodel.extendedexecution.foreground.extendedexecutionforegroundsession)**:
27 | The following may be used to prevent an UWP app from being suspended by the operating system, although this fulfills our needs, it prevents an UWP app from being published on the Microsoft Store. 28 | 29 | 3. **[`IPackageDebugSettings::EnableDebugging`](https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipackagedebugsettings-enabledebugging)**:
30 | This following may be used to enable debug mode for an UWP app, when enabled the following happens:
31 | - Optionally enables debugger attach on activation. 32 | - Disables activation timeouts. 33 | - Disables automatic process suspension. 34 | - Disables automatic process termination. 35 | - Disables automatic process resumption. 36 |
37 | 38 | Out of the 3 methods, the 3rd one maybe used safely with any UWP app to prevent automatic suspension by the operating system. 39 | 40 | ## Usage 41 | 1. Download the latest release from [GitHub Releases](https://github.com/Aetopia/AppLifecycleOptOut/releases/latest). 42 | 2. Use the following command in PowerShell to obtain current installed UWP apps along with their package family and full names.
43 | 44 | **Command**:
45 | ```ps 46 | $AppxPackages = Get-AppxPackage 47 | Get-StartApps | 48 | ForEach-Object { 49 | [Object]$StartApp = $_ 50 | [Object]$AppxPackage = $AppxPackages | Where-Object { $StartApp.AppID -like "$($_.PackageFamilyName)*" } 51 | if ($AppxPackage) { 52 | Write-Host "$($StartApp.Name):`n`t$($AppxPackage.PackageFamilyName)`n`t$($AppxPackage.PackageFullName)`n" 53 | } 54 | } 55 | ``` 56 | 57 | **Output**:
58 | ``` 59 | Settings: 60 | windows.immersivecontrolpanel_cw5n1h2txyewy 61 | windows.immersivecontrolpanel_10.0.2.1000_neutral_neutral_cw5n1h2txyewy 62 | ``` 63 | 64 | 3. Provide the full package names of the UWP apps that shouldn't be suspended by the operating system to `AppLifecycleOptOut.exe` like this:
65 | 66 | ```ps 67 | AppLifecycleOptOut.exe PackageFamilyName1 PackageFullName1 PackageFamilyName2 PackageFullName2 68 | ``` 69 | > [!IMPORTANT] 70 | > - You need to simply run the program, everytime you log in.
71 | > - If possible always specify package family names, this way the program can resolve package full names correctly.
72 | > - Use package full names, if you need to use the program with any loose package. 73 | 74 | ## Building 75 | 1. Install [`GCC`](https://github.com/brechtsanders/winlibs_mingw) and [`UPX`](https://upx.github.io) for optional compression. 76 | 2. Run [`Build.cmd`](Build.cmd). 77 | --------------------------------------------------------------------------------