This commit is contained in:
lyswhut
2023-01-06 14:39:44 +08:00
parent 1db54195f5
commit 27c1bf8eb6
30 changed files with 196 additions and 85 deletions
+9 -3
View File
@@ -116,8 +116,14 @@ export const registerDeeplink = (startApp: () => void) => {
export const listenerAppEvent = (startApp: () => void) => {
app.on('web-contents-created', (event, contents) => {
contents.on('will-navigate', (event, navigationUrl) => {
if (global.isDev) return console.log('navigation to url:', navigationUrl)
if (!navigationUrlWhiteList.some(url => url.test(navigationUrl))) return event.preventDefault()
if (global.isDev) {
console.log('navigation to url:', navigationUrl)
return
}
if (!navigationUrlWhiteList.some(url => url.test(navigationUrl))) {
event.preventDefault()
return
}
console.log('navigation to url:', navigationUrl)
})
contents.setWindowOpenHandler(({ url }) => {
@@ -233,7 +239,7 @@ export const initAppSetting = async() => {
if (!isInitialized) {
const dbFileExists = await global.lx.worker.dbService.init(global.lxDataPath)
global.lx.appSetting = (await initSetting()).setting
if (!dbFileExists) await migrateDBData().catch(err => log.error(err))
if (!dbFileExists) await migrateDBData().catch(err => { log.error(err) })
initTheme()
}
// global.lx.theme = getTheme()
+6 -2
View File
@@ -17,8 +17,12 @@ electronDebug({
// Install `vue-devtools`
app.on('ready', () => {
installExtension(VUEJS_DEVTOOLS)
.then((name: string) => console.log(`Added Extension: ${name}`))
.catch((err: Error) => console.log('An error occurred: ', err))
.then((name: string) => {
console.log(`Added Extension: ${name}`)
})
.catch((err: Error) => {
console.log('An error occurred: ', err)
})
})
// Require `main` process to boot app
+3 -1
View File
@@ -30,4 +30,6 @@ listenerAppEvent(init)
// https://github.com/electron/electron/issues/16809
void app.whenReady().then(() => isLinux ? setTimeout(init, 300) : init())
void app.whenReady().then(() => {
isLinux ? setTimeout(init, 300) : init()
})
+1 -1
View File
@@ -146,7 +146,7 @@ const broadcast = async(action: listAction, data: any, excludeIds: string[] = []
export const sendListAction = async(action: LX.Sync.ActionList) => {
console.log('sendListAction', action.action)
// io.sockets
return await broadcast('list:action', JSON.stringify(action))
await broadcast('list:action', JSON.stringify(action))
}
export const registerListHandler = (_io: Server, socket: LX.Sync.Socket) => {
+6 -3
View File
@@ -142,7 +142,10 @@ const handleStartServer = async(port = 9527) => await new Promise((resolve, reje
httpServer.on('listening', () => {
const addr = httpServer.address()
if (!addr) return reject(new Error('address is null'))
if (!addr) {
reject(new Error('address is null'))
return
}
const bind = typeof addr == 'string' ? `pipe ${addr}` : `port ${addr.port}`
console.info(`Listening on ${bind}`)
resolve(null)
@@ -171,7 +174,7 @@ export const stopServer = async() => {
return
}
console.log('stoping sync server...')
return await handleStopServer().then(() => {
await handleStopServer().then(() => {
console.log('sync server stoped')
status.status = false
status.message = ''
@@ -189,7 +192,7 @@ export const startServer = async(port: number) => {
if (status.status) await handleStopServer()
console.log('starting sync server...')
return await handleStartServer(port).then(() => {
await handleStartServer(port).then(() => {
console.log('sync server started')
status.status = true
status.message = ''
+8 -5
View File
@@ -31,7 +31,10 @@ const getRemoteListData = async(socket: LX.Sync.Socket): Promise<LX.Sync.ListDat
socket.removeListener('list:sync', handleSuccess)
console.log('getRemoteListData', 'handleSuccess')
const data: LX.Sync.Data | null = JSON.parse(decryptMsg(socket.data.keyInfo, enData))
if (!data) return reject(new Error('Get remote list data failed'))
if (!data) {
reject(new Error('Get remote list data failed'))
return
}
if (data.action != 'getData') return
resolve(patchListData(data.data))
}
@@ -101,10 +104,10 @@ const updateSnapshot = async(path: string, data: string) => {
let writeFilePromise = writeFilePromises.get(path) ?? Promise.resolve()
writeFilePromise = writeFilePromise.then(async() => {
if (writeFilePromise !== writeFilePromises.get(path)) return
return await fsPromises.writeFile(path, data)
await fsPromises.writeFile(path, data)
})
writeFilePromises.set(path, writeFilePromise)
return await writeFilePromise.finally(() => {
await writeFilePromise.finally(() => {
if (writeFilePromise !== writeFilePromises.get(path)) return
writeFilePromises.delete(path)
})
@@ -453,7 +456,7 @@ const checkSyncQueue = async(): Promise<void> => {
if (!syncingId) return
console.log('sync queue...')
await wait()
return await checkSyncQueue()
await checkSyncQueue()
}
// export {
@@ -484,7 +487,7 @@ const _syncList = async(_io: Server, socket: LX.Sync.Socket) => {
const removeSnapshot = async(keyInfo: LX.Sync.KeyInfo) => {
const filePath = getSnapshotFilePath(keyInfo)
return await fsPromises.unlink(filePath)
await fsPromises.unlink(filePath)
}
export {
+4 -1
View File
@@ -72,7 +72,10 @@ export const createWindow = async(userApi: LX.UserApi.UserApiInfo) => {
})
}
browserWindow.webContents.session.setPermissionRequestHandler((webContents, permission, resolve) => {
if (webContents === browserWindow?.webContents) return resolve(false)
if (webContents === browserWindow?.webContents) {
resolve(false)
return
}
resolve(true)
})
browserWindow.webContents.setWindowOpenHandler(() => {
@@ -118,7 +118,9 @@ export const cancelRequest = (requestKey: string) => {
}
export const request = async({ requestKey, data }: LX.UserApi.UserApiRequestParams): Promise<any> => await new Promise((resolve, reject) => {
if (!userApi) return reject(new Error('user api is not load'))
if (!userApi) {
reject(new Error('user api is not load'))
}
// const requestKey = `request__${Math.random().toString().substring(2)}`
const timeout = timeouts.get(requestKey)
+4 -1
View File
@@ -202,7 +202,10 @@ export const alwaysOnTopTools: AlwaysOnTopTools = {
startLoop() {
this.clearLoop()
this.timeout = setInterval(() => {
if (!isExistWindow()) return this.clearLoop()
if (!isExistWindow()) {
this.clearLoop()
return
}
setAlwaysOnTop(true, 'screen-saver')
}, 1000)
},
+2 -2
View File
@@ -242,13 +242,13 @@ export const setThumbarButtons = ({ empty, collect, play, next, prev }: LX.TaskB
export const setThumbnailClip = (region: Electron.Rectangle) => {
if (!browserWindow) return
return browserWindow.setThumbnailClip(region)
browserWindow.setThumbnailClip(region)
}
export const clearCache = async() => {
if (!browserWindow) throw new Error('main window is undefined')
return await browserWindow.webContents.session.clearCache()
await browserWindow.webContents.session.clearCache()
}
export const getCacheSize = async() => {
@@ -55,7 +55,10 @@ export default () => {
showWindow()
})
mainOn<boolean>(WIN_MAIN_RENDERER_EVENT_NAME.close, ({ params: isForce }) => {
if (isForce) return app.exit(0)
if (isForce) {
app.exit(0)
return
}
global.lx.isTrafficLightClose = true
closeWindow()
})
@@ -79,7 +82,7 @@ export default () => {
mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.clear_cache, async() => {
return await clearCache()
await clearCache()
})
mainHandle<number>(WIN_MAIN_RENDERER_EVENT_NAME.get_cache_size, async() => {
@@ -13,7 +13,7 @@ export default () => {
await global.lx.worker.dbService.downloadInfoUpdate(list)
})
mainHandle<string[]>(WIN_MAIN_RENDERER_EVENT_NAME.download_list_remove, async({ params: ids }) => {
return await global.lx.worker.dbService.downloadInfoRemove(ids)
await global.lx.worker.dbService.downloadInfoRemove(ids)
})
mainHandle(WIN_MAIN_RENDERER_EVENT_NAME.download_list_clear, async() => {
await global.lx.worker.dbService.downloadInfoClear()
@@ -6,7 +6,10 @@ import { WIN_MAIN_RENDERER_EVENT_NAME } from '@common/ipcNames'
const handleInflate = async(data: Buffer) => {
return await new Promise((resolve: (result: Buffer) => void, reject) => {
inflate(data, (err, result) => {
if (err) return reject(err)
if (err) {
reject(err)
return
}
resolve(result)
})
})
@@ -9,7 +9,8 @@ export default () => {
mainHandle<LX.Sync.SyncServiceActions, any>(WIN_MAIN_RENDERER_EVENT_NAME.sync_action, async({ params: data }) => {
switch (data.action) {
case 'enable':
return data.data.enable ? await startServer(parseInt(data.data.port)) : await stopServer()
data.data.enable ? await startServer(parseInt(data.data.port)) : await stopServer()
return
case 'get_status':
return getStatus()
case 'generate_code':
@@ -22,7 +22,7 @@ export default () => {
})
mainHandle<LX.UserApi.UserApiSetApiParams>(WIN_MAIN_RENDERER_EVENT_NAME.set_user_api, async({ params: apiId }) => {
return await setApi(apiId)
await setApi(apiId)
})
mainHandle<LX.UserApi.UserApiInfo[]>(WIN_MAIN_RENDERER_EVENT_NAME.get_user_api_list, async() => {
@@ -34,14 +34,14 @@ export default () => {
})
mainHandle<LX.UserApi.UserApiSetAllowUpdateAlertParams>(WIN_MAIN_RENDERER_EVENT_NAME.user_api_set_allow_update_alert, async({ params: { id, enable } }) => {
return setAllowShowUpdateAlert(id, enable)
setAllowShowUpdateAlert(id, enable)
})
mainHandle<LX.UserApi.UserApiRequestParams>(WIN_MAIN_RENDERER_EVENT_NAME.request_user_api, async({ params }) => {
return await request(params)
})
mainHandle<LX.UserApi.UserApiRequestCancelParams>(WIN_MAIN_RENDERER_EVENT_NAME.request_user_api_cancel, async({ params: requestKey }) => {
return cancelRequest(requestKey)
cancelRequest(requestKey)
})
}
+6 -2
View File
@@ -82,7 +82,9 @@ const migrateFile = async(name: string, targetName: string) => {
if (!await checkPath(path) && await checkPath(oldPath)) {
await fs.promises.copyFile(oldPath, path).catch(err => {
log.error(err)
}).catch(err => log.error(err))
}).catch(err => {
log.error(err)
})
}
}
@@ -108,7 +110,9 @@ export const migrateDataJson = async() => {
if (oldDataFile.listPosition) newData.listScrollPosition = oldDataFile.listPosition
if (oldDataFile.listUpdateInfo) newData.listUpdateInfo = oldDataFile.listUpdateInfo
await fs.promises.writeFile(path, JSON.stringify(newData)).catch(err => log.error(err))
await fs.promises.writeFile(path, JSON.stringify(newData)).catch(err => {
log.error(err)
})
}
+1 -3
View File
@@ -4,9 +4,7 @@ import { join } from 'path'
import fs from 'fs'
import log from 'electron-log'
interface Stores {
[key: string]: Store
}
type Stores = Record<string, Store>
const stores: Stores = {}
@@ -91,7 +91,7 @@ export const insertMusicInfoList = (list: LX.DBService.MusicInfo[]) => {
const musicInfoInsertStatement = createMusicInfoInsertStatement()
const musicInfoOrderInsertStatement = createMusicInfoOrderInsertStatement()
const db = getDB()
return db.transaction((musics: LX.DBService.MusicInfo[]) => {
db.transaction((musics: LX.DBService.MusicInfo[]) => {
for (const music of musics) {
musicInfoInsertStatement.run(music)
musicInfoOrderInsertStatement.run({
@@ -238,7 +238,7 @@ export const removeMusicInfos = (listId: string, ids: string[]) => {
const musicInfoDeleteStatement = createMusicInfoDeleteStatement()
const musicInfoOrderDeleteStatement = createMusicInfoOrderDeleteStatement()
const db = getDB()
return db.transaction((listId: string, ids: string[]) => {
db.transaction((listId: string, ids: string[]) => {
for (const id of ids) {
musicInfoDeleteStatement.run({ listId, id })
musicInfoOrderDeleteStatement.run({ listId, id })