Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Tencent/lemon-cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jul 6, 2024
2 parents e099dfa + 955092b commit f6572d3
Show file tree
Hide file tree
Showing 38 changed files with 6,529 additions and 6,185 deletions.
4 changes: 2 additions & 2 deletions Lemon/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>5.1.8</string>
<string>5.1.9</string>
<key>CFBundleVersion</key>
<string>1015</string>
<string>1017</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSAppTransportSecurity</key>
Expand Down
12 changes: 11 additions & 1 deletion Lemon/MobileNotification/QMUserNotificationCenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@
//

#import <Foundation/Foundation.h>
#import <UserNotifications/UserNotifications.h>

@import UserNotifications;
typedef NS_ENUM(NSUInteger, QMUNCNotificationAction) {
QMUNCNotificationActionNone,
QMUNCNotificationActionShown,
QMUNCNotificationActionContentClicked,
QMUNCNotificationActionButtonClicked,
QMUNCNotificationActionDismissed,
};

#define UNNotificationActionDidBlock @"UNNotificationActionDidBlock" // 弹窗中选择【拒绝】按钮操作

Expand All @@ -30,4 +37,7 @@
- (void)deliverNotification:(NSUserNotification *)notification key:(NSString *)key;
- (void)removeAllDeliveredNotifications;

/// 通知弹窗行为回调
- (void)addNotificationActionCallBack:(void(^)(QMUNCNotificationAction action, NSString *notificationKey))callBack;

@end
78 changes: 71 additions & 7 deletions Lemon/MobileNotification/QMUserNotificationCenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#define kNotificationKey @"_notification_key"
#define kNotificationCategoryKey @"_category_key"

@interface QMUserNotificationCenter ()
@property (nonatomic, copy) void (^actionCallBack)(QMUNCNotificationAction action, NSString *notificationKey);
@end

@implementation QMUserNotificationCenter

- (id)init
Expand Down Expand Up @@ -83,18 +87,13 @@ - (void)deliverNotification:(NSUserNotification *)notification key:(NSString *)k
request = [UNNotificationRequest requestWithIdentifier:notification.identifier content:content trigger:NULL];

//send notification
__weak typeof(self) weakSelf = self;
NSSet *categories = [NSSet setWithArray:@[[self categoryWithUserNotification:notification]]];
[[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:categories];
[[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError *_Nullable error)
{
if (!error) {
NSString * key = [dict objectForKey:kNotificationKey];
if (key) {
id obj = [self->_delegateDict objectForKey:key];
if ([obj respondsToSelector:@selector(userNotificationCenter:didDeliverNotification:)])
[obj userNotificationCenter:[NSUserNotificationCenter defaultUserNotificationCenter]
didDeliverNotification:notification];
}
[weakSelf presentedWhenAuthorizedWithNotification:notification key:key];
}
}];

Expand All @@ -106,6 +105,24 @@ - (void)deliverNotification:(NSUserNotification *)notification key:(NSString *)k
return;
}

- (void)presentedWhenAuthorizedWithNotification:(NSUserNotification *)notification key:(NSString *)key API_AVAILABLE(macos(10.14)) {
__weak typeof(self) weakSelf = self;
[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
__strong typeof(weakSelf) strongSelf = weakSelf;
if (settings.authorizationStatus == UNAuthorizationStatusAuthorized
|| settings.authorizationStatus == UNAuthorizationStatusProvisional) {
if (key) {
// 通知被展示(添加的通知均为立即展示)
[strongSelf notificationPresentedWithNotificationKey:key];
id obj = [strongSelf->_delegateDict objectForKey:key];
if ([obj respondsToSelector:@selector(userNotificationCenter:didDeliverNotification:)])
[obj userNotificationCenter:[NSUserNotificationCenter defaultUserNotificationCenter]
didDeliverNotification:notification];
}
}
}];
}

- (void)removeAllDeliveredNotifications {
if (@available(macOS 10.14, *)) {
[[UNUserNotificationCenter currentNotificationCenter] removeAllDeliveredNotifications];
Expand Down Expand Up @@ -196,6 +213,7 @@ - (void)userNotificationCenter:(NSUserNotificationCenter *)center didDeliverNoti
NSString * key = [userInfo objectForKey:kNotificationKey];
if (key)
{
[self notificationPresentedWithNotificationKey:key];
id obj = [_delegateDict objectForKey:key];
if ([obj respondsToSelector:@selector(userNotificationCenter:didDeliverNotification:)])
[obj userNotificationCenter:center didDeliverNotification:notification];
Expand All @@ -211,6 +229,13 @@ - (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNot
return;
}
NSString * key = [userInfo objectForKey:kNotificationKey];
if (notification.activationType == NSUserNotificationActivationTypeContentsClicked) {
[self notificationContentClickedWithNotificationKey:key];
} else if (notification.activationType == NSUserNotificationActivationTypeActionButtonClicked) {
[self notificationButtonClickedWithNotificationKey:key];
} else if (notification.activationType == NSUserNotificationActivationTypeNone) {
[self notificationDismissedWithNotificationKey:key];
}
if (key)
{
id obj = [_delegateDict objectForKey:key];
Expand Down Expand Up @@ -284,6 +309,13 @@ - (UNNotificationCategory *)categoryWithUserNotification:(NSUserNotification *)n
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler API_AVAILABLE(macos(10.14)) {

NSString *key = [response.notification.request.content.userInfo objectForKey:kNotificationKey];
if ([response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier]) {
[self notificationContentClickedWithNotificationKey:key];
} else if ([response.actionIdentifier isEqualToString:UNNotificationDismissActionIdentifier]) {
[self notificationDismissedWithNotificationKey:key];
} else {
[self notificationButtonClickedWithNotificationKey:key];
}
if (key) {
id obj = [_delegateDict objectForKey:key];

Expand All @@ -304,6 +336,38 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNoti

}

#pragma mark - private

/// 通知被展示
- (void)notificationPresentedWithNotificationKey:(NSString *)key {
if (self.actionCallBack) {
self.actionCallBack(QMUNCNotificationActionShown, key?:@"");
}
}

/// 通知内容被点击
- (void)notificationContentClickedWithNotificationKey:(NSString *)key {
if (self.actionCallBack) {
self.actionCallBack(QMUNCNotificationActionContentClicked, key?:@"");
}
}

/// 通知按钮被点击
- (void)notificationButtonClickedWithNotificationKey:(NSString *)key {
if (self.actionCallBack) {
self.actionCallBack(QMUNCNotificationActionButtonClicked, key?:@"");
}
}

/// 通知被关闭
- (void)notificationDismissedWithNotificationKey:(NSString *)key {
if (self.actionCallBack) {
self.actionCallBack(QMUNCNotificationActionDismissed, key?:@"");
}
}

- (void)addNotificationActionCallBack:(void (^)(QMUNCNotificationAction, NSString *))callBack {
self.actionCallBack = callBack;
}

@end
39 changes: 38 additions & 1 deletion LemonClener/LemonClener/Controller/LMCleanBigViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#import <QMCoreFunction/NSColor+Extension.h>
#import <QMCoreFunction/McCoreFunction.h>
#import <QMCleanManager.h>
#import "CleanerCantant.h"
#import <Masonry/Masonry.h>
#import <QMUICommon/QMProgressView.h>
#import <QMUICommon/LMBorderButton.h>
Expand All @@ -45,6 +44,7 @@
#import <LemonFileMove/LMFileMoveFeatureDefines.h>

#define Lemon_KB_To_GB 1000000000.0
#define kItemIdDownloadSubItemID @"1007"

static NSString * const kLemonFileMoveIntroduceVCDidAppear = @"kLemonFileMoveIntroduceVCDidAppear";

Expand Down Expand Up @@ -876,6 +876,10 @@ - (void)checkButtonAction:(id)sender
return;
}

if (checkBtn.state == NSOnState) {
[self showAlertIfNeededWhenSelectItem:item control:checkBtn];
}

if ([item isKindOfClass:[QMCategorySubItem class]] && [item isScaned]) {
//写入数据库,记住用户选择
if (checkBtn.state == NSOnState) {
Expand Down Expand Up @@ -1046,6 +1050,39 @@ - (void)refreshStateValue:(QMBaseItem *)item {

}

- (void)showAlertIfNeededWhenSelectItem:(QMCategorySubItem *)item control:(NSButton *)button{
if (![item isKindOfClass:QMCategorySubItem.class]) {
return;
}
if (![item.subCategoryID isEqualToString:kItemIdDownloadSubItemID]) {
return;
}
BOOL isShowed = [[NSUserDefaults standardUserDefaults] boolForKey:LMCLEAN_DOWNLOAD_SELECT_ALL_ALERT_SHOWED];
if (isShowed) {
return;
}
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:LMCLEAN_DOWNLOAD_SELECT_ALL_ALERT_SHOWED];

NSAlert *alert = [[NSAlert alloc] init];

[alert.accessoryView setFrameOrigin:NSMakePoint(0, 0)];
alert.alertStyle = NSAlertStyleInformational;
alert.messageText = NSLocalizedStringFromTableInBundle(@"LMCleanBigViewController_downloadSelectAll_alert_titleString_1", nil, [NSBundle bundleForClass:[self class]], @"");
alert.informativeText = NSLocalizedStringFromTableInBundle(@"LMCleanBigViewController_downloadSelectAll_alert_descString_1", nil, [NSBundle bundleForClass:[self class]], @"");
[alert addButtonWithTitle:NSLocalizedStringFromTableInBundle(@"LMCleanBigViewController_downloadSelectAll_alert_okButtonString_1", nil, [NSBundle bundleForClass:[self class]], @"")];
[alert addButtonWithTitle:NSLocalizedStringFromTableInBundle(@"LMCleanBigViewController_downloadSelectAll_alert_cancelButtonString_1", nil, [NSBundle bundleForClass:[self class]], @"")];

__weak typeof(self) weakSelf = self;
[alert beginSheetModalForWindow:self.view.window completionHandler:^(NSModalResponse returnCode) {
if (returnCode == NSAlertFirstButtonReturn) {

} else {
button.state = NSControlStateValueOff;
[weakSelf checkButtonAction:button];
}
}];

}

#pragma mark -- 扫描或者清理定时器回调方法
- (void)scanProgressRefresh:(id)sender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
"LMCleanBigViewController_rememberCleanSetting_alert_titleLabelString_2" = "Cancel cleanup items next time";
"LMCleanBigViewController_rememberCleanSetting_alert_okButtonString_1" = "OK";
"LMCleanBigViewController_rememberCleanSetting_alert_cancelButtonString_1" = "Cancel";
"LMCleanBigViewController_downloadSelectAll_alert_titleString_1" = "Delete Download Files";
"LMCleanBigViewController_downloadSelectAll_alert_descString_1" = "Downloaded files may contain important files, such as those downloaded through a browser, Please confirm and select them.";
"LMCleanBigViewController_downloadSelectAll_alert_okButtonString_1" = "Confirm Selection";
"LMCleanBigViewController_downloadSelectAll_alert_cancelButtonString_1" = "Cancel";
"LMCleanScanViewController_initView_startScanBtn_1" = "Grant access";
"LMCleanScanViewController_initView_mainViewDescLabel_2" = "Welcome to Lemon Cleaner Lite";
"LMCleanScanViewController_initView_mainViewDescLabel_3" = "Welcome to Lemon Cleaner";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
"LMCleanBigViewController_rememberCleanSetting_alert_titleLabelString_2" = "如果不需要清理,将不会记住这个目录!";
"LMCleanBigViewController_rememberCleanSetting_alert_okButtonString_1" = "确定";
"LMCleanBigViewController_rememberCleanSetting_alert_cancelButtonString_1" = "取消";
"LMCleanBigViewController_downloadSelectAll_alert_titleString_1" = "是否删除下载文件";
"LMCleanBigViewController_downloadSelectAll_alert_descString_1" = "下载文件可能包含重要文件。例如通过浏览器下载的文件,请确认后勾选";
"LMCleanBigViewController_downloadSelectAll_alert_okButtonString_1" = "确认勾选";
"LMCleanBigViewController_downloadSelectAll_alert_cancelButtonString_1" = "取消";
"LMCleanScanViewController_initView_startScanBtn_1" = "获取权限";
"LMCleanScanViewController_initView_mainViewDescLabel_2" = "欢迎使用 Lemon Cleaner Lite";
"LMCleanScanViewController_initView_mainViewDescLabel_3" = "欢迎使用 Lemon Cleaner";
Expand Down
3 changes: 3 additions & 0 deletions LemonClener/LemonClener/Util/CleanerCantant.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,7 @@ typedef NS_ENUM(NSUInteger, SysSubcategoryIdType) {

#define IS_SHOW_BIG_VIEW @"is_show_big_view" //打开主界面后,是否展示大界面

// alert 标识符
#define LMCLEAN_DOWNLOAD_SELECT_ALL_ALERT_SHOWED @"LMCLEAN_DOWNLOAD_SELECT_ALL_ALERT_SHOWED"

#endif /* CleanerCantant_h */
2 changes: 2 additions & 0 deletions LemonClener/LemonClener/libcleaner/QMScanCategory.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#import "QMCacheEnumerator.h"
#import "QMWechatScan.h"
#import "QMScanFileSizeCacheManager.h"
#import "CleanerCantant.h"

@interface QMScanCategory()<QMScanDelegate>

Expand Down Expand Up @@ -198,6 +199,7 @@ - (void)scanCategoryWithItem:(QMCategoryItem *)categoryItem

- (void)startScanAllCategoryArray:(NSArray *)itemArray
{
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:LMCLEAN_DOWNLOAD_SELECT_ALL_ALERT_SHOWED];
self.isStopScan = NO;
dispatch_async(dispatch_get_global_queue(0, 0), ^{
[self performAllCategoryScanWithArray:itemArray];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ - (BOOL)hasCachedFileSizeWithPath:(NSString *)path {
return NO;
}

return [self.mutableDict.allKeys containsObject:path];
return self.mutableDict[path] != nil;
}

- (uint64)getCachedFileSizeWithPath:(NSString *)path {
Expand Down
2 changes: 2 additions & 0 deletions LemonClener/LemonClener/libcleaner/QMXMLItem/QMActionItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ - (void)addActionPathItem:(QMActionPathItem *)item
- (void)addResultItem:(QMResultItem *)item
{
@synchronized (self) {
/// array 中元素较多时 containsObject:耗时较高
/// set的containsObject 的时间复杂度为O(1)
if (![self.m_resultItemArray containsObject:item])
{
[self.m_resultItemArray addObject:item];
Expand Down
3 changes: 1 addition & 2 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def available_pods
pod 'QMCoreFunction',:path => './localPod/QMCoreFunction'
pod 'Masonry', '= 1.1.0'
pod 'FMDB', '= 2.7.5'
pod 'LemonFileManager',:path => './localPod/LemonFileManager'
end
target 'Lemon' do
use_frameworks!
Expand All @@ -35,7 +36,6 @@ target 'Lemon' do
pod 'LemonUninstaller',:path => './localPod/LemonUninstaller'
pod 'LemonLoginItemManager',:path => './localPod/LemonLoginItemManager'
pod 'LemonFileMove',:path => './localPod/LemonFileMove'
pod 'LemonFileManager',:path => './localPod/LemonFileManager'

end

Expand All @@ -61,7 +61,6 @@ target 'LemonClener' do
inherit! :search_paths
project 'LemonClener/LemonClener.xcodeproj'
pod 'LemonFileMove',:path => './localPod/LemonFileMove'
pod 'LemonFileManager',:path => './localPod/LemonFileManager'
available_pods
end

Expand Down
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,6 @@ SPEC CHECKSUMS:
QMUICommon: e2f5520cce7e70c46b2297294d7656a30b8e0c4f
YMTreeMap: 8bd766573bc5005cf6b6f5d2674e4225ee734f6e

PODFILE CHECKSUM: 0e60e5fc829530706e4624ee4f84df3f7076eafb
PODFILE CHECKSUM: 7c90e302b84c5e645af9a8c80d982264f03d8f00

COCOAPODS: 1.15.2
2 changes: 1 addition & 1 deletion Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f6572d3

Please sign in to comment.