Skip to content

Commit

Permalink
fix(desktop): support rebuild database when load connection error
Browse files Browse the repository at this point in the history
  • Loading branch information
ysfscream authored and Red-Asuka committed Jul 5, 2024
1 parent 83eca29 commit 192e541
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { app, protocol, BrowserWindow, ipcMain, shell, Menu } from 'electron'
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer'
import { quitAndRenameLogger } from './utils/logger'
import rebuildDatabase from './utils/rebuildDatabase'
import rebuildDatabase from './database/rebuildDatabase'
import { createUpdateWindow, autoDownload } from './main/updateDownloader'
import { getCurrentLang } from './main/updateChecker'
import getMenuTemplate from './main/getMenuTemplate'
Expand Down
2 changes: 1 addition & 1 deletion src/components/DatabaseError.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class DatabaseError extends Vue {
}
private mounted() {
this.$log.error(`Database connect error - ${this.connectDatabaseFailMessage}`)
this.$log.error(`Database error - ${this.connectDatabaseFailMessage}`)
}
}
</script>
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions src/store/modules/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const SET_INSERT_BUTTON_ADDED = 'SET_INSERT_BUTTON_ADDED'
const TOGGLE_ENABLE_COPILOT = 'TOGGLE_ENABLE_COPILOT'
const SET_LOG_LEVEL = 'SET_LOG_LEVEL'
const TOGGLE_SHOW_CONNECTION_LIST = 'TOGGLE_SHOW_CONNECTION_LIST'
const SET_DATABASE_FAIL_MESSAGE = 'SET_DATABASE_FAIL_MESSAGE'

const getShowConnectionList = (): boolean => {
const _showConnectionList: string | null = localStorage.getItem('showConnectionList')
Expand Down Expand Up @@ -165,6 +166,9 @@ const app = {
state.showConnectionList = showConnectionList
localStorage.setItem('showConnectionList', JSON.stringify(state.showConnectionList))
},
[SET_DATABASE_FAIL_MESSAGE](state: App, connectDatabaseFailMessage: string) {
state.connectDatabaseFailMessage = connectDatabaseFailMessage
},
},
actions: {
async TOGGLE_THEME({ commit }: any, payload: App) {
Expand Down Expand Up @@ -281,6 +285,9 @@ const app = {
TOGGLE_SHOW_CONNECTION_LIST({ commit }: any, payload: App) {
commit(TOGGLE_SHOW_CONNECTION_LIST, payload.showConnectionList)
},
SET_DATABASE_FAIL_MESSAGE({ commit }: any, payload: App) {
commit(SET_DATABASE_FAIL_MESSAGE, payload.connectDatabaseFailMessage)
},
},
}

Expand Down
20 changes: 16 additions & 4 deletions src/views/connections/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ export default class Connections extends Vue {
@Getter('showConnectionList') private showConnectionList!: boolean
@Action('SET_CURRENT_CONNECTION_ID') private setCurrentConnectionId!: (id: string) => void
@Action('SET_DATABASE_FAIL_MESSAGE') private setDatabaseFailMessage!: ({
connectDatabaseFailMessage,
}: {
connectDatabaseFailMessage: string
}) => void
private isEmpty: boolean = false
private isLoadingData: boolean = false
Expand Down Expand Up @@ -110,7 +115,11 @@ export default class Connections extends Vue {
}
}
private async loadData(loadLatest: boolean = false, firstLoad: boolean = false, callback?: () => {}): Promise<void> {
private async loadData(
shouldLoadLatest: boolean = false,
firstLoad: boolean = false,
callback?: () => {},
): Promise<void> {
try {
if (firstLoad) {
this.isLoadingData = true
Expand All @@ -119,7 +128,7 @@ export default class Connections extends Vue {
const connections: ConnectionModel[] | [] = (await connectionService.getAll()) ?? []
this.refreshConnectionList()
this.isLoadingData = false
if (connections.length && loadLatest) {
if (connections.length && shouldLoadLatest) {
const latestId = await connectionService.getLeatestId()
this.$router.push({ path: `/recent_connections/${latestId}` })
}
Expand All @@ -133,8 +142,11 @@ export default class Connections extends Vue {
this.isEmpty = true
}
} catch (error) {
this.$message.error(`Failed to load data: ${error}`)
this.$log.error(`Failed to load data: ${JSON.stringify(error)}`)
const err = error as any
this.$log.error(`Failed to load data: ${JSON.stringify(err, null, 2)}`)
if (err.code === 'SQLITE_ERROR') {
this.setDatabaseFailMessage({ connectDatabaseFailMessage: `Failed to load data: ${error}` })
}
} finally {
callback && callback()
}
Expand Down

0 comments on commit 192e541

Please sign in to comment.