From f0e7b1117775fc244fce1b41ab7b3d1d34f744a7 Mon Sep 17 00:00:00 2001 From: phlpsong Date: Sun, 7 Jan 2024 12:57:22 +0800 Subject: [PATCH] fix: service list order issue and UI change --- Easydict/NewApp/View/ServiceItemView.swift | 3 ++- Easydict/NewApp/View/SettingView/Tabs/ServiceTab.swift | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Easydict/NewApp/View/ServiceItemView.swift b/Easydict/NewApp/View/ServiceItemView.swift index e5b0d5eac..9f34a1740 100644 --- a/Easydict/NewApp/View/ServiceItemView.swift +++ b/Easydict/NewApp/View/ServiceItemView.swift @@ -17,7 +17,7 @@ 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()) @@ -25,6 +25,7 @@ struct ServiceItemView: View { toggleValueChanged(value) })) {} .toggleStyle(.switch) + .controlSize(.small) } .padding(4.0) diff --git a/Easydict/NewApp/View/SettingView/Tabs/ServiceTab.swift b/Easydict/NewApp/View/SettingView/Tabs/ServiceTab.swift index 4a5159a60..d96cc86dc 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/ServiceTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/ServiceTab.swift @@ -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() } @@ -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() } @@ -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) }