Skip to content

Commit

Permalink
fix: 修正插件启动白屏问题
Browse files Browse the repository at this point in the history
- 不支持非hashmode的路由
  • Loading branch information
ZiuChen committed Apr 9, 2023
1 parent 21e7d76 commit 6efbef2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/common/registerCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { $emit } from '@/hooks/useEventBus'
import { ENTER_FILE, ENTER_CREATE, ENTER_IMPORT, ENTER_CONTENT } from '@/common/symbol'
import { isElectron } from '@/utils'
import { useMainStore } from '@/store'
import { useRouter } from 'vue-router'
import type { IPayloadFile } from '@/types'

export function registerCallback() {
Expand Down Expand Up @@ -48,7 +47,8 @@ function emitWithWatch(event: symbol, payload?: any) {
$emit(event, payload)
} else {
// 如果当前在其他页面 则跳转回editor
if (window.location.pathname !== 'editor') window.history.back()
if (window.location.pathname !== '/' && window.location.pathname !== 'editor')
window.history.back()

// 等待编辑器初始化完毕后emit
// 执行完毕后立刻cancel掉监听
Expand Down
21 changes: 10 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ import { createPinia } from 'pinia'
import { registerIcon } from '@/common/registerIcon'
import { registerCallback } from '@/common/registerCallback'
import { isElectron, SERVER_DEV } from './utils'
;(function () {
try {
if (!SERVER_DEV && !isElectron) throw new Error('unsupported platform') // 禁用非 electron 环境的运行
if (!SERVER_DEV && utools.isDev()) return // 禁用非热更新服务器的开发模式的运行 防止逆向

const pinia = createPinia()
createApp(App).use(router).use(pinia).use(registerIcon).mount('#app')
try {
if (!SERVER_DEV && !isElectron) throw new Error('unsupported platform') // 禁用非 electron 环境的运行
if (!SERVER_DEV && utools.isDev()) throw Error('unsupported enviroment') // 禁用非热更新服务器的开发模式的运行 防止逆向

registerCallback()
} catch (error) {
if (isElectron) utools.showNotification('初始化失败: ' + error)
}
})()
const pinia = createPinia()
createApp(App).use(router).use(pinia).use(registerIcon).mount('#app')

registerCallback()
} catch (error) {
if (isElectron) utools.showNotification('初始化失败: ' + error)
}
4 changes: 2 additions & 2 deletions src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createRouter, createWebHistory } from 'vue-router'
import { createRouter, createWebHashHistory } from 'vue-router'

export default createRouter({
history: createWebHistory(),
history: createWebHashHistory(),
routes: [
{
path: '/',
Expand Down

0 comments on commit 6efbef2

Please sign in to comment.