refactor: remove dead exports, unused params, and stale config
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import Store from 'electron-store';
|
import Store from 'electron-store';
|
||||||
import { detectPlatform } from './platform';
|
|
||||||
|
|
||||||
export interface Keybind {
|
export interface Keybind {
|
||||||
key: string;
|
key: string;
|
||||||
@@ -112,10 +111,6 @@ export interface AppConfig {
|
|||||||
y: number | undefined;
|
y: number | undefined;
|
||||||
maximized: boolean;
|
maximized: boolean;
|
||||||
};
|
};
|
||||||
platform: {
|
|
||||||
detectedOS: string;
|
|
||||||
gpuBackend: string;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_KEYBINDS: AppConfig['keybinds'] = {
|
export const DEFAULT_KEYBINDS: AppConfig['keybinds'] = {
|
||||||
@@ -131,7 +126,6 @@ export const DEFAULT_KEYBINDS: AppConfig['keybinds'] = {
|
|||||||
fullscreenToggle: { key: 'F11', ctrl: false, shift: false, alt: false },
|
fullscreenToggle: { key: 'F11', ctrl: false, shift: false, alt: false },
|
||||||
};
|
};
|
||||||
|
|
||||||
const platformInfo = detectPlatform();
|
|
||||||
|
|
||||||
export const config = new Store<AppConfig>({
|
export const config = new Store<AppConfig>({
|
||||||
name: 'krunker-civilian-config',
|
name: 'krunker-civilian-config',
|
||||||
@@ -222,9 +216,5 @@ export const config = new Store<AppConfig>({
|
|||||||
y: undefined,
|
y: undefined,
|
||||||
maximized: true,
|
maximized: true,
|
||||||
},
|
},
|
||||||
platform: {
|
|
||||||
detectedOS: platformInfo.os,
|
|
||||||
gpuBackend: platformInfo.gpuBackend,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
+2
-2
@@ -551,7 +551,7 @@ async function launchApp(): Promise<void> {
|
|||||||
const ALLOWED_CONFIG_KEYS = new Set<string>([
|
const ALLOWED_CONFIG_KEYS = new Set<string>([
|
||||||
'window', 'performance', 'game', 'swapper', 'matchmaker',
|
'window', 'performance', 'game', 'swapper', 'matchmaker',
|
||||||
'keybinds', 'userscripts', 'ui', 'discord', 'translator',
|
'keybinds', 'userscripts', 'ui', 'discord', 'translator',
|
||||||
'advanced', 'accounts', 'tabWindow', 'platform',
|
'advanced', 'accounts', 'tabWindow',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
ipcMain.handle('get-version', () => appVersion);
|
ipcMain.handle('get-version', () => appVersion);
|
||||||
@@ -745,7 +745,7 @@ async function launchApp(): Promise<void> {
|
|||||||
|
|
||||||
// ── Action button IPC handlers ──
|
// ── Action button IPC handlers ──
|
||||||
ipcMain.handle('open-electron-log', () => {
|
ipcMain.handle('open-electron-log', () => {
|
||||||
shell.openPath(getLogPath('electron'));
|
shell.openPath(getLogPath());
|
||||||
});
|
});
|
||||||
ipcMain.handle('reset-swapper', async () => {
|
ipcMain.handle('reset-swapper', async () => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
+1
-1
@@ -67,7 +67,7 @@ function makeLogger(getStream: () => WriteStream) {
|
|||||||
|
|
||||||
export const electronLog = makeLogger(() => electronStream);
|
export const electronLog = makeLogger(() => electronStream);
|
||||||
|
|
||||||
export function getLogPath(_type: 'electron'): string {
|
export function getLogPath(): string {
|
||||||
init();
|
init();
|
||||||
return electronPath;
|
return electronPath;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,10 +61,10 @@ function startHPCounter(): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function stopHPCounter(): void {
|
function stopHPCounter(): void {
|
||||||
if (hpCheckInterval) { clearInterval(hpCheckInterval); hpCheckInterval = null; }
|
clearInterval(hpCheckInterval!); hpCheckInterval = null;
|
||||||
if (hpObserver) { hpObserver.disconnect(); hpObserver = null; }
|
hpObserver?.disconnect(); hpObserver = null;
|
||||||
if (hpCounterEl) { hpCounterEl.remove(); hpCounterEl = null; }
|
hpCounterEl?.remove(); hpCounterEl = null;
|
||||||
if (hpTimeout) { clearTimeout(hpTimeout); hpTimeout = null; }
|
clearTimeout(hpTimeout!); hpTimeout = null;
|
||||||
hpPointCounter = null;
|
hpPointCounter = null;
|
||||||
hpEnemyOBJ = 0;
|
hpEnemyOBJ = 0;
|
||||||
}
|
}
|
||||||
@@ -72,11 +72,6 @@ function stopHPCounter(): void {
|
|||||||
export function initHPCounter(): void { startHPCounter(); }
|
export function initHPCounter(): void { startHPCounter(); }
|
||||||
export function destroyHPCounter(): void { stopHPCounter(); }
|
export function destroyHPCounter(): void { stopHPCounter(); }
|
||||||
|
|
||||||
export function setHPCounterEnabled(enabled: boolean): void {
|
|
||||||
stopHPCounter();
|
|
||||||
if (enabled) startHPCounter();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Rank Progress Tracker ──
|
// ── Rank Progress Tracker ──
|
||||||
|
|
||||||
interface RankInfo {
|
interface RankInfo {
|
||||||
|
|||||||
@@ -1427,7 +1427,7 @@ function renderUserscriptsSection(body: HTMLElement): void {
|
|||||||
function renderScriptSettings(inst: UserscriptInstance, container: HTMLElement): void {
|
function renderScriptSettings(inst: UserscriptInstance, container: HTMLElement): void {
|
||||||
if (!inst.settings) return;
|
if (!inst.settings) return;
|
||||||
|
|
||||||
for (const [key, setting] of Object.entries(inst.settings)) {
|
for (const [, setting] of Object.entries(inst.settings)) {
|
||||||
const typeClass = setting.type === 'bool' ? 'bool' : setting.type === 'sel' ? 'sel' : setting.type === 'num' ? 'num' : setting.type === 'keybind' ? 'keybind' : '';
|
const typeClass = setting.type === 'bool' ? 'bool' : setting.type === 'sel' ? 'sel' : setting.type === 'num' ? 'num' : setting.type === 'keybind' ? 'keybind' : '';
|
||||||
const row = document.createElement('div');
|
const row = document.createElement('div');
|
||||||
row.className = 'setting settName safety-0' + (typeClass ? ' ' + typeClass : '');
|
row.className = 'setting settName safety-0' + (typeClass ? ' ' + typeClass : '');
|
||||||
@@ -1447,7 +1447,7 @@ function renderScriptSettings(inst: UserscriptInstance, container: HTMLElement):
|
|||||||
input.addEventListener('change', () => {
|
input.addEventListener('change', () => {
|
||||||
setting.value = input.checked;
|
setting.value = input.checked;
|
||||||
if (typeof setting.changed === 'function') setting.changed(setting.value);
|
if (typeof setting.changed === 'function') setting.changed(setting.value);
|
||||||
saveScriptSetting(inst, key);
|
saveScriptSetting(inst);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1463,7 +1463,7 @@ function renderScriptSettings(inst: UserscriptInstance, container: HTMLElement):
|
|||||||
input.addEventListener('change', () => {
|
input.addEventListener('change', () => {
|
||||||
setting.value = parseFloat(input.value) || 0;
|
setting.value = parseFloat(input.value) || 0;
|
||||||
if (typeof setting.changed === 'function') setting.changed(setting.value);
|
if (typeof setting.changed === 'function') setting.changed(setting.value);
|
||||||
saveScriptSetting(inst, key);
|
saveScriptSetting(inst);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1483,7 +1483,7 @@ function renderScriptSettings(inst: UserscriptInstance, container: HTMLElement):
|
|||||||
select.addEventListener('change', () => {
|
select.addEventListener('change', () => {
|
||||||
setting.value = select.value;
|
setting.value = select.value;
|
||||||
if (typeof setting.changed === 'function') setting.changed(setting.value);
|
if (typeof setting.changed === 'function') setting.changed(setting.value);
|
||||||
saveScriptSetting(inst, key);
|
saveScriptSetting(inst);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1496,7 +1496,7 @@ function renderScriptSettings(inst: UserscriptInstance, container: HTMLElement):
|
|||||||
input.addEventListener('input', () => {
|
input.addEventListener('input', () => {
|
||||||
setting.value = input.value;
|
setting.value = input.value;
|
||||||
if (typeof setting.changed === 'function') setting.changed(setting.value);
|
if (typeof setting.changed === 'function') setting.changed(setting.value);
|
||||||
saveScriptSetting(inst, key);
|
saveScriptSetting(inst);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1510,7 +1510,7 @@ function renderScriptSettings(inst: UserscriptInstance, container: HTMLElement):
|
|||||||
setting.value = newBind;
|
setting.value = newBind;
|
||||||
keyEl.textContent = keybindDisplayString(newBind);
|
keyEl.textContent = keybindDisplayString(newBind);
|
||||||
if (typeof setting.changed === 'function') setting.changed(setting.value);
|
if (typeof setting.changed === 'function') setting.changed(setting.value);
|
||||||
saveScriptSetting(inst, key);
|
saveScriptSetting(inst);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
row.appendChild(keyEl);
|
row.appendChild(keyEl);
|
||||||
@@ -1522,7 +1522,7 @@ function renderScriptSettings(inst: UserscriptInstance, container: HTMLElement):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveScriptSetting(inst: UserscriptInstance, _key: string): void {
|
function saveScriptSetting(inst: UserscriptInstance): void {
|
||||||
if (!inst.settings) return;
|
if (!inst.settings) return;
|
||||||
const prefs: Record<string, unknown> = {};
|
const prefs: Record<string, unknown> = {};
|
||||||
for (const [k, s] of Object.entries(inst.settings)) {
|
for (const [k, s] of Object.entries(inst.settings)) {
|
||||||
|
|||||||
+2
-29
@@ -19,37 +19,10 @@ export function escapeHtml(s: string): string {
|
|||||||
return s.replace(/[&<>"']/g, c => HTML_ESCAPE_MAP[c]);
|
return s.replace(/[&<>"']/g, c => HTML_ESCAPE_MAP[c]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Chat message injection ──
|
|
||||||
// Creates messages in #chatHolder inside a persistent #kpcMessageHolder div.
|
|
||||||
// timeout=0 means the message is persistent (not auto-removed).
|
|
||||||
|
|
||||||
export function genChatMsg(text: string, timeout = 2.25): HTMLElement | null {
|
|
||||||
const chatHolder = document.getElementById('chatHolder');
|
|
||||||
if (!chatHolder) return null;
|
|
||||||
if (!document.getElementById('kpcMessageHolder')) {
|
|
||||||
chatHolder.insertAdjacentHTML('afterbegin', '<div id="kpcMessageHolder"></div>');
|
|
||||||
}
|
|
||||||
const holder = document.getElementById('kpcMessageHolder')!;
|
|
||||||
holder.insertAdjacentHTML('beforeend',
|
|
||||||
'<div class="chatHolder_kpc"><div class="chatItem_kpc"><span class="chatMsg_kpc">' +
|
|
||||||
escapeHtml(text) + '</span></div></div>');
|
|
||||||
const elem = holder.lastElementChild as HTMLElement;
|
|
||||||
if (timeout !== 0) {
|
|
||||||
setTimeout(() => { elem.remove(); }, timeout * 1000);
|
|
||||||
}
|
|
||||||
return elem;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Filename sanitisation ──
|
|
||||||
|
|
||||||
export function sanitizeFilename(name: string): string {
|
|
||||||
return name.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Shared CSS constants ──
|
// ── Shared CSS constants ──
|
||||||
|
|
||||||
export const DEATH_ANIM_BLOCK_ID = 'kpc-animationBlock';
|
const DEATH_ANIM_BLOCK_ID = 'kpc-animationBlock';
|
||||||
export const DEATH_ANIM_BLOCK_CSS =
|
const DEATH_ANIM_BLOCK_CSS =
|
||||||
'.death-ui-bottom, .death-ui-bottom-empty { animation: none !important; transition: none !important; }';
|
'.death-ui-bottom, .death-ui-bottom-empty { animation: none !important; transition: none !important; }';
|
||||||
|
|
||||||
/** Inject or remove the death screen animation block style element. */
|
/** Inject or remove the death screen animation block style element. */
|
||||||
|
|||||||
Reference in New Issue
Block a user