Skip to content

Commit b36f11e

Browse files
committed
Some minor cleaning up.
1 parent 19ee502 commit b36f11e

2 files changed

Lines changed: 37 additions & 31 deletions

File tree

src/renderer/src/common/vueCommon.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,30 +68,34 @@ export const useTheme = vueusecore.createGlobalState(() => {
6868
};
6969
});
7070

71-
// Composable to dynamically track and update element height as a CSS variable.
71+
// A composable to track the height of an element as a CSS variable.
7272

73-
export const setupElementHeightTracking = (
73+
export const trackElementHeight = (
7474
sourceElement: HTMLElement,
7575
targetElement: HTMLElement,
76-
cssVariableName: string = '--element-height'
76+
cssVariableName: string
7777
): (() => void) => {
7878
const updateHeight = () => {
7979
const height = sourceElement.offsetHeight;
80+
8081
targetElement.style.setProperty(cssVariableName, `${height}px`);
8182
};
8283

83-
// Set initial height.
84+
// Set the initial height.
85+
8486
updateHeight();
8587

86-
// Watch for height changes continuously, including border and padding changes.
87-
const { stop } = vueusecore.useResizeObserver(
88+
// Watch for height changes, including border and padding changes.
89+
90+
const { stop: stopTrackingElementHeight } = vueusecore.useResizeObserver(
8891
sourceElement,
8992
() => {
9093
updateHeight();
9194
},
9295
{ box: 'border-box' }
9396
);
9497

95-
// Return cleanup function.
96-
return stop;
98+
// Return the function to stop tracking the element's height.
99+
100+
return stopTrackingElementHeight;
97101
};

src/renderer/src/components/OpenCOR.vue

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<template>
2-
<BlockUI ref="blockUi"
3-
class="opencor overflow-hidden h-full"
4-
:class="showMainMenu ? 'with-main-menu' : ''"
2+
<BlockUI ref="blockUi" class="opencor overflow-hidden h-full" :class="showMainMenu ? 'with-main-menu' : ''"
53
:blocked="compBlockUiEnabled"
64
@click="activateInstance"
75
@focus="activateInstance"
@@ -140,8 +138,8 @@ const props = defineProps<IOpenCORProps>();
140138
const { isDialogActive } = provideDialogState();
141139
142140
const blockUi = vue.ref<vue.ComponentPublicInstance | null>(null);
143-
const mainMenu = vue.ref<vue.ComponentPublicInstance | null>(null);
144141
const toastId = vue.ref('opencorToast');
142+
const mainMenu = vue.ref<vue.ComponentPublicInstance | null>(null);
145143
const mainMenuId = vue.ref('opencorMainMenu');
146144
const files = vue.ref<HTMLElement | null>(null);
147145
const contents = vue.ref<InstanceType<typeof IContentsComponent> | null>(null);
@@ -162,10 +160,6 @@ const compIsActive = vue.computed(() => {
162160
return activeInstanceUid.value === crtInstanceUid;
163161
});
164162
165-
const showMainMenu = vue.computed(() => {
166-
return !electronApi && !props.omex;
167-
});
168-
169163
// Determine whether the component UI should be blocked/enabled.
170164
// Note: compBlockUiEnabled is used to determine whether PrimeVue's BlockUI component should be enabled, whereas
171165
// compUiEnabled is used to determine whether the UI should be enabled (it checks whether various dialogs are
@@ -188,6 +182,12 @@ const compUiEnabled = vue.computed(() => {
188182
return !compBlockUiEnabled.value && !isDialogActive.value;
189183
});
190184
185+
// Determine whether to show the main menu or not.
186+
187+
const showMainMenu = vue.computed(() => {
188+
return !electronApi && !props.omex;
189+
});
190+
191191
// Provide access to our progress message features.
192192
193193
export interface IProgressMessage {
@@ -940,9 +940,9 @@ vue.onMounted(() => {
940940
}, SHORT_DELAY);
941941
});
942942
943-
// Dynamically track the main menu height.
943+
// Track the height of our main menu.
944944
945-
let stopHeightTracking: (() => void) | null = null;
945+
let stopTrackingMainMenuHeight: (() => void) | null = null;
946946
947947
vue.onMounted(() => {
948948
if (!showMainMenu.value) {
@@ -954,15 +954,16 @@ vue.onMounted(() => {
954954
const blockUiElement = blockUi.value?.$el as HTMLElement | undefined;
955955
956956
if (mainMenuElement && blockUiElement) {
957-
stopHeightTracking = vueCommon.setupElementHeightTracking(mainMenuElement, blockUiElement, '--main-menu-height');
957+
stopTrackingMainMenuHeight = vueCommon.trackElementHeight(mainMenuElement, blockUiElement, '--main-menu-height');
958958
}
959959
});
960960
});
961961
962962
vue.onBeforeUnmount(() => {
963-
if (stopHeightTracking) {
964-
stopHeightTracking();
965-
stopHeightTracking = null;
963+
if (stopTrackingMainMenuHeight) {
964+
stopTrackingMainMenuHeight();
965+
966+
stopTrackingMainMenuHeight = null;
966967
}
967968
});
968969
@@ -1262,15 +1263,6 @@ const onGitHubButtonClick = async (): Promise<void> => {
12621263
color: var(--p-red-700);
12631264
}
12641265
1265-
.with-main-menu {
1266-
:deep(.p-dialog-mask) {
1267-
padding-top: var(--main-menu-height, 28px) !important;
1268-
}
1269-
:deep(.p-message) {
1270-
margin-top: calc(var(--main-menu-height, 28px) / 2) !important;
1271-
}
1272-
}
1273-
12741266
@media (prefers-color-scheme: dark) {
12751267
.connected-to-github,
12761268
:deep(.connected-to-github .pi-github) {
@@ -1300,4 +1292,14 @@ const onGitHubButtonClick = async (): Promise<void> => {
13001292
color: var(--p-red-200);
13011293
}
13021294
}
1295+
1296+
.with-main-menu {
1297+
:deep(.p-dialog-mask) {
1298+
padding-top: var(--main-menu-height) !important;
1299+
}
1300+
1301+
:deep(.p-message) {
1302+
margin-top: calc(0.5 * var(--main-menu-height)) !important;
1303+
}
1304+
}
13031305
</style>

0 commit comments

Comments
 (0)