fix: save history
This commit is contained in:
@@ -12,3 +12,4 @@ TODO
|
|||||||
- [x] 保存历史
|
- [x] 保存历史
|
||||||
- [x] 自动接收
|
- [x] 自动接收
|
||||||
- [ ] 传输加密
|
- [ ] 传输加密
|
||||||
|
- [ ] 单例模式
|
||||||
@@ -263,35 +263,49 @@ const canAccept = computed(() => {
|
|||||||
color="success"
|
color="success"
|
||||||
icon="mdi-content-save"
|
icon="mdi-content-save"
|
||||||
@click="acceptTransfer"
|
@click="acceptTransfer"
|
||||||
></v-btn>
|
>
|
||||||
|
<v-tooltip activator="parent" location="top">Accept</v-tooltip>
|
||||||
|
</v-btn>
|
||||||
|
|
||||||
<v-btn
|
<v-btn
|
||||||
v-if="canAccept"
|
v-if="canAccept"
|
||||||
color="success"
|
color="success"
|
||||||
icon="mdi-folder-arrow-right"
|
icon="mdi-folder-arrow-right"
|
||||||
@click="acceptToFolder"
|
@click="acceptToFolder"
|
||||||
></v-btn>
|
>
|
||||||
|
<v-tooltip activator="parent" location="top">
|
||||||
|
Save to Folder
|
||||||
|
</v-tooltip>
|
||||||
|
</v-btn>
|
||||||
|
|
||||||
<v-btn
|
<v-btn
|
||||||
v-if="canAccept"
|
v-if="canAccept"
|
||||||
color="error"
|
color="error"
|
||||||
icon="mdi-close"
|
icon="mdi-close"
|
||||||
@click="rejectTransfer"
|
@click="rejectTransfer"
|
||||||
></v-btn>
|
>
|
||||||
|
<v-tooltip activator="parent" location="top">Reject</v-tooltip>
|
||||||
|
</v-btn>
|
||||||
|
|
||||||
<v-btn
|
<v-btn
|
||||||
v-if="canCopy"
|
v-if="canCopy"
|
||||||
color="success"
|
color="success"
|
||||||
icon="mdi-eye"
|
icon="mdi-eye"
|
||||||
@click="showContentDialog = true"
|
@click="showContentDialog = true"
|
||||||
></v-btn>
|
>
|
||||||
|
<v-tooltip activator="parent" location="top">
|
||||||
|
View Content
|
||||||
|
</v-tooltip>
|
||||||
|
</v-btn>
|
||||||
|
|
||||||
<v-btn
|
<v-btn
|
||||||
v-if="canCopy"
|
v-if="canCopy"
|
||||||
color="success"
|
color="success"
|
||||||
icon="mdi-content-copy"
|
icon="mdi-content-copy"
|
||||||
@click="handleCopy"
|
@click="handleCopy"
|
||||||
></v-btn>
|
>
|
||||||
|
<v-tooltip activator="parent" location="top">Copy</v-tooltip>
|
||||||
|
</v-btn>
|
||||||
|
|
||||||
<v-btn
|
<v-btn
|
||||||
v-if="
|
v-if="
|
||||||
@@ -303,14 +317,18 @@ const canAccept = computed(() => {
|
|||||||
color="info"
|
color="info"
|
||||||
icon="mdi-delete"
|
icon="mdi-delete"
|
||||||
@click="handleDelete"
|
@click="handleDelete"
|
||||||
></v-btn>
|
>
|
||||||
|
<v-tooltip activator="parent" location="top">Delete</v-tooltip>
|
||||||
|
</v-btn>
|
||||||
|
|
||||||
<v-btn
|
<v-btn
|
||||||
v-if="canCancel"
|
v-if="canCancel"
|
||||||
color="error"
|
color="error"
|
||||||
icon="mdi-stop"
|
icon="mdi-stop"
|
||||||
@click="CancelTransfer(props.transfer.id)"
|
@click="CancelTransfer(props.transfer.id)"
|
||||||
></v-btn>
|
>
|
||||||
|
<v-tooltip activator="parent" location="top">Cancel</v-tooltip>
|
||||||
|
</v-btn>
|
||||||
</v-btn-group>
|
</v-btn-group>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ func Load() *Config {
|
|||||||
}
|
}
|
||||||
v.SetDefault("host_name", defaultHostName)
|
v.SetDefault("host_name", defaultHostName)
|
||||||
v.SetDefault("id", uuid.New().String())
|
v.SetDefault("id", uuid.New().String())
|
||||||
|
v.SetDefault("save_history", true)
|
||||||
|
|
||||||
v.SetConfigFile(configFile)
|
v.SetConfigFile(configFile)
|
||||||
v.SetConfigType("json")
|
v.SetConfigType("json")
|
||||||
@@ -182,3 +183,16 @@ func (c *Config) GetSaveHistory() bool {
|
|||||||
func (c *Config) GetVersion() string {
|
func (c *Config) GetVersion() string {
|
||||||
return Version
|
return Version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Config) SetWindowState(state WindowState) {
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
|
c.WindowState = state
|
||||||
|
c.v.Set("window_state", state)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) GetWindowState() WindowState {
|
||||||
|
c.mu.RLock()
|
||||||
|
defer c.mu.RUnlock()
|
||||||
|
return c.WindowState
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ func (s *Service) SaveHistory() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
file, err := os.OpenFile(historyPath, os.O_CREATE|os.O_RDWR, os.FileMode(0644))
|
file, err := os.OpenFile(historyPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ func (s *Service) Start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) GetTransferList() []*Transfer {
|
func (s *Service) GetTransferList() []*Transfer {
|
||||||
var requests []*Transfer
|
var requests []*Transfer = make([]*Transfer, 0)
|
||||||
s.transferList.Range(func(key, value any) bool {
|
s.transferList.Range(func(key, value any) bool {
|
||||||
requests = append(requests, value.(*Transfer))
|
requests = append(requests, value.(*Transfer))
|
||||||
return true
|
return true
|
||||||
|
|||||||
13
main.go
13
main.go
@@ -81,20 +81,25 @@ func main() {
|
|||||||
|
|
||||||
// 窗口关闭事件
|
// 窗口关闭事件
|
||||||
window.OnWindowEvent(events.Common.WindowClosing, func(event *application.WindowEvent) {
|
window.OnWindowEvent(events.Common.WindowClosing, func(event *application.WindowEvent) {
|
||||||
// 保存配置
|
|
||||||
x, y := window.Position()
|
x, y := window.Position()
|
||||||
width, height := window.Size()
|
width, height := window.Size()
|
||||||
conf.WindowState = config.WindowState{
|
conf.SetWindowState(config.WindowState{
|
||||||
X: x,
|
X: x,
|
||||||
Y: y,
|
Y: y,
|
||||||
Width: width,
|
Width: width,
|
||||||
Height: height,
|
Height: height,
|
||||||
}
|
})
|
||||||
_ = conf.Save()
|
|
||||||
// 保存传输历史
|
// 保存传输历史
|
||||||
if conf.GetSaveHistory() {
|
if conf.GetSaveHistory() {
|
||||||
transferService.SaveHistory()
|
transferService.SaveHistory()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 保存配置
|
||||||
|
err := conf.Save()
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("Failed to save config", "error", err)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
application.RegisterEvent[FilesDroppedEvent]("files-dropped")
|
application.RegisterEvent[FilesDroppedEvent]("files-dropped")
|
||||||
|
|||||||
Reference in New Issue
Block a user