mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17: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,
|
||||
|
||||
Reference in new issue
Block a user