Added the ability for characters to override the client theme

This commit is contained in:
Nensec 2024-05-06 01:37:48 +02:00
parent 0d3d111f8c
commit b463e00294
4 changed files with 29 additions and 4 deletions

View File

@ -219,6 +219,17 @@
Show high-quality portraits
</label>
</div>
<div class="form-group">
<label class="control-label" for="risingCharacterTheme">
Select character theme
<select id="risingCharacterTheme" class="form-control" v-model="risingCharacterTheme" style="flex:1;margin-right:10px">
<option value=undefined>Client theme</option>
<option disabled>---</option>
<option v-for="theme in risingAvailableThemes" :value="theme">{{theme}}</option>
</select>
</label>
</div>
</div>
<div v-show="selectedTab === '3'">
@ -334,6 +345,8 @@
</template>
<script lang="ts">
import * as fs from 'fs';
import * as path from 'path';
import {Component} from '@f-list/vue-ts';
import CustomDialog from '../components/custom_dialog';
import Modal from '../components/Modal.vue';
@ -394,6 +407,9 @@
risingFilter!: SmartFilterSettings = {} as any;
risingAvailableThemes!: ReadonlyArray<string> = [];
risingCharacterTheme!: string | undefined;
smartFilterTypes = smartFilterTypesOrigin;
async load(): Promise<void> {
@ -438,6 +454,9 @@
this.risingShowHighQualityPortraits = settings.risingShowHighQualityPortraits;
this.risingFilter = settings.risingFilter;
this.risingAvailableThemes = fs.readdirSync(path.join(__dirname, 'themes')).filter((x) => x.substr(-4) === '.css').map((x) => x.slice(0, -4));
this.risingCharacterTheme = settings.risingCharacterTheme;
}
async doImport(): Promise<void> {
@ -506,7 +525,9 @@
...this.risingFilter,
minAge: (minAge !== null && maxAge !== null) ? Math.min(minAge, maxAge) : minAge,
maxAge: (minAge !== null && maxAge !== null) ? Math.max(minAge, maxAge) : maxAge
}
},
risingCharacterTheme: this.risingCharacterTheme != "undefined" ? this.risingCharacterTheme : undefined
};
console.log('SETTINGS', minAge, maxAge, core.state.settings);

View File

@ -104,6 +104,8 @@ export class Settings implements ISettings {
},
exceptionNames: []
};
risingCharacterTheme = undefined;
}

View File

@ -240,6 +240,8 @@ export namespace Settings {
readonly risingShowHighQualityPortraits: boolean;
readonly risingFilter: SmartFilterSettings;
readonly risingCharacterTheme: string | undefined;
}
}

View File

@ -543,7 +543,7 @@
}
return {
[`theme-${this.settings.theme}`]: true,
[`theme-${core.state.settings.risingCharacterTheme || this.settings.theme}`]: true,
colorblindMode: core.state.settings.risingColorblindMode,
disableWindowsHighContrast: core.state.generalSettings?.risingDisableWindowsHighContrast || false
};
@ -593,9 +593,9 @@
get styling(): string {
try {
return `<style id="themeStyle">${fs.readFileSync(path.join(__dirname, `themes/${this.settings.theme}.css`), 'utf8').toString()}</style>`;
return `<style id="themeStyle">${fs.readFileSync(path.join(__dirname, `themes/${((this.character != undefined && core.state.settings.risingCharacterTheme) || this.settings.theme)}.css`), 'utf8').toString()}</style>`;
} catch(e) {
if((<Error & {code: string}>e).code === 'ENOENT' && this.settings.theme !== 'default') {
if((<Error & {code: string}>e).code === 'ENOENT' && this.settings.theme !== 'default') {
this.settings.theme = 'default';
return this.styling;
}