Skip to content

Commit

Permalink
fix: service list order issue and UI change
Browse files Browse the repository at this point in the history
  • Loading branch information
phlpsong committed Jan 7, 2024
1 parent 7ae9c0a commit f0e7b11
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Easydict/NewApp/View/ServiceItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ struct ServiceItemView: View {
HStack {
Image(nsImage: NSImage(named: service.serviceType().rawValue) ?? NSImage())
.resizable()
.frame(maxWidth: 24.0, maxHeight: 24.0)
.frame(maxWidth: 18.0, maxHeight: 18.0)

Text(service.name())

Toggle(isOn: $service.enabled.didSet(execute: { value in
toggleValueChanged(value)
})) {}
.toggleStyle(.switch)
.controlSize(.small)
}

.padding(4.0)
Expand Down
9 changes: 6 additions & 3 deletions Easydict/NewApp/View/SettingView/Tabs/ServiceTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ struct ServiceTab: View {
}
let windowType = EZWindowType(rawValue: windowTypeValue) ?? .none
EZLocalStorage.shared().setService(services[index], windowType: windowType)
// refresh service list
loadService(type: windowTypeValue)
postUpdateServiceNotification()
}

Expand All @@ -90,15 +92,17 @@ struct ServiceTab: View {
}

func onServiceItemMove(fromOffsets: IndexSet, toOffset: Int) {
let oldEnabledServices = enabledServices(in: services)

services.move(fromOffsets: fromOffsets, toOffset: toOffset)
serviceTypes.move(fromOffsets: fromOffsets, toOffset: toOffset)

let oldEnabledServices = enabledServices(in: services)
let windowType = EZWindowType(rawValue: windowTypeValue) ?? .none
EZLocalStorage.shared().setAllServiceTypes(serviceTypes, windowType: windowType)
let newServices = EZLocalStorage.shared().allServices(windowType)
let newEnabledServices = enabledServices(in: newServices)

// post notification after enabled services order changed
if isEnabledServicesOrderChanged(source: oldEnabledServices, dest: newEnabledServices) {
postUpdateServiceNotification()
}
Expand All @@ -114,8 +118,7 @@ struct ServiceTab: View {
}

func postUpdateServiceNotification() {
let windowType = EZWindowType(rawValue: windowTypeValue) ?? .none
let userInfo: [String: Any] = [EZWindowTypeKey: windowType]
let userInfo: [String: Any] = [EZWindowTypeKey: windowTypeValue]
let notification = Notification(name: .serviceHasUpdated, object: nil, userInfo: userInfo)
NotificationCenter.default.post(notification)
}
Expand Down

0 comments on commit f0e7b11

Please sign in to comment.