Skip to content

Commit

Permalink
Merge branch 'dev' into fix/tips_view_blank
Browse files Browse the repository at this point in the history
  • Loading branch information
tisfeng committed May 4, 2024
2 parents 17270b7 + 5800e14 commit 73de70a
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 45 deletions.
16 changes: 8 additions & 8 deletions Easydict.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3346,7 +3346,7 @@
CODE_SIGN_IDENTITY = $CODE_SIGN_IDENTITY;
CODE_SIGN_STYLE = $CODE_SIGN_STYLE;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 34;
CURRENT_PROJECT_VERSION = 35;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -3357,7 +3357,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 2.7.0;
MARKETING_VERSION = 2.7.1;
PRODUCT_BUNDLE_IDENTIFIER = "com.izual.EasydictHelper-debug";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand All @@ -3372,7 +3372,7 @@
CODE_SIGN_IDENTITY = $CODE_SIGN_IDENTITY;
CODE_SIGN_STYLE = $CODE_SIGN_STYLE;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 34;
CURRENT_PROJECT_VERSION = 35;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -3383,7 +3383,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 2.7.0;
MARKETING_VERSION = 2.7.1;
PRODUCT_BUNDLE_IDENTIFIER = com.izual.EasydictHelper;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -3529,7 +3529,7 @@
CODE_SIGN_STYLE = $CODE_SIGN_STYLE;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 34;
CURRENT_PROJECT_VERSION = 35;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -3544,7 +3544,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 2.7.0;
MARKETING_VERSION = 2.7.1;
PRODUCT_BUNDLE_IDENTIFIER = "com.izual.Easydict-debug";
PRODUCT_MODULE_NAME = Easydict;
PRODUCT_NAME = "Easydict-debug";
Expand All @@ -3569,7 +3569,7 @@
CODE_SIGN_STYLE = $CODE_SIGN_STYLE;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 34;
CURRENT_PROJECT_VERSION = 35;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = "$(DEVELOPMENT_TEAM)";
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -3584,7 +3584,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 2.7.0;
MARKETING_VERSION = 2.7.1;
PRODUCT_BUNDLE_IDENTIFIER = com.izual.Easydict;
PRODUCT_MODULE_NAME = Easydict;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
1 change: 0 additions & 1 deletion Easydict/App/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ - (void)restartApplication {
[task launch];
}


#pragma mark - NSApplicationDelegate

- (void)applicationWillTerminate:(NSNotification *)aNotification {
Expand Down
30 changes: 30 additions & 0 deletions Easydict/App/EasydictApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ struct EasydictApp: App {
.menuBarExtraStyle(.menu)
.commands {
EasyDictMainMenu() // main menu
// Override About button
CommandGroup(replacing: .appInfo) {
Button {
showAboutWindow()
} label: {
Text("menubar.about")
}
}
}

Window("go_to_settings", id: "go_to_settings") {
Expand Down Expand Up @@ -83,6 +91,28 @@ struct EasydictApp: App {

@Default(.selectedMenuBarIcon) private var menuBarIcon
@StateObject private var languageState = LanguageState()

@State var aboutWindow: NSWindow?

private func showAboutWindow() {
if let aboutWindow = aboutWindow {
aboutWindow.makeKeyAndOrderFront(nil)
} else {
aboutWindow = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 500, height: 220),
styleMask: [.titled, .closable],
backing: .buffered, defer: false
)
aboutWindow?.titleVisibility = .hidden
aboutWindow?.titlebarAppearsTransparent = true
aboutWindow?.isReleasedWhenClosed = false
aboutWindow?.center()
if #available(macOS 13, *) {
aboutWindow?.contentView = NSHostingView(rootView: SettingsAboutTab())
}
aboutWindow?.makeKeyAndOrderFront(nil)
}
}
}

// MARK: - FakeViewToOpenSettingsInSonoma
Expand Down
64 changes: 64 additions & 0 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,22 @@
}
}
},
"contributor_link" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Contributors"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "贡献者"
}
}
}
},
"copy_text" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -877,6 +893,22 @@
}
}
},
"current_version %@" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Version %@"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "版本 %@"
}
}
}
},
"custom_openai" : {
"comment" : "The name of Custom OpenAI Translate",
"localizations" : {
Expand Down Expand Up @@ -1453,6 +1485,22 @@
}
}
},
"github_link" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "GitHub"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "GitHub"
}
}
}
},
"GitHub:" : {
"localizations" : {
"zh-Hans" : {
Expand Down Expand Up @@ -2026,6 +2074,22 @@
}
}
},
"menubar.about" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "About Easydict"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "关于 Easydict"
}
}
}
},
"mini_window" : {
"localizations" : {
"en" : {
Expand Down
18 changes: 15 additions & 3 deletions Easydict/Swift/Feature/Localization/I18nHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,24 @@ class I18nHelper: NSObject {
}

var localizeCode: String {
UserDefaults.standard.string(forKey: languagePreferenceLocalKey) ?? LanguageState.LanguageType
.simplifiedChinese.rawValue
if let code = UserDefaults.standard.string(forKey: languagePreferenceLocalKey) {
return code
}

if let localLanguageType = LanguageState.LanguageType(rawValue: Locale.current.identifier) {
return localLanguageType.rawValue
}

// We should use EZLanguageModel localeIdentifier to rewrite this code.
if Locale.current.identifier == "zh_CN" {
return LanguageState.LanguageType.simplifiedChinese.rawValue
}

return LanguageState.LanguageType.english.rawValue
}

var languageType: LanguageState.LanguageType {
LanguageState.LanguageType(rawValue: localizeCode) ?? .simplifiedChinese
LanguageState.LanguageType(rawValue: localizeCode) ?? .english
}

var isSimplifiedChineseLocalize: Bool {
Expand Down
2 changes: 1 addition & 1 deletion Easydict/Swift/Feature/Localization/LanguageState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class LanguageState: ObservableObject {
}

@AppStorage(languagePreferenceLocalKey) var language: LanguageType = (.init(
rawValue: Locale.current.identifier
rawValue: I18nHelper.shared.localizeCode
) ?? .simplifiedChinese) {
didSet {
NotificationCenter.default.post(name: .languagePreferenceChanged, object: nil)
Expand Down
4 changes: 2 additions & 2 deletions Easydict/Swift/View/SettingView/SettingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct SettingView: View {
.tabItem { Label("privacy", systemImage: "hand.raised.square") }
.tag(SettingTab.privacy)

AboutTab()
SettingsAboutTab()
.tabItem { Label("about", systemImage: "info.bubble") }
.tag(SettingTab.about)
}
Expand Down Expand Up @@ -82,7 +82,7 @@ struct SettingView: View {
case .privacy:
320
case .about:
450
300
default:
maxWidth * 0.82
}
Expand Down
79 changes: 58 additions & 21 deletions Easydict/Swift/View/SettingView/Tabs/TabView/AboutTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,71 @@
// Copyright © 2023 izual. All rights reserved.
//

import Defaults
import SwiftUI

// MARK: - SettingsAboutTab

// Use ScrollView to enable resize animation for Settings
@available(macOS 13, *)
struct SettingsAboutTab: View {
var body: some View {
ScrollView {
AboutTab()
}
}
}

// MARK: - AboutTab

@available(macOS 13, *)
struct AboutTab: View {
// MARK: Internal

var body: some View {
ScrollView {
VStack(spacing: 15) {
Image(.logo)
.resizable()
.frame(width: 110, height: 110)
Text(appName)
.font(.system(size: 26, weight: .semibold))
Text("current_version") + Text(verbatim: " \(version)")
.font(.system(size: 14))

HStack {
Text("author")
Link("Tisfeng", destination: URL(string: EZGithubRepoEasydictURL)!.deletingLastPathComponent())
HStack(alignment: .center, spacing: 30) {
Image(.logo)
.resizable()
.frame(width: 100, height: 100)
.padding()
.shadow(color: .gray, radius: 1, x: 0, y: 0.8)

VStack(alignment: .leading) {
VStack(alignment: .leading) {
Text(appName)
.font(.system(size: 35, weight: .medium))
.padding(.top, 25)
.padding(.bottom, 3)

Text("current_version \(version)")
.font(.system(size: 13))
.foregroundColor(.gray)

Text(copyrightInfo)
.font(.system(size: 11))
.foregroundColor(.gray)
.padding(.top, 25)
.padding(.bottom, 20)
}
HStack {
Text("GitHub:")
Link("Easydict", destination: URL(string: EZGithubRepoEasydictURL)!)

HStack(spacing: 15) {
Button {
NSWorkspace.shared.open(URL(string: "https://github.com/tisfeng/Easydict")!)
} label: {
Label("github_link", systemImage: "star.fill")
.frame(width: 120, height: 20)
}

Button {
NSWorkspace.shared
.open(URL(string: "https://github.com/tisfeng/Easydict/graphs/contributors")!)
} label: {
Label("contributor_link", systemImage: "person.3.sequence.fill")
.frame(width: 120, height: 20)
}
}
}
.padding(.horizontal, 50)
.padding(.vertical, 30)
.frame(maxWidth: .infinity)
}
.scrollIndicators(.hidden)
.frame(maxWidth: .infinity)
}

// MARK: Private
Expand All @@ -49,6 +82,10 @@ struct AboutTab: View {
private var version: String {
Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
}

private var copyrightInfo: String {
Bundle.main.infoDictionary?["NSHumanReadableCopyright"] as? String ?? ""
}
}

@available(macOS 13, *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,18 @@ - (void)setupAppModelList {
NSArray<EZAppModel *> *allAppModelList = [EZLocalStorage.shared selectTextTypeAppModelList];
NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
for (EZAppModel *appModel in allAppModelList) {
NSURL *appURL = [workspace URLForApplicationWithBundleIdentifier:appModel.appBundleID];
if (appURL) {
[self.appModelList addObject:appModel];
/**
Fix appcenter issue
-[EZDisableAutoSelectTextViewController setupAppModelList]
EZDisableAutoSelectTextViewController.m, line 85
SIGABRT: Invalid parameter not satisfying: bundleIdentifier != nil
*/
if (appModel.appBundleID) {
NSURL *appURL = [workspace URLForApplicationWithBundleIdentifier:appModel.appBundleID];
if (appURL) {
[self.appModelList addObject:appModel];
}
}
}
}
Expand Down

0 comments on commit 73de70a

Please sign in to comment.