Skip to content

Commit 980077f

Browse files
authored
Add UI performance-related settings (#6747)
2 parents 5daca27 + 1d0503d commit 980077f

File tree

11 files changed

+107
-4
lines changed

11 files changed

+107
-4
lines changed

apps/client/src/stylesheets/style.css

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,28 @@
2828
--ck-mention-list-max-height: 500px;
2929
}
3030

31+
body#trilium-app.motion-disabled *,
32+
body#trilium-app.motion-disabled *::before,
33+
body#trilium-app.motion-disabled *::after {
34+
/* Disable transitions and animations */
35+
transition: none !important;
36+
animation: none !important;
37+
}
38+
39+
body#trilium-app.shadows-disabled *,
40+
body#trilium-app.shadows-disabled *::before,
41+
body#trilium-app.shadows-disabled *::after {
42+
/* Disable shadows */
43+
box-shadow: none !important;
44+
}
45+
46+
body#trilium-app.backdrop-effects-disabled *,
47+
body#trilium-app.backdrop-effects-disabled *::before,
48+
body#trilium-app.backdrop-effects-disabled *::after {
49+
/* Disable backdrop effects */
50+
backdrop-filter: none !important;
51+
}
52+
3153
.table {
3254
--bs-table-bg: transparent !important;
3355
}
@@ -355,7 +377,7 @@ body.desktop .tabulator-popup-container {
355377

356378
@supports (animation-fill-mode: forwards) {
357379
/* Delay the opening of submenus */
358-
body.desktop .dropdown-submenu .dropdown-menu {
380+
body.desktop:not(.motion-disabled) .dropdown-submenu .dropdown-menu {
359381
opacity: 0;
360382
animation-fill-mode: forwards;
361383
animation-delay: var(--submenu-opening-delay);

apps/client/src/stylesheets/theme-next-dark.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989

9090
--menu-text-color: #e3e3e3;
9191
--menu-background-color: #222222d9;
92+
--menu-background-color-no-backdrop: #1b1b1b;
9293
--menu-item-icon-color: #8c8c8c;
9394
--menu-item-disabled-opacity: 0.5;
9495
--menu-item-keyboard-shortcut-color: #ffffff8f;

apps/client/src/stylesheets/theme-next-light.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383

8484
--menu-text-color: #272727;
8585
--menu-background-color: #ffffffd9;
86+
--menu-background-color-no-backdrop: #fdfdfd;
8687
--menu-item-icon-color: #727272;
8788
--menu-item-disabled-opacity: 0.6;
8889
--menu-item-keyboard-shortcut-color: #666666a8;

apps/client/src/stylesheets/theme-next/base.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@
8383
--tab-note-icons: true;
8484
}
8585

86+
body.backdrop-effects-disabled {
87+
/* Backdrop effects are disabled, replace the menu background color with the
88+
* no-backdrop fallback color */
89+
--menu-background-color: var(--menu-background-color-no-backdrop);
90+
}
91+
8692
/*
8793
* MENUS
8894
*

apps/client/src/translations/en/translation.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,12 @@
11131113
"layout-vertical-description": "launcher bar is on the left (default)",
11141114
"layout-horizontal-description": "launcher bar is underneath the tab bar, the tab bar is now full width."
11151115
},
1116+
"ui-performance": {
1117+
"title": "Performance",
1118+
"enable-motion": "Enable transitions and animations",
1119+
"enable-shadows": "Enable shadows",
1120+
"enable-backdrop-effects": "Enable background effects for menus, popups and panels"
1121+
},
11161122
"ai_llm": {
11171123
"not_started": "Not started",
11181124
"title": "AI Settings",

apps/client/src/widgets/containers/root_container.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import utils from "../../services/utils.js";
2-
import type BasicWidget from "../basic_widget.js";
1+
import { EventData } from "../../components/app_context.js";
32
import FlexContainer from "./flex_container.js";
3+
import options from "../../services/options.js";
4+
import type BasicWidget from "../basic_widget.js";
5+
import utils from "../../services/utils.js";
46

57
/**
68
* The root container is the top-most widget/container, from which the entire layout derives.
@@ -27,15 +29,45 @@ export default class RootContainer extends FlexContainer<BasicWidget> {
2729
window.visualViewport?.addEventListener("resize", () => this.#onMobileResize());
2830
}
2931

32+
this.#setMotion(options.is("motionEnabled"));
33+
this.#setShadows(options.is("shadowsEnabled"));
34+
this.#setBackdropEffects(options.is("backdropEffectsEnabled"));
35+
3036
return super.render();
3137
}
3238

39+
entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
40+
if (loadResults.isOptionReloaded("motionEnabled")) {
41+
this.#setMotion(options.is("motionEnabled"));
42+
}
43+
44+
if (loadResults.isOptionReloaded("shadowsEnabled")) {
45+
this.#setShadows(options.is("shadowsEnabled"));
46+
}
47+
48+
if (loadResults.isOptionReloaded("backdropEffectsEnabled")) {
49+
this.#setBackdropEffects(options.is("backdropEffectsEnabled"));
50+
}
51+
}
52+
3353
#onMobileResize() {
3454
const currentViewportHeight = getViewportHeight();
3555
const isKeyboardOpened = (currentViewportHeight < this.originalViewportHeight);
3656
this.$widget.toggleClass("virtual-keyboard-opened", isKeyboardOpened);
3757
}
3858

59+
#setMotion(enabled: boolean) {
60+
document.body.classList.toggle("motion-disabled", !enabled);
61+
jQuery.fx.off = !enabled;
62+
}
63+
64+
#setShadows(enabled: boolean) {
65+
document.body.classList.toggle("shadows-disabled", !enabled);
66+
}
67+
68+
#setBackdropEffects(enabled: boolean) {
69+
document.body.classList.toggle("backdrop-effects-disabled", !enabled);
70+
}
3971
}
4072

4173
function getViewportHeight() {

apps/client/src/widgets/type_widgets/options/appearance.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export default function AppearanceSettings() {
8888
<ApplicationTheme />
8989
{overrideThemeFonts === "true" && <Fonts />}
9090
{isElectron() && <ElectronIntegration /> }
91+
<Performance />
9192
<MaxContentWidth />
9293
<RelatedSettings items={[
9394
{
@@ -245,6 +246,30 @@ function ElectronIntegration() {
245246
)
246247
}
247248

249+
function Performance() {
250+
const [ motionEnabled, setMotionEnabled ] = useTriliumOptionBool("motionEnabled");
251+
const [ shadowsEnabled, setShadowsEnabled ] = useTriliumOptionBool("shadowsEnabled");
252+
const [ backdropEffectsEnabled, setBackdropEffectsEnabled ] = useTriliumOptionBool("backdropEffectsEnabled");
253+
254+
return <OptionsSection title={t("ui-performance.title")}>
255+
<FormCheckbox
256+
label={t("ui-performance.enable-motion")}
257+
currentValue={motionEnabled} onChange={setMotionEnabled}
258+
/>
259+
260+
<FormCheckbox
261+
label={t("ui-performance.enable-shadows")}
262+
currentValue={shadowsEnabled} onChange={setShadowsEnabled}
263+
/>
264+
265+
<FormCheckbox
266+
label={t("ui-performance.enable-backdrop-effects")}
267+
currentValue={backdropEffectsEnabled} onChange={setBackdropEffectsEnabled}
268+
/>
269+
</OptionsSection>
270+
}
271+
272+
248273
function MaxContentWidth() {
249274
const [ maxContentWidth, setMaxContentWidth ] = useTriliumOption("maxContentWidth");
250275

apps/server/src/assets/views/desktop.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<link rel="manifest" crossorigin="use-credentials" href="manifest.webmanifest">
1010
<title>Trilium Notes</title>
1111
</head>
12-
<body class="desktop heading-style-<%= headingStyle %> layout-<%= layoutOrientation %> platform-<%= platform %> <%= isElectron ? 'electron' : '' %> <%= hasNativeTitleBar ? 'native-titlebar' : '' %> <%= hasBackgroundEffects ? 'background-effects' : '' %>">
12+
<body id="trilium-app" class="desktop heading-style-<%= headingStyle %> layout-<%= layoutOrientation %> platform-<%= platform %> <%= isElectron ? 'electron' : '' %> <%= hasNativeTitleBar ? 'native-titlebar' : '' %> <%= hasBackgroundEffects ? 'background-effects' : '' %>">
1313
<noscript><%= t("javascript-required") %></noscript>
1414

1515
<script>

apps/server/src/routes/api/options.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ const ALLOWED_OPTIONS = new Set<OptionNames>([
6363
"dailyBackupEnabled",
6464
"weeklyBackupEnabled",
6565
"monthlyBackupEnabled",
66+
"motionEnabled",
67+
"shadowsEnabled",
68+
"backdropEffectsEnabled",
6669
"maxContentWidth",
6770
"compressImages",
6871
"downloadImagesAutomatically",

apps/server/src/services/options_init.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ const defaultOptions: DefaultOption[] = [
152152
},
153153
isSynced: false
154154
},
155+
{ name: "motionEnabled", value: "true", isSynced: false },
156+
{ name: "shadowsEnabled", value: "true", isSynced: false },
157+
{ name: "backdropEffectsEnabled", value: "true", isSynced: false },
158+
155159

156160
// Internationalization
157161
{ name: "locale", value: "en", isSynced: true },

0 commit comments

Comments
 (0)