From b26fd9faf538801f65450647302b17413294a391 Mon Sep 17 00:00:00 2001 From: Peter Repukat Date: Mon, 30 Jan 2023 12:05:33 +0100 Subject: [PATCH] Update SteamTweaks --- SteamTweaks/rollup.config.js | 51 ++++++++++++++---- SteamTweaks/src/GlosSITweaks.ts | 54 +++++++++++++++++++ .../src/Tweaks/Overlay/HideFPSCounter.ts | 20 +++---- SteamTweaks/src/common/tweakApi.ts | 42 --------------- SteamTweaks/tsconfig.json | 3 +- 5 files changed, 106 insertions(+), 64 deletions(-) create mode 100644 SteamTweaks/src/GlosSITweaks.ts diff --git a/SteamTweaks/rollup.config.js b/SteamTweaks/rollup.config.js index c77730b..3eec110 100644 --- a/SteamTweaks/rollup.config.js +++ b/SteamTweaks/rollup.config.js @@ -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()] -}; \ No newline at end of file +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], + } + }) +]; \ No newline at end of file diff --git a/SteamTweaks/src/GlosSITweaks.ts b/SteamTweaks/src/GlosSITweaks.ts new file mode 100644 index 0000000..dd5140b --- /dev/null +++ b/SteamTweaks/src/GlosSITweaks.ts @@ -0,0 +1,54 @@ +import type { SteamConfig } from './common/util/types'; +class SteamTargetApi { + public getSteamSettings(): Promise { + 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; + } + + // eslint-disable-next-line + const GlosSIApi: InstanceType; + 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(); +} diff --git a/SteamTweaks/src/Tweaks/Overlay/HideFPSCounter.ts b/SteamTweaks/src/Tweaks/Overlay/HideFPSCounter.ts index f7865cc..c8a37a8 100644 --- a/SteamTweaks/src/Tweaks/Overlay/HideFPSCounter.ts +++ b/SteamTweaks/src/Tweaks/Overlay/HideFPSCounter.ts @@ -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); } }); diff --git a/SteamTweaks/src/common/tweakApi.ts b/SteamTweaks/src/common/tweakApi.ts index df2544e..7b3ad99 100644 --- a/SteamTweaks/src/common/tweakApi.ts +++ b/SteamTweaks/src/common/tweakApi.ts @@ -1,45 +1,3 @@ -import type { SteamConfig } from './util/types'; -class GlosSIApi { - public getSettings(): Promise { - 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 unknown; uninstall?: () => void}>; - GlosSI: InstanceType; - } - // eslint-disable-next-line - const GlosSI: InstanceType; -} - - -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 = (name: string, tweakMain: (() => T)|{ install: () => T; diff --git a/SteamTweaks/tsconfig.json b/SteamTweaks/tsconfig.json index 1f74fb2..44bc984 100644 --- a/SteamTweaks/tsconfig.json +++ b/SteamTweaks/tsconfig.json @@ -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", ] } \ No newline at end of file