Skip to content

Commit 0195785

Browse files
committed
Use OverlayScrollbars
1 parent 34bb3ec commit 0195785

File tree

9 files changed

+73
-23
lines changed

9 files changed

+73
-23
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"@tauri-apps/api": "^1.2.0",
1616
"@vueuse/core": "^9.12.0",
1717
"dayjs": "^1.11.7",
18+
"overlayscrollbars": "^2.2.0",
19+
"overlayscrollbars-vue": "^0.5.1",
1820
"p-all": "^4.0.0",
1921
"pinia": "^2.0.29",
2022
"redaxios": "^0.5.1",

pnpm-lock.yaml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.vue

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import AppContent from './components/AppContent.vue'
44
import AppSidebar from './components/AppSidebar.vue'
55
import HomePage from './pages/HomePage.vue'
66
import SettingsPage from './pages/SettingsPage.vue'
7-
import { ColorPreference, FETCH_INTERVAL_DURATION, Page, prefersDark } from './constants'
7+
import { ColorPreference, FETCH_INTERVAL_DURATION, Page } from './constants'
88
import { useStore } from './stores/store'
99
import LandingPage from './pages/LandingPage.vue'
1010
import { useInterval } from './composables/useInterval'
@@ -18,18 +18,7 @@ useInterval(() => {
1818
}, FETCH_INTERVAL_DURATION)
1919
2020
watchEffect(() => {
21-
const preference = AppStorage.get('colorPreference')
22-
23-
let theme: ColorPreference.Dark | ColorPreference.Light
24-
25-
if (preference === ColorPreference.Dark)
26-
theme = ColorPreference.Dark
27-
else if (preference === ColorPreference.Light)
28-
theme = ColorPreference.Light
29-
else
30-
theme = prefersDark.value ? ColorPreference.Dark : ColorPreference.Light
31-
32-
if (theme === ColorPreference.Dark)
21+
if (store.theme === ColorPreference.Dark)
3322
document.documentElement.classList.remove('light-theme')
3423
else
3524
document.documentElement.classList.add('light-theme')

src/assets/main.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ $colors: (
4848
line-height: 20px;
4949

5050
--accent-color: rgb(23, 115, 243);
51+
--os-handle-bg: var(--accent-color) !important;
5152

5253
// Colors look really bad on Windows and Linux because there is no glass effect.
5354
// Some colors are different because of that.

src/components/AppContent.vue

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,60 @@
11
<script lang="ts" setup>
2-
import { ref, watch } from 'vue'
2+
import { onMounted, ref, watch } from 'vue'
3+
import { type OverlayScrollbarsComponentRef, OverlayScrollbarsComponent as ScrollView } from 'overlayscrollbars-vue'
4+
import { type PartialOptions as OverlayScrollbarsOptions } from 'overlayscrollbars'
5+
import { computedEager } from '@vueuse/core'
36
import { useTauriEvent } from '../composables/useTauriEvent'
47
import { useStore } from '../stores/store'
58
import type { Option } from '../types'
69
import { batchFn } from '../utils/batch'
10+
import { ColorPreference } from '../constants'
711
812
const store = useStore()
9-
const mainEl = ref<Option<HTMLElement>>(null)
13+
const scrollView = ref<Option<OverlayScrollbarsComponentRef>>(null)
1014
1115
const focus = batchFn(() => {
12-
mainEl.value?.focus()
16+
scrollView.value?.getElement()?.focus()
1317
})
1418
1519
watch(() => store.currentPage, focus, { flush: 'post' })
1620
useTauriEvent('window:hidden', focus)
21+
onMounted(focus)
22+
23+
watch(() => store.currentPage, () => {
24+
const element = scrollView.value?.osInstance()?.elements().scrollOffsetElement
25+
if (element)
26+
element.scrollTop = 0
27+
}, { flush: 'post' })
28+
29+
const options = computedEager<OverlayScrollbarsOptions>(() => ({
30+
scrollbars: {
31+
autoHide: 'scroll',
32+
theme: store.theme === ColorPreference.Dark ? 'os-theme-light' : 'os-theme-dark',
33+
},
34+
}))
1735
</script>
1836

1937
<template>
20-
<main
21-
ref="mainEl"
38+
<ScrollView
39+
ref="scrollView"
40+
element="main"
41+
defer
42+
:options="options"
2243
tabindex="-1"
2344
class="main"
2445
>
2546
<slot />
26-
</main>
47+
</ScrollView>
2748
</template>
2849

2950
<style lang="scss" scoped>
3051
.main {
3152
width: 100%;
3253
height: 100%;
33-
overflow: hidden;
54+
overflow: auto;
3455
background-color: var(--content-bg);
3556
position: relative;
3657
outline: none;
58+
scroll-padding: 10px 10px;
3759
}
3860
</style>

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import './assets/main.scss'
22
import 'wowerlay/style.css'
33
import 'focus-visible'
4+
import 'overlayscrollbars/overlayscrollbars.css'
45

56
import { createApp } from 'vue'
67
import { createPinia } from 'pinia'

src/pages/HomePage.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ whenever(() => store.skeletonVisible, () => {
353353
padding: 10px;
354354
width: 100%;
355355
height: 100%;
356-
overflow-y: auto;
357356
scroll-padding-top: 10px;
358357
scroll-padding-bottom: 10px;
359358
position: relative;

src/pages/SettingsPage.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ function handleScroll(e: Event) {
268268
top: 0;
269269
width: 100%;
270270
height: 100%;
271-
overflow-y: auto;
272271
display: flex;
273272
flex-flow: column nowrap;
274273

src/stores/store.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { readonly, ref, shallowRef, triggerRef, watchEffect } from 'vue'
55
import pAll from 'p-all'
66
import { type UpdateManifest, installUpdate } from '@tauri-apps/api/updater'
77
import { relaunch } from '@tauri-apps/api/process'
8+
import { computedEager } from '@vueuse/core'
89
import { type Thread, getNotifications, markNotificationAsRead, unsubscribeNotification } from '../api/notifications'
9-
import { InvokeCommand, Page, notificationApiMutex } from '../constants'
10+
import { ColorPreference, InvokeCommand, Page, notificationApiMutex, prefersDark } from '../constants'
1011
import { AppStorage } from '../storage'
1112
import type { AppStorageContext, NotificationList, Option, PageState } from '../types'
1213
import { filterNewThreads, isRepository, isThread, toNotificationList } from '../utils/notification'
@@ -200,6 +201,21 @@ export const useStore = defineStore('store', () => {
200201
}
201202
}
202203

204+
const theme = computedEager(() => {
205+
const preference = AppStorage.get('colorPreference')
206+
207+
let theme: ColorPreference.Dark | ColorPreference.Light
208+
209+
if (preference === ColorPreference.Dark)
210+
theme = ColorPreference.Dark
211+
else if (preference === ColorPreference.Light)
212+
theme = ColorPreference.Light
213+
else
214+
theme = prefersDark.value ? ColorPreference.Dark : ColorPreference.Light
215+
216+
return theme
217+
})
218+
203219
return {
204220
newRelease,
205221
notifications,
@@ -211,6 +227,7 @@ export const useStore = defineStore('store', () => {
211227
currentPageState,
212228
checkedItems,
213229
installingUpate,
230+
theme,
214231
updateAndRestart,
215232
unsubscribeCheckedNotifications,
216233
removeNotificationById,

0 commit comments

Comments
 (0)