重构数据同步功能,新增客户端模式
This commit is contained in:
@@ -32,25 +32,62 @@ export default () => {
|
||||
immediate: true,
|
||||
})
|
||||
|
||||
watch(() => appSetting['sync.mode'], (mode) => {
|
||||
sync.mode = mode
|
||||
})
|
||||
|
||||
watch(() => appSetting['sync.enable'], enable => {
|
||||
void sendSyncAction({
|
||||
action: 'enable',
|
||||
data: {
|
||||
enable,
|
||||
port: appSetting['sync.port'],
|
||||
},
|
||||
})
|
||||
switch (appSetting['sync.mode']) {
|
||||
case 'server':
|
||||
if (appSetting['sync.server.port']) {
|
||||
void sendSyncAction({
|
||||
action: 'enable_server',
|
||||
data: {
|
||||
enable: appSetting['sync.enable'],
|
||||
port: appSetting['sync.server.port'],
|
||||
},
|
||||
})
|
||||
}
|
||||
break
|
||||
case 'client':
|
||||
if (appSetting['sync.client.host']) {
|
||||
void sendSyncAction({
|
||||
action: 'enable_client',
|
||||
data: {
|
||||
enable: appSetting['sync.enable'],
|
||||
host: appSetting['sync.client.host'],
|
||||
},
|
||||
})
|
||||
}
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
sync.enable = enable
|
||||
})
|
||||
watch(() => appSetting['sync.port'], port => {
|
||||
void sendSyncAction({
|
||||
action: 'enable',
|
||||
data: {
|
||||
enable: appSetting['sync.enable'],
|
||||
port: appSetting['sync.port'],
|
||||
},
|
||||
})
|
||||
sync.port = port
|
||||
watch(() => appSetting['sync.server.port'], port => {
|
||||
if (appSetting['sync.mode'] == 'server') {
|
||||
void sendSyncAction({
|
||||
action: 'enable_server',
|
||||
data: {
|
||||
enable: appSetting['sync.enable'],
|
||||
port: appSetting['sync.server.port'],
|
||||
},
|
||||
})
|
||||
}
|
||||
sync.server.port = port
|
||||
})
|
||||
watch(() => appSetting['sync.client.host'], host => {
|
||||
if (appSetting['sync.mode'] == 'client') {
|
||||
void sendSyncAction({
|
||||
action: 'enable_client',
|
||||
data: {
|
||||
enable: appSetting['sync.enable'],
|
||||
host: appSetting['sync.client.host'],
|
||||
},
|
||||
})
|
||||
}
|
||||
sync.client.host = host
|
||||
})
|
||||
|
||||
watch(() => appSetting['network.proxy.enable'], enable => {
|
||||
|
||||
@@ -2,23 +2,33 @@ import { markRaw, onBeforeUnmount } from '@common/utils/vueTools'
|
||||
import { onSyncAction, sendSyncAction } from '@renderer/utils/ipc'
|
||||
import { sync } from '@renderer/store'
|
||||
import { appSetting } from '@renderer/store/setting'
|
||||
import { SYNC_CODE } from '@common/constants'
|
||||
|
||||
export default () => {
|
||||
const handleSyncList = (event: LX.Sync.SyncMainWindowActions) => {
|
||||
console.log(event)
|
||||
switch (event.action) {
|
||||
case 'select_mode':
|
||||
sync.deviceName = event.data.deviceName
|
||||
sync.deviceName = event.data
|
||||
sync.isShowSyncMode = true
|
||||
break
|
||||
case 'close_select_mode':
|
||||
sync.isShowSyncMode = false
|
||||
break
|
||||
case 'status':
|
||||
sync.status.status = event.data.status
|
||||
sync.status.message = event.data.message
|
||||
sync.status.address = markRaw(event.data.address)
|
||||
sync.status.code = event.data.code
|
||||
sync.status.devices = markRaw(event.data.devices)
|
||||
case 'server_status':
|
||||
sync.server.status.status = event.data.status
|
||||
sync.server.status.message = event.data.message
|
||||
sync.server.status.address = markRaw(event.data.address)
|
||||
sync.server.status.code = event.data.code
|
||||
sync.server.status.devices = markRaw(event.data.devices)
|
||||
break
|
||||
case 'client_status':
|
||||
sync.client.status.status = event.data.status
|
||||
sync.client.status.message = event.data.message
|
||||
sync.client.status.address = markRaw(event.data.address)
|
||||
if (event.data.message == SYNC_CODE.missingAuthCode || event.data.message == SYNC_CODE.authFailed) {
|
||||
if (!sync.isShowAuthCodeModal) sync.isShowAuthCodeModal = true
|
||||
} else if (sync.isShowAuthCodeModal) sync.isShowAuthCodeModal = false
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -33,15 +43,36 @@ export default () => {
|
||||
|
||||
return async() => {
|
||||
sync.enable = appSetting['sync.enable']
|
||||
sync.port = appSetting['sync.port']
|
||||
if (appSetting['sync.enable'] && appSetting['sync.port']) {
|
||||
void sendSyncAction({
|
||||
action: 'enable',
|
||||
data: {
|
||||
enable: appSetting['sync.enable'],
|
||||
port: appSetting['sync.port'],
|
||||
},
|
||||
})
|
||||
sync.mode = appSetting['sync.mode']
|
||||
sync.server.port = appSetting['sync.server.port']
|
||||
sync.client.host = appSetting['sync.client.host']
|
||||
if (appSetting['sync.enable']) {
|
||||
switch (appSetting['sync.mode']) {
|
||||
case 'server':
|
||||
if (appSetting['sync.server.port']) {
|
||||
void sendSyncAction({
|
||||
action: 'enable_server',
|
||||
data: {
|
||||
enable: appSetting['sync.enable'],
|
||||
port: appSetting['sync.server.port'],
|
||||
},
|
||||
})
|
||||
}
|
||||
break
|
||||
case 'client':
|
||||
if (appSetting['sync.client.host']) {
|
||||
void sendSyncAction({
|
||||
action: 'enable_client',
|
||||
data: {
|
||||
enable: appSetting['sync.enable'],
|
||||
host: appSetting['sync.client.host'],
|
||||
},
|
||||
})
|
||||
}
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user