Closed Nirbhay97 closed 1 month ago
Thank you! @Nirbhay97
Typically our users might want 1080p usually and 720p or 480p on battery or to pause when the charger is unplugged i also appreciate the gradually switching down like a gradual reminder.
"qualityWhenRunningOnBattery":{ "message": "Quality, when running on battery" },
"pauseWhileIUnplugTheCharger":{ "message": "Pause when I unplug the charger!" },
"whenBatteryIslowDecreaseQuality":{ "message": "Low battery: Gradually decrease the quality!" },
The battery listener/s can depend on battery feature/s being enabled.
if (improvedTube.storage.qualityWhenRunningOnBattery || improvedTube.storage.pauseWhileIUnplugTheCharger || improvedTube.storage.whenBatteryIslowDecreaseQuality) {
async function battery() {
try {
const battery = await navigator.getBattery();
if (battery === null) {
console.log('Desktop!(?) "Battery === null"');
} else if (battery.level === null) {
console.log("No battery present");
} else if (improvedTube.storage.qualityWhenRunningOnBattery || improvedTube.storage.whenBatteryIslowDecreaseQuality) {
battery.addEventListener("levelchange", () => {
if (!battery.charging) {
if (improvedTube.storage.qualityWhenRunningOnBattery) {
playerQuality(improvedTube.storage.qualityWhenRunningOnBattery);
}
if (improvedTube.storage.whenBatteryIslowDecreaseQuality && (battery.level < 0.15 || battery.dischargingTime < 1200)) {
if (battery.level > 0.11 || battery.dischargingTime > 900) {
playerQuality("large");
} else if (battery.level > 0.08 || battery.dischargingTime > 600) {
playerQuality("medium");
} else if (battery.level > 0.04 && battery.dischargingTime > 360) {
playerQuality("small");
} else {
playerQuality("tiny");
}
}
}
});
}
if (improvedTube.storage.pauseWhileIUnplugTheCharger) {
battery.addEventListener("chargingchange", () => {
if (!battery.charging) {
ImprovedTube.elements.player.pauseVideo();
ImprovedTube.paused = true;
} else if (ImprovedTube.paused === true) {
ImprovedTube.elements.player.playVideo();
delete ImprovedTube.paused;
}
});
}
} catch (error) {
console.error("Error accessing battery information:", error.message);
}
}
battery();
}
(untested)
[ ] The position in the menu can be next to our Quality & Quality without Focus (Codec, FPS, HDR settings also are related)
(BTW, in our menu UI, we only used the on
click
functions when a toggle should cause another one to flip, so thats not required here yet)
That's a really well written and improved code considering different battery cases, a whole lot of learning for me! Thanks @ImprovedTube .
Since the PR is still open, what is to be done from my side now? Or what things shall I focus on now for this feat.
Hi! @Nirbhay97 was yours tested already?
if you like you can.. : ..test/finish this with my code:
ImprovedTube.playerQuality();
ImprovedTube.batteryFeatures();
(we dont need to call it on focus, like QualityWithoutFocus)
..and/or check how to do this too:
So in our menu we can make battery features invisible on Desktops.
(which wont matter if it will be the same PR or another)
Yes, I tested my code and it worked well,
Yes, it makes more sense to hide this feat when using on desktop, which is currently not handled.
hi! @Nirbhay97
I commented out the toggles for now. As my continuation of your code might not be finished.
Looking forward!
It will automatically resume previous set quality when on charging
if it was set with our quality feature,
qualityWhenRunningOnBattery: {
whenBatteryIslowDecreaseQuality: {
pauseWhileIUnplugTheCharger
inconsistent Naming convention, lets stick to snake case since every other option is already that please :)
someone already planned that, because: https://github.com/code-charity/youtube/blob/e8bd44f798263e76ec32afd1b02a2521b580fbac/menu/skeleton-parts/player.js#L925 but didnt finish, didnt add id and forgot to comment it :) no quality_when_low_battery ID = Codec h254 modal doesnt close on OK :
player.js:920 Uncaught
TypeError: Cannot read properties of null (reading 'dispatchEvent')
at refresh (player.js:920:58)
at Object.ok (player.js:934:9)
at HTMLButtonElement.click (satus.js:1234:36)
Sorry my additions & tuned numbers delayed the release of the feature yet.
Greetings @Nirbhay97
issue -> quality and bandwidth #2240