first commit
This commit is contained in:
10
packages/electron/package.json
Normal file
10
packages/electron/package.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "@native-vue-router/electron",
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"files": ["dist"],
|
||||
"scripts": { "build": "vite build --config vite.config.ts && vue-tsc -p tsconfig.json --emitDeclarationOnly" },
|
||||
"exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" } },
|
||||
"peerDependencies": { "@native-vue-router/core": "^0.1.0" }
|
||||
}
|
||||
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?.()
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
15
packages/electron/tsconfig.json
Normal file
15
packages/electron/tsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"extends": "../../tsconfig.app.json",
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"emitDeclarationOnly": true,
|
||||
"noEmit": false,
|
||||
"rootDir": "src",
|
||||
"outDir": "dist",
|
||||
"tsBuildInfoFile": "../../node_modules/.tmp/electron.tsbuildinfo",
|
||||
"baseUrl": ".",
|
||||
"paths": { "@native-vue-router/core": ["../core/dist/index.d.ts"] }
|
||||
},
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
10
packages/electron/vite.config.ts
Normal file
10
packages/electron/vite.config.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import { resolve } from 'node:path'
|
||||
|
||||
export default defineConfig({
|
||||
build: {
|
||||
outDir: 'dist', emptyOutDir: true,
|
||||
lib: { entry: resolve(__dirname, 'src/index.ts'), formats: ['es'], fileName: 'index' },
|
||||
rollupOptions: { external: ['@native-vue-router/core'] },
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user