Skip to content

Commit

Permalink
Merge branch 'dev' into privacy-about-tab-defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
tisfeng authored Jan 27, 2024
2 parents 351c87d + f822299 commit 47849ff
Show file tree
Hide file tree
Showing 19 changed files with 166 additions and 146 deletions.
4 changes: 4 additions & 0 deletions Easydict.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@
EA9943EE2B5353AB00EE7B97 /* WindowTypeExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA9943ED2B5353AB00EE7B97 /* WindowTypeExtensions.swift */; };
EA9943F02B5354C400EE7B97 /* ShowWindowPositionExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA9943EF2B5354C400EE7B97 /* ShowWindowPositionExtensions.swift */; };
EA9943F22B5358BF00EE7B97 /* LanguageExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA9943F12B5358BF00EE7B97 /* LanguageExtensions.swift */; };
EAE3D3502B62E9DE001EE3E3 /* GlobalContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAE3D34F2B62E9DE001EE3E3 /* GlobalContext.swift */; };
EAED41EC2B54AA920005FE0A /* ServiceConfigurationSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAED41EB2B54AA920005FE0A /* ServiceConfigurationSection.swift */; };
EAED41EF2B54B1430005FE0A /* ConfigurableService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAED41EE2B54B1430005FE0A /* ConfigurableService.swift */; };
EAED41F22B54B39D0005FE0A /* OpenAIService+ConfigurableService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAED41F12B54B39D0005FE0A /* OpenAIService+ConfigurableService.swift */; };
Expand Down Expand Up @@ -772,6 +773,7 @@
EA9943ED2B5353AB00EE7B97 /* WindowTypeExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowTypeExtensions.swift; sourceTree = "<group>"; };
EA9943EF2B5354C400EE7B97 /* ShowWindowPositionExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShowWindowPositionExtensions.swift; sourceTree = "<group>"; };
EA9943F12B5358BF00EE7B97 /* LanguageExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LanguageExtensions.swift; sourceTree = "<group>"; };
EAE3D34F2B62E9DE001EE3E3 /* GlobalContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlobalContext.swift; sourceTree = "<group>"; };
EAED41EB2B54AA920005FE0A /* ServiceConfigurationSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceConfigurationSection.swift; sourceTree = "<group>"; };
EAED41EE2B54B1430005FE0A /* ConfigurableService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigurableService.swift; sourceTree = "<group>"; };
EAED41F12B54B39D0005FE0A /* OpenAIService+ConfigurableService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OpenAIService+ConfigurableService.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2230,6 +2232,7 @@
EA9943DD2B534BAE00EE7B97 /* Utility */ = {
isa = PBXGroup;
children = (
EAE3D34F2B62E9DE001EE3E3 /* GlobalContext.swift */,
EAED41ED2B54B1390005FE0A /* Protocol */,
EA9943E62B534D7C00EE7B97 /* Extensions */,
);
Expand Down Expand Up @@ -2795,6 +2798,7 @@
0320C5872B29F35700861B3D /* QueryServiceRecord.swift in Sources */,
03FC699A2B39D13A0035D2DA /* EZOpenAIChatResponse.m in Sources */,
03B022FA29231FA6001C7E63 /* EZServiceTypes.m in Sources */,
EAE3D3502B62E9DE001EE3E3 /* GlobalContext.swift in Sources */,
EA9943F02B5354C400EE7B97 /* ShowWindowPositionExtensions.swift in Sources */,
03B0233129231FA6001C7E63 /* MMCrash.m in Sources */,
03B0232629231FA6001C7E63 /* NSAttributedString+MM.m in Sources */,
Expand Down
3 changes: 0 additions & 3 deletions Easydict/App/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
//

#import <Cocoa/Cocoa.h>
#import <Sparkle/SPUStandardUpdaterController.h>

@interface AppDelegate : NSObject <NSApplicationDelegate>

@property (weak) IBOutlet SPUStandardUpdaterController *updaterController;

@end
25 changes: 1 addition & 24 deletions Easydict/App/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,12 @@
//

#import "AppDelegate.h"
#import "EZMenuItemManager.h"
#import "EZShortcut.h"
#import "MMCrash.h"
#import "EZWindowManager.h"
#import "EZLanguageManager.h"
#import "EZLog.h"
#import "EZSchemeParser.h"
#import "AppDelegate+EZURLScheme.h"
#import <Sparkle/SPUUpdaterDelegate.h>
#import <Sparkle/SPUStandardUserDriverDelegate.h>
#import "Easydict-Swift.h"

@interface AppDelegate () <SPUUpdaterDelegate, SPUStandardUserDriverDelegate>
@interface AppDelegate ()

@end

Expand Down Expand Up @@ -99,20 +92,4 @@ - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)applica
return NO;
}

#pragma mark - SUUpdaterDelegate

- (NSString *)feedURLStringForUpdater:(SPUUpdater *)updater {
NSString *feedURLString = @"https://raw.githubusercontent.com/tisfeng/Easydict/main/appcast.xml";
#if DEBUG
feedURLString = @"http://localhost:8000/appcast.xml";
#endif
return feedURLString;
}

#pragma mark - SPUStandardUserDriverDelegate

- (BOOL)supportsGentleScheduledUpdateReminders {
return YES;
}

@end
14 changes: 2 additions & 12 deletions Easydict/App/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -716,18 +716,8 @@ DQ
<outlet property="delegate" destination="Voe-Tx-rLC" id="PrD-fu-P6m"/>
</connections>
</application>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate">
<connections>
<outlet property="updaterController" destination="dTQ-Lg-1D6" id="ulf-mx-z8R"/>
</connections>
</customObject>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate"/>
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
<customObject id="dTQ-Lg-1D6" customClass="SPUStandardUpdaterController">
<connections>
<outlet property="updaterDelegate" destination="Voe-Tx-rLC" id="3Ya-Y2-qiK"/>
<outlet property="userDriverDelegate" destination="Voe-Tx-rLC" id="pxF-ql-RTh"/>
</connections>
</customObject>
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
<customObject id="qM9-fT-Fym" customClass="EZMenuItemManager">
<connections>
Expand Down Expand Up @@ -799,7 +789,7 @@ DQ
<menuItem title="检查更新" id="GQ2-WA-9QB">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="checkForUpdates:" target="dTQ-Lg-1D6" id="ydL-Jy-6z2"/>
<action selector="checkForUpdateItem:" target="qM9-fT-Fym" id="m6i-mV-Hiy"/>
</connections>
</menuItem>
<menuItem title="帮助" id="ICB-w8-IqK">
Expand Down
29 changes: 18 additions & 11 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1958,16 +1958,6 @@
}
}
},
"other" : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "其他"
}
}
}
},
"Parameter Error" : {
"comment" : "Error description",
"localizations" : {
Expand Down Expand Up @@ -2772,6 +2762,23 @@
}
}
},
"setting.general.other.header" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Other"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "其他"
}
}
}
},
"setting.general.quick_link.header" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -3443,4 +3450,4 @@
}
},
"version" : "1.0"
}
}
10 changes: 2 additions & 8 deletions Easydict/Feature/Configuration/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ let kHideMenuBarIconKey = "EZConfiguration_kHideMenuBarIconKey"
}
}

var appDelegate = NSApp.delegate as? AppDelegate

var updater: SPUUpdater? {
appDelegate?.updaterController.updater
}

@DefaultsWrapper(.firstLanguage)
var firstLanguage: Language

Expand Down Expand Up @@ -65,10 +59,10 @@ let kHideMenuBarIconKey = "EZConfiguration_kHideMenuBarIconKey"

var automaticallyChecksForUpdates: Bool {
get {
updater?.automaticallyChecksForUpdates ?? false
GlobalContext.shared.updaterController.updater.automaticallyDownloadsUpdates
}
set {
updater?.automaticallyChecksForUpdates = newValue
GlobalContext.shared.updaterController.updater.automaticallyDownloadsUpdates = newValue
logSettings(["automatically_checks_for_updates": newValue])
}
}
Expand Down
3 changes: 3 additions & 0 deletions Easydict/Feature/Configuration/EZConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import <Foundation/Foundation.h>
#import "EZLanguageManager.h"
#import "EZLayoutManager.h"
#import <Sparkle/SPUUpdater.h>

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -84,6 +85,8 @@ typedef NS_ENUM(NSUInteger, EZAppearenceType) {

@property (nonatomic, assign) EZAppearenceType appearance;

@property (nonatomic, strong, readonly) SPUUpdater *updater;

+ (instancetype)shared;
+ (void)destroySharedInstance;

Expand Down
10 changes: 5 additions & 5 deletions Easydict/Feature/Configuration/EZConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
@interface EZConfiguration ()

@property (nonatomic, strong) AppDelegate *appDelegate;
@property (nonatomic, strong) SPUUpdater *updater;
@property (nonatomic, strong, readwrite) SPUUpdater *updater;

@end

Expand Down Expand Up @@ -142,12 +142,12 @@ - (BOOL)launchAtStartup {
return launchAtStartup;
}

- (BOOL)automaticallyChecksForUpdates {
return self.updater.automaticallyChecksForUpdates;
- (SPUUpdater *)updater {
return GlobalContext.shared.updaterController.updater;
}

- (SPUUpdater *)updater {
return self.appDelegate.updaterController.updater;
- (BOOL)automaticallyChecksForUpdates {
return self.updater.automaticallyChecksForUpdates;
}

#pragma mark - setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ - (void)viewDidLoad {
}

- (void)setup {
self.appModelList = [[EZLocalStorage.shared selectTextTypeAppModelList] mutableCopy];
[self setupAppModelList];

[self.titleTextField mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.inset(kMargin + 5); // ???: Why is the actual inset is 18?
Expand All @@ -78,6 +78,18 @@ - (void)setup {
}];
}

- (void)setupAppModelList {
self.appModelList = [[NSMutableArray alloc] init];
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];
}
}
}


#pragma mark - Getter && Setter

Expand Down
38 changes: 20 additions & 18 deletions Easydict/Feature/Service/Apple/EZAppleService.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

static NSArray *const kAllowedCharactersInPoetryList = @[ @"", @"", @"", @"" ];

static CGFloat const kParagraphLineHeightRatio = 1.2;
static CGFloat const kParagraphLineHeightRatio = 1.5;

static NSInteger const kShortPoetryCharacterCountOfLine = 12;

Expand Down Expand Up @@ -1211,18 +1211,6 @@ - (void)setupOCRResult:(EZOCRResult *)ocrResult
CGFloat deltaY = prevBoundingBox.origin.y - (boundingBox.origin.y + boundingBox.size.height);
CGFloat deltaX = boundingBox.origin.x - (prevBoundingBox.origin.x + prevBoundingBox.size.width);

// Note that line spacing is inaccurate, sometimes it's too small 😢
BOOL isNewParagraph = NO;
if (deltaY > 0) {
// averageLineSpacing may too small, so deltaY should be much larger than averageLineSpacing
BOOL isBigLineSpacing = [self isBigSpacingLineOfTextObservation:textObservation
prevTextObservation:prevTextObservation
greaterThanLineHeightRatio:kParagraphLineHeightRatio];
if (isBigLineSpacing) {
isNewParagraph = YES;
}
}

// Note that sometimes the line frames will overlap a little, then deltaY will less then 0
BOOL isNewLine = NO;
if (deltaY > 0) {
Expand Down Expand Up @@ -1251,10 +1239,9 @@ - (void)setupOCRResult:(EZOCRResult *)ocrResult
if (isNeedRemoveLastDashOfText) {
mergedText = [mergedText substringToIndex:mergedText.length - 1].mutableCopy;
}
} else if (isNewParagraph || isNewLine) {
} else if (isNewLine) {
joinedString = [self joinedStringOfTextObservation:textObservation
prevTextObservation:prevTextObservation
isNewParagraph:isNewParagraph];
prevTextObservation:prevTextObservation];
} else {
joinedString = @" "; // if the same line, just join two texts
}
Expand Down Expand Up @@ -1489,9 +1476,10 @@ - (BOOL)isPoetryOftextObservations:(NSArray<VNRecognizedTextObservation *> *)tex
/// Get joined string of text, according to its last char.
- (NSString *)joinedStringOfTextObservation:(VNRecognizedTextObservation *)textObservation
prevTextObservation:(VNRecognizedTextObservation *)prevTextObservation
isNewParagraph:(BOOL)isNewParagraph {
{
NSString *joinedString = @"";
BOOL needLineBreak = NO;
BOOL isNewParagraph = NO;

CGRect prevBoundingBox = prevTextObservation.boundingBox;
CGFloat prevLineLength = prevBoundingBox.size.width;
Expand All @@ -1509,7 +1497,7 @@ - (NSString *)joinedStringOfTextObservation:(VNRecognizedTextObservation *)textO

BOOL hasPrevIndentation = [self hasIndentationOfTextObservation:prevTextObservation];
BOOL hasIndentation = [self hasIndentationOfTextObservation:textObservation];

BOOL isPrevLongText = [self isLongTextObservation:prevTextObservation isStrict:NO];

BOOL isEqualChineseText = [self isEqualChineseTextObservation:textObservation prevTextObservation:prevTextObservation];
Expand Down Expand Up @@ -1895,6 +1883,20 @@ - (BOOL)hasIndentationOfTextObservation:(VNRecognizedTextObservation *)textObser
return hasIndentation;
}

- (BOOL)hasIndentationOfTextObservation:(VNRecognizedTextObservation *)textObservation
prevTextObservation:(VNRecognizedTextObservation *)prevTextObservation {
BOOL isEqualX = [self isEqualXOfTextObservation:textObservation prevTextObservation:prevTextObservation];

CGFloat lineX = CGRectGetMinX(textObservation.boundingBox);
CGFloat prevLineX = CGRectGetMinX(prevTextObservation.boundingBox);
CGFloat dx = lineX - prevLineX;

if (!isEqualX && dx < 0) {
return YES;
}
return NO;
}

- (BOOL)isEqualTextObservation:(VNRecognizedTextObservation *)textObservation
prevTextObservation:(VNRecognizedTextObservation *)prevTextObservation {
// 0.06 - 0.025
Expand Down
1 change: 0 additions & 1 deletion Easydict/Feature/Service/DeepL/EZDeepLTranslate.m
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ - (void)deepLTranslate:(NSString *)text from:(EZLanguage)from to:(EZLanguage)to
}
*/
NSString *translatedText = [responseObject[@"translations"] firstObject][@"text"];
translatedText = [translatedText.trim removeExtraLineBreaks];
NSArray *translatedTextArray = [translatedText toParagraphs];

return translatedTextArray;
Expand Down
Loading

0 comments on commit 47849ff

Please sign in to comment.