Skip to content

Commit

Permalink
service tab refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
CanglongCl committed Jan 14, 2024
1 parent 068203e commit 4498f74
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 161 deletions.
4 changes: 0 additions & 4 deletions Easydict.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@
03FD68BB2B1DC59600FD388E /* CryptoSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 03FD68BA2B1DC59600FD388E /* CryptoSwift */; };
03FD68BE2B1E151A00FD388E /* String+EncryptAES.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03FD68BD2B1E151A00FD388E /* String+EncryptAES.swift */; };
0A057D6D2B499A000025C51D /* ServiceTab.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A057D6C2B499A000025C51D /* ServiceTab.swift */; };
0A057D6F2B499A0B0025C51D /* ServiceItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A057D6E2B499A0B0025C51D /* ServiceItemView.swift */; };
0A2BA9602B49A989002872A4 /* Binding+DidSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A2BA95F2B49A989002872A4 /* Binding+DidSet.swift */; };
0A2BA9642B4A3CCD002872A4 /* Notification+Name.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A2BA9632B4A3CCD002872A4 /* Notification+Name.swift */; };
0AC11B222B4D16A500F07198 /* WindowAccessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AC11B212B4D16A500F07198 /* WindowAccessor.swift */; };
Expand Down Expand Up @@ -703,7 +702,6 @@
03FD68BD2B1E151A00FD388E /* String+EncryptAES.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+EncryptAES.swift"; sourceTree = "<group>"; };
06E15747A7BD34D510ADC6A8 /* Pods-Easydict.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Easydict.debug.xcconfig"; path = "Target Support Files/Pods-Easydict/Pods-Easydict.debug.xcconfig"; sourceTree = "<group>"; };
0A057D6C2B499A000025C51D /* ServiceTab.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServiceTab.swift; sourceTree = "<group>"; };
0A057D6E2B499A0B0025C51D /* ServiceItemView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServiceItemView.swift; sourceTree = "<group>"; };
0A2BA95F2B49A989002872A4 /* Binding+DidSet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Binding+DidSet.swift"; sourceTree = "<group>"; };
0A2BA9632B4A3CCD002872A4 /* Notification+Name.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Notification+Name.swift"; sourceTree = "<group>"; };
0AC11B212B4D16A500F07198 /* WindowAccessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowAccessor.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2052,7 +2050,6 @@
isa = PBXGroup;
children = (
27FE980A2B3DD5D1000AD654 /* MenuItemView.swift */,
0A057D6E2B499A0B0025C51D /* ServiceItemView.swift */,
0AC11B212B4D16A500F07198 /* WindowAccessor.swift */,
0AC11B232B4E46B300F07198 /* TapHandlerView.swift */,
27FE98072B3DD52B000AD654 /* SettingView */,
Expand Down Expand Up @@ -2605,7 +2602,6 @@
03991166292A8A4400E1B06D /* EZTitleBarMoveView.m in Sources */,
03542A582937CC3200C34C33 /* EZConfiguration.m in Sources */,
27FE98092B3DD536000AD654 /* SettingView.swift in Sources */,
0A057D6F2B499A0B0025C51D /* ServiceItemView.swift in Sources */,
035E37E72A0953120061DFAF /* EZToast.m in Sources */,
03542A492937B5CF00C34C33 /* EZGoogleTranslate.m in Sources */,
03D0435A2928C4C800E7559E /* EZWindowManager.m in Sources */,
Expand Down
3 changes: 3 additions & 0 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -2742,6 +2742,9 @@
}
}
}
},
"setting.service.detail.no_selection" : {

},
"setting.tts_service.options.apple" : {
"localizations" : {
Expand Down
41 changes: 0 additions & 41 deletions Easydict/NewApp/View/ServiceItemView.swift

This file was deleted.

33 changes: 20 additions & 13 deletions Easydict/NewApp/View/SettingView/SettingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,48 @@ enum SettingTab: Int {

@available(macOS 13, *)
struct SettingView: View {
@State private var selection = SettingTab.general.rawValue
@State private var selection = SettingTab.general
@State private var window: NSWindow?

var body: some View {
TabView(selection: $selection.didSet(execute: { _ in
resizeWindowFrame()
})) {
TabView(selection: $selection) {
GeneralTab()
.tabItem { Label("setting_general", systemImage: "gear") }
.tag(SettingTab.general.rawValue)
.tag(SettingTab.general)

ServiceTab()
.tabItem { Label("service", systemImage: "briefcase") }
.tag(SettingTab.service.rawValue)
.tag(SettingTab.service)

PrivacyTab()
.tabItem { Label("privacy", systemImage: "hand.raised.square") }
.tag(SettingTab.privacy.rawValue)
.tag(SettingTab.privacy)

AboutTab()
.tabItem { Label("about", systemImage: "info.bubble") }
.tag(SettingTab.about.rawValue)
.tag(SettingTab.about)
}
.background(WindowAccessor(window: $window.didSet(execute: { _ in
// reset frame when first launch
.background(
WindowAccessor(window: $window.didSet(execute: { _ in
// reset frame when first launch
resizeWindowFrame()
}))
)
.onChange(of: selection) { _ in
resizeWindowFrame()
})))
}
}

func resizeWindowFrame() {
guard let window else { return }

let originalFrame = window.frame
let newSize = selection == SettingTab.service.rawValue
? CGSize(width: 360, height: 520) : CGSize(width: 500, height: 400)
let newSize = switch selection {
case .general, .privacy, .about:
CGSize(width: 500, height: 520)
case .service:
CGSize(width: 800, height: 520)
}

let newY = originalFrame.origin.y + originalFrame.size.height - newSize.height
let newRect = NSRect(origin: CGPoint(x: originalFrame.origin.x, y: newY), size: newSize)
Expand Down
Loading

0 comments on commit 4498f74

Please sign in to comment.