mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core&ui: add setting provider
This commit is contained in:
10 files changed
+56
-28
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import esbuild from 'esbuild';
|
||||
import {
|
||||
Context, fs, Handler, Logger, NotFoundError, param, SettingModel, sha1,
|
||||
size, SystemModel, Types, UiContextBase,
|
||||
size, Types, UiContextBase,
|
||||
} from 'hydrooj';
|
||||
import { debounce } from 'lodash';
|
||||
import { tmpdir } from 'os';
|
||||
@@ -17,15 +17,10 @@ declare module 'hydrooj' {
|
||||
'ui-default.nav_logo_dark': string;
|
||||
}
|
||||
interface UiContextBase {
|
||||
nav_logo_dark?: string;
|
||||
constantVersion?: string;
|
||||
}
|
||||
}
|
||||
|
||||
function updateLogo() {
|
||||
UiContextBase.nav_logo_dark = SystemModel.get('ui-default.nav_logo_dark');
|
||||
}
|
||||
|
||||
const vfs: Record<string, string> = {};
|
||||
const hashes: Record<string, string> = {};
|
||||
const logger = new Logger('ui');
|
||||
@@ -140,13 +135,11 @@ export async function apply(ctx: Context) {
|
||||
ctx.Route('constant', '/constant/:version', UiConstantsHandler);
|
||||
ctx.Route('constant', '/lazy/:version/:name', UiConstantsHandler);
|
||||
ctx.Route('constant', '/resource/:version/:name', UiConstantsHandler);
|
||||
ctx.on('app/started', updateLogo);
|
||||
ctx.on('app/started', buildUI);
|
||||
const debouncedBuildUI = debounce(buildUI, 2000, { trailing: true });
|
||||
const triggerHotUpdate = (path?: string) => {
|
||||
if (path && !path.includes('/ui-default/') && !path.includes('/public/')) return;
|
||||
debouncedBuildUI();
|
||||
updateLogo();
|
||||
};
|
||||
ctx.on('system/setting', () => triggerHotUpdate());
|
||||
ctx.on('app/watch/change', triggerHotUpdate);
|
||||
|
||||
@@ -170,6 +170,7 @@ const render = (name: string, state: any) => new Promise<string>((resolve, rejec
|
||||
return state._(text.message).format(...text.params || []) + ((process.env.DEV && text.stack) ? `\n${text.stack}` : '');
|
||||
}).join('\n'),
|
||||
datetimeSpan: (arg0, arg1, arg2) => misc.datetimeSpan(arg0, arg1, arg2, state.handler.user?.timeZone),
|
||||
ctx: state.handler?.ctx,
|
||||
perm: PERM,
|
||||
PRIV,
|
||||
STATUS,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="row"><div class="columns clearfix">
|
||||
<div class="float-left">
|
||||
<a class="header--mobile__domain" href="/" target="_self">
|
||||
<img src="{{ UiContext.domain.nav_logo_dark or UiContext.nav_logo_dark }}">
|
||||
<img src="{{ ctx.setting.get('ui-default.nav_logo_dark') }}">
|
||||
</a>
|
||||
</div>
|
||||
<div class="float-right">
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<div class="row"><div class="columns clearfix">
|
||||
<ol class="nav__list nav__list--main clearfix">
|
||||
<li class="nav__list-item">
|
||||
<a href="/"><img class="nav__logo" src="{{ UiContext.domain.nav_logo_dark or UiContext.nav_logo_dark }}"></a>
|
||||
<a href="/"><img class="nav__logo" src="{{ ctx.setting.get('ui-default.nav_logo_dark') }}"></a>
|
||||
</li>
|
||||
{%- for item in overrideNav|default(ui.getNodes('Nav')) -%}{% if item.checker(handler) %}
|
||||
{{ nav_item(item) }}
|
||||
|
||||
Reference in new issue
Block a user