first commit
This commit is contained in:
34
packages/electron/src/index.ts
Normal file
34
packages/electron/src/index.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import type { NativePlatformAdapter, NativeRouterRuntime } from '@native-vue-router/core'
|
||||
|
||||
export interface ElectronCommandLine {
|
||||
appendSwitch(name: string, value?: string): void
|
||||
}
|
||||
|
||||
export function disableElectronHistoryGestures(commandLine: ElectronCommandLine) {
|
||||
commandLine.appendSwitch('disable-features', 'OverscrollHistoryNavigation')
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
nativeVueHost?: {
|
||||
onBack(callback: () => void): () => void
|
||||
onForward?(callback: () => void): () => void
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function createElectronRendererAdapter(): NativePlatformAdapter {
|
||||
return {
|
||||
name: 'electron',
|
||||
install(runtime: NativeRouterRuntime) {
|
||||
const removeBack = window.nativeVueHost?.onBack(() => {
|
||||
if (runtime.canGoBack.value) void runtime.pop()
|
||||
})
|
||||
const removeForward = window.nativeVueHost?.onForward?.(() => runtime.router.forward())
|
||||
return () => {
|
||||
removeBack?.()
|
||||
removeForward?.()
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user