Skip to content

Commit

Permalink
fix: reload only on page navigation event
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Jun 4, 2024
1 parent af51c9d commit f6b0062
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
6 changes: 3 additions & 3 deletions packages/app-frontend/src/features/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default defineComponent({
},
setup() {
const { isConnected, isInitializing, showDisplayDisconnected, connectedTimes } = useAppConnection()
const { isConnected, isInitializing, showDisplayDisconnected, reloadTimes } = useAppConnection()
function updateTheme(theme: string) {
if (theme === 'dark' || theme === 'high-contrast' || (theme === 'auto' && chromeTheme === 'dark')) {
Expand Down Expand Up @@ -81,7 +81,7 @@ export default defineComponent({
isConnected,
isInitializing,
showDisplayDisconnected,
connectedTimes,
reloadTimes,
showAppsSelector,
orientation,
isChrome,
Expand Down Expand Up @@ -110,7 +110,7 @@ export default defineComponent({

<div
v-else
:key="connectedTimes"
:key="reloadTimes"
class="w-full h-full flex"
:class="{
'flex-col': orientation === 'portrait',
Expand Down
18 changes: 13 additions & 5 deletions packages/app-frontend/src/features/connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { useNow } from '@vueuse/core'
const isConnected = ref(false)
const isInitializing = ref(true)
const lastDisconnect = ref(0)
const connectedTimes = ref(0)
const reloadTimes = ref(0)
let reloadRegistered = false

export function useAppConnection() {
const now = useNow({
Expand All @@ -26,20 +27,27 @@ export function useAppConnection() {
isInitializing,
lastDisconnect,
showDisplayDisconnected,
connectedTimes,
reloadTimes,
}
}

export function setAppConnected(value: boolean, force = false) {
export function setAppConnected(value: boolean, force = false, fromReload = false) {
// We got disconnected from a page reload
if (!value) {
reloadRegistered = fromReload
}

if (force) {
lastDisconnect.value = 0
}
else if (!value && isConnected.value) {
lastDisconnect.value = Date.now()
}
isConnected.value = value
if (value) {
connectedTimes.value++

// We are reconnected after a page reload
if (value && reloadRegistered) {
reloadTimes.value++
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/app-frontend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function initDevTools(shell: Shell) {
app.mount('#app')
connectApp(app, shell)
shell.onReload(() => {
setAppConnected(false, true)
setAppConnected(false, true, true)
getBridge()?.removeAllListeners()
connectApp(app, shell)
})
Expand Down

1 comment on commit f6b0062

@CrawfordW
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fix! Seems to work fine now.

Please sign in to comment.