Skip to content
This repository has been archived by the owner on May 18, 2022. It is now read-only.

Commit

Permalink
Merge pull request #91 from CastleDev/fix/forceResolution
Browse files Browse the repository at this point in the history
Fix/force resolution
  • Loading branch information
Mafrans authored Jun 16, 2020
2 parents 90934ec + 7436f5d commit e589563
Show file tree
Hide file tree
Showing 3 changed files with 21,636 additions and 10 deletions.
5,382 changes: 5,380 additions & 2 deletions dist/app.js

Large diffs are not rendered by default.

16,243 changes: 16,235 additions & 8 deletions dist/popup.js

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions src/components/ForceResolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class ForceResolution extends Component {
*/
snackbar: Snackbar;


constructor(tab: UITab, snackbar: Snackbar) {
super();

Expand Down Expand Up @@ -144,41 +145,61 @@ export class ForceResolution extends Component {
static setResolution(resolution: number): void {
const script = document.createElement('script');

// Rudimentary mapping of stadia localStorage variables for performance setting
const stadiaPerformance = {HD: 2, FHD: 3, WQHD: 4, UHD_4K: 4}

// Number based on performance to be injected in localStorage for Stadia settings.
let performanceInject;

let height;
let width;
switch (resolution) {
case Resolution.UHD_4K:
width = 3840;
height = 2160;
performanceInject = stadiaPerformance.UHD_4K;
break;

case Resolution.WQHD:
width = 2560;
height = 1440;
performanceInject = stadiaPerformance.UHD_4K;
break;

case Resolution.FHD:
width = 1920;
height = 1080;
performanceInject = stadiaPerformance.FHD;
break;

case Resolution.HD:
width = 1280;
height = 720;
performanceInject = stadiaPerformance.HD;
break;

case Resolution.AUTOMATIC:
script.innerHTML = `
localStorage.removeItem("_bl3");
`;
document.body.appendChild(script);
return;

default:
return;
}

/** Create localStorage compatible value string from params with date
* Date is included as milisecond unix timestamp in value by Stadia, some values have safeguard expiration so refresh to be safe
* */
const performanceValue = JSON.stringify({"data":`[${performanceInject},2]`,"creation": Date.now()});

script.innerHTML = `
Object.defineProperty(window.screen, 'availWidth', { value: ${width} });
Object.defineProperty(window.screen, 'availHeight', { value: ${height} });
Object.defineProperty(window.screen, 'width', { value: ${width} });
Object.defineProperty(window.screen, 'height', { value: ${height} });
localStorage.setItem("_bl3", '${performanceValue}');
`;

document.body.appendChild(script);
Expand Down

0 comments on commit e589563

Please sign in to comment.