Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(themes): active multi-themes #720

Merged
merged 3 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/core/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ export async function bootstrap() {
consola.success(
`[${prefix + pid}] 服务器正在监听: ${listening_ip}:${PORT}`,
);
consola.success(`Mog Core 已启动. ${chalk.yellow(`+${performance.now() | 0}ms`)}`);
Logger.log(
`NxServer 已启动. ${chalk.yellow(`+${performance.now() | 0}ms`)}`,
`Mog Core 已启动. ${chalk.yellow(`+${performance.now() | 0}ms`)}`,
);
});
if (module.hot) {
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/modules/themes/themes.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class ThemesController {
});
}

@Patch('/:id')
@Get('/:id/active')
@Auth()
@ApiOperation({ summary: '激活主题' })
async active(@Param('id') id: string) {
Expand Down
10 changes: 3 additions & 7 deletions apps/themes-service/src/themes-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,9 @@ export class ThemesServiceService {
}
_theme.active = true;
if (!theme) {
await this.configService.patchAndValidate('seo', {
...(await this.configService.get('seo')),
});

await this.configService.patchAndValidate('themes', [
...themes.filter((t) => t.id !== activeTheme?.id),
...(activeTheme ? [activeTheme] : []),
(activeTheme ? activeTheme : undefined),
_theme,
]);
return true;
Expand All @@ -352,11 +348,11 @@ export class ThemesServiceService {
...themes
.filter((t) => t.id !== id)
.filter((t) => t.id !== activeTheme?.id),
(activeTheme ? activeTheme : undefined),
_theme, // 重新获取一次, 防止配置文件被修改而无更新
]);
this.setENV(_theme.path);
this.untrackThemeChange(); // 取消旧主题的监听
this.trackThemeChange(); // 监听新主题的变化
this.refreshThemes();

activeTheme &&
this.notificationService.emit(ThemesEvents.ThemeAfterDeactivate, {
Expand Down