File tree Expand file tree Collapse file tree
apps/code/src/main/platform-adapters Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,8 +9,6 @@ const execFileAsync = promisify(execFile);
99
1010@injectable ( )
1111export class ElectronPowerManager implements IPowerManager {
12- private hasBuiltInBatteryResult : Promise < boolean > | null = null ;
13-
1412 public onResume ( handler : ( ) => void ) : ( ) => void {
1513 powerMonitor . on ( "resume" , handler ) ;
1614 return ( ) => powerMonitor . off ( "resume" , handler ) ;
@@ -26,13 +24,13 @@ export class ElectronPowerManager implements IPowerManager {
2624 }
2725
2826 public hasBuiltInBattery ( ) : Promise < boolean > {
29- if ( ! this . hasBuiltInBatteryResult ) {
30- this . hasBuiltInBatteryResult = detectBuiltInBattery ( ) . catch ( ( ) => false ) ;
31- }
32- return this . hasBuiltInBatteryResult ;
27+ memoizedBuiltInBattery ??= detectBuiltInBattery ( ) . catch ( ( ) => false ) ;
28+ return memoizedBuiltInBattery ;
3329 }
3430}
3531
32+ let memoizedBuiltInBattery : Promise < boolean > | null = null ;
33+
3634async function detectBuiltInBattery ( ) : Promise < boolean > {
3735 switch ( process . platform ) {
3836 case "darwin" : {
You can’t perform that action at this time.
0 commit comments