Update SteamTweaks

pull/239/head
Peter Repukat 1 year ago
parent a07faa926c
commit b26fd9faf5

@ -1,11 +1,44 @@
import typescript from '@rollup/plugin-typescript';
import { readdirSync, lstatSync } from 'fs';
import path from 'path';
export default {
input: 'src/Tweaks/Overlay/HideFPSCounter.ts',
output: {
file: 'dist/glossiTweaks.js',
sourcemap: "inline",
format: 'es',
},
plugins: [typescript()]
};
const getFileListForDir = (dir) => {
return readdirSync(dir).map((file) => {
const absolute = path.resolve(dir, file);
if (file.endsWith('.ts')) {
return absolute;
}
if (lstatSync(absolute).isDirectory()) {
return getFileListForDir(absolute)
}
}).flat(999);
}
const tsPluginConf = typescript({
cacheDir: '.rollup.tscache'
});
export default [
{
input: 'src/GlosSITweaks.ts',
output: {
dir: 'dist',
sourcemap: "inline",
format: 'iife',
},
plugins: [tsPluginConf],
},
...getFileListForDir('src/Tweaks').map((file) => {
return {
input: file,
output: {
file: file.replace('src', 'dist').replace(/\.ts$/, '.js'),
sourcemap: "inline",
format: 'iife',
},
plugins: [tsPluginConf],
}
})
];

@ -0,0 +1,54 @@
import type { SteamConfig } from './common/util/types';
class SteamTargetApi {
public getSteamSettings(): Promise<SteamConfig> {
return fetch('http://localhost:8756/steam_settings')
.then(
(res) => res.json().then(
(json) => (json as SteamConfig).UserLocalConfigStore as SteamConfig
)
);
}
}
class GlosSIApiCtor {
public readonly SteamTarget: SteamTargetApi = new SteamTargetApi();
}
interface GlosSITweaks {
[tweakName: string]: { readonly install: () => unknown; readonly uninstall?: () => void }
}
declare global {
interface Window {
GlosSITweaks: GlosSITweaks
GlosSIApi: InstanceType<typeof GlosSIApiCtor>;
}
// eslint-disable-next-line
const GlosSIApi: InstanceType<typeof GlosSIApiCtor>;
const GlosSITweaks: GlosSITweaks
}
const installGlosSIApi = () => {
window.GlosSITweaks = {
GlosSI: {
install: () => {
const api = new GlosSIApiCtor();
Object.assign(window, { GlosSIApi: api });
},
uninstall: () => {
Object.values(window.GlosSITweaks)
.forEach((obj) => obj.uninstall?.());
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete window.GlosSIApi;
}
}
};
window.GlosSITweaks.GlosSI.install();
};
if (!window.GlosSITweaks || !window.GlosSIApi) {
installGlosSIApi();
}

@ -2,21 +2,17 @@
import type { SteamConfig } from "../../common/util/types";
import { initTweak } from "../../common/tweakApi";
// variables here are scoped to the tweak
// and are not accessible from other tweaks or even the main script
// there is no risk of conflicts
const originalFpsCorner = Number(
((await GlosSI.getSettings()).system as SteamConfig)
.InGameOverlayShowFPSCorner
) as 0 | 1 | 2 | 3 | 4;
initTweak('HideFPSCounter', {
install: () => {
const backup: { originalFpsCorner?: number } = {};
initTweak('AnotherTweak', {
install: async () => {
backup.originalFpsCorner = Number(
((await GlosSIApi.SteamTarget.getSteamSettings()).system as SteamConfig)
.InGameOverlayShowFPSCorner
) as 0 | 1 | 2 | 3 | 4;
SteamClient.Settings.SetInGameOverlayShowFPSCorner(0);
},
uninstall: () => {
SteamClient.Settings.SetInGameOverlayShowFPSCorner(originalFpsCorner);
SteamClient.Settings.SetInGameOverlayShowFPSCorner((backup.originalFpsCorner ?? 0) as 0 | 1 | 2 | 3 | 4);
}
});

@ -1,45 +1,3 @@
import type { SteamConfig } from './util/types';
class GlosSIApi {
public getSettings(): Promise<SteamConfig> {
return fetch('http://localhost:8756/steam_settings')
.then(
(res) => res.json().then(
(json) => (json as SteamConfig).UserLocalConfigStore as SteamConfig
)
);
}
}
declare global {
interface Window {
GlosSITweaks: Record<string, {install: () => unknown; uninstall?: () => void}>;
GlosSI: InstanceType<typeof GlosSIApi>;
}
// eslint-disable-next-line
const GlosSI: InstanceType<typeof GlosSIApi>;
}
const installGlosSIApi = () => {
window.GlosSITweaks = {
GlosSI: {
install: () => {
const api = new GlosSIApi();
Object.assign(window, { GlosSI: api });
},
uninstall: () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete window.GlosSI;
}
}
};
window.GlosSITweaks.GlosSI.install();
};
if (!window.GlosSITweaks || !window.GlosSI) {
installGlosSIApi();
}
export const initTweak = <T>(name: string, tweakMain: (() => T)|{
install: () => T;

@ -11,6 +11,7 @@
"skipLibCheck": true,
"useDefineForClassFields": true,
"forceConsistentCasingInFileNames": true,
"incremental": true,
"lib": [
"esnext",
"DOM"
@ -20,6 +21,6 @@
"src/**/*"
],
"exclude": [
"node_modules"
"node_modules",
]
}
Loading…
Cancel
Save