Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor settings menu in swiftui only UI #316

Merged
merged 10 commits into from
Jan 14, 2024
2 changes: 2 additions & 0 deletions Easydict/App/Easydict-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@
#import "EZConfiguration.h"

#import "NSString+EZConvenience.h"
#import "EZWindowManager.h"
#import "NSViewController+EZWindow.h"
122 changes: 122 additions & 0 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,16 @@
}
}
},
"Export Log" : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "导出日志"
}
}
}
},
"Failed to allocate memory" : {
"comment" : "Error reason",
"localizations" : {
Expand All @@ -1069,6 +1079,16 @@
}
}
},
"Feedback" : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "反馈问题"
}
}
}
},
"first_language" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -1283,6 +1303,16 @@
}
}
},
"Help" : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "帮助"
}
}
}
},
"hide" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -1569,6 +1599,16 @@
}
}
},
"Log Directory" : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "日志目录"
}
}
}
},
"main_window" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -1612,6 +1652,88 @@
}
}
},
"menu_input_translate" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Input Translate"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "输入翻译"
}
}
}
},
"menu_screenshot_Translate" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Screenshot Translate"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "截图翻译"
}
}
}
},
"menu_selectWord_Translate" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Select Translate"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "划词翻译"
}
}
}
},
"menu_show_mini_window" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Show Mini Window"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "显示迷你窗口"
}
}
}
},
"menu_silent_screenshot_OCR" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Silent Screenshot OCR"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "静默截图 OCR"
}
}
}
},
"mini_window" : {
"localizations" : {
"en" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN

@interface NSViewController (EZWindow)

- (NSWindow *)window;
- (nullable NSWindow *)window;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@implementation NSViewController (EZWindow)

- (NSWindow *)window {
- (nullable NSWindow *)window {
NSResponder *responder = self;
while ((responder = [responder nextResponder])) {
if ([responder isKindOfClass:[NSWindow class]]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, copy) NSString *inputText;

@property (nonatomic, assign) EZWindowType windowType;
@property (nonatomic, weak) EZBaseQueryWindow *window;
@property (nullable, nonatomic, weak) EZBaseQueryWindow *baseQueryWindow;

@property (nonatomic, strong, readonly) NSArray<EZQueryService *> *services;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,11 @@ - (void)retryQuery {

- (void)focusInputTextView {
// Fix ⚠️: ERROR: Setting <EZTextView: 0x13d82c5d0> as the first responder for window <EZFixedQueryWindow: 0x11c607800>, but it is in a different window ((null))! This would eventually crash when the view is freed. The first responder will be set to nil.
if (self.queryView.window == self.window) {
if (self.queryView.window == self.baseQueryWindow) {
// Need to activate the current application first.
[NSApp activateIgnoringOtherApps:YES];

[self.window makeFirstResponder:self.queryView.textView];
[self.baseQueryWindow makeFirstResponder:self.queryView.textView];
}
}

Expand Down Expand Up @@ -1420,7 +1420,7 @@ - (void)updateWindowViewHeightWithLock:(BOOL)lockFlag
// ???: why set window frame will change tableView height?
// ???: why this window animation will block cell rendering?
// [self.window setFrame:safeFrame display:NO animate:animateFlag];
[self.window setFrame:safeFrame display:NO];
[self.baseQueryWindow setFrame:safeFrame display:NO];

// Restore tableView height.
self.tableView.height = tableViewHeight;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ - (void)setWindowType:(EZWindowType)windowType {
- (void)setQueryViewController:(EZBaseQueryViewController *)viewController {
_queryViewController = viewController;

viewController.window = self;
viewController.baseQueryWindow = self;
self.contentViewController = viewController;
}

Expand Down
33 changes: 31 additions & 2 deletions Easydict/NewApp/EasydictApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2023 izual. All rights reserved.
//

import Sparkle
import SwiftUI

@main
Expand All @@ -20,6 +21,22 @@ enum EasydictCmpatibilityEntry {
}
}

class SPUUpdaterHelper: NSObject, SPUUpdaterDelegate {
func feedURLString(for _: SPUUpdater) -> String? {
var feedURLString = "https://raw.githubusercontent.com/tisfeng/Easydict/main/appcast.xml"
#if DEBUG
feedURLString = "http://localhost:8000/appcast.xml"
#endif
return feedURLString
}
}

class SPUUserDriverHelper: NSObject, SPUStandardUserDriverDelegate {
var supportsGentleScheduledUpdateReminders: Bool {
true
}
}

struct EasydictApp: App {
@NSApplicationDelegateAdaptor
var delegate: AppDelegate
Expand All @@ -35,10 +52,22 @@ struct EasydictApp: App {
#endif
}

let userDriverHelper = SPUUserDriverHelper()
let upadterHelper = SPUUpdaterHelper()

private let updaterController: SPUStandardUpdaterController

init() {
// 参考 https://sparkle-project.org/documentation/programmatic-setup/
// If you want to start the updater manually, pass false to startingUpdater and call .startUpdater() later
// This is where you can also pass an updater delegate if you need one
updaterController = SPUStandardUpdaterController(startingUpdater: true, updaterDelegate: upadterHelper, userDriverDelegate: userDriverHelper)
}

var body: some Scene {
if #available(macOS 13, *) {
MenuBarExtra(isInserted: $hideMenuBar.toggledValue) {
MenuItemView()
MenuItemView(updater: updaterController.updater)
} label: {
Label {
Text("Easydict")
Expand All @@ -49,7 +78,7 @@ struct EasydictApp: App {
.scaledToFit()
}
.help("Easydict 🍃")
}
}.menuBarExtraStyle(.menu)
Settings {
SettingView()
}
Expand Down
Loading
Loading