trifle-labs / anybody-problem

Anybody Problem simulates the 3-body problem in two dimensions using zk proofs written in circom.
https://anybody.gg
17 stars 4 forks source link

maybe show popup if mobile is in lower power mode #304

Open evvvritt opened 3 months ago

evvvritt commented 3 months ago

from claude

Yes, it's possible to detect if a device is in low power mode using JavaScript, but the implementation depends on the specific platform and browser. Here's how you can do it for different scenarios:

  1. For iOS devices (Safari browser):

    if ('deviceLowPower' in navigator) {
    navigator.deviceLowPower.addEventListener('change', (event) => {
    console.log('Low Power Mode:', event.lowPower);
    });
    
    navigator.deviceLowPower.query().then((state) => {
    console.log('Current Low Power Mode:', state.lowPower);
    });
    }
  2. For Android devices: Currently, there's no direct API to detect low power mode on Android using JavaScript. However, you can use the Battery Status API to infer if the device might be in a power-saving state:

if ('getBattery' in navigator) {
  navigator.getBattery().then((battery) => {
    console.log('Battery level:', battery.level);
    console.log('Is charging:', battery.charging);

    battery.addEventListener('levelchange', () => {
      console.log('Battery level changed:', battery.level);
    });

    battery.addEventListener('chargingchange', () => {
      console.log('Charging status changed:', battery.charging);
    });
  });
}
  1. For desktop browsers: Desktop browsers don't typically have a low power mode, but you can still use the Battery Status API to get information about the battery status:
if ('getBattery' in navigator) {
  navigator.getBattery().then((battery) => {
    console.log('Battery level:', battery.level);
    console.log('Is charging:', battery.charging);
  });
}

Note that the Battery Status API is being deprecated in some browsers due to privacy concerns, so its availability may be limited.

Would you like me to explain or break down any part of this code?

evvvritt commented 3 months ago

duplicate of #275