Skip to content

Commit

Permalink
1. Settings view controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightonke committed Mar 9, 2017
1 parent 557b9d3 commit 07754f7
Show file tree
Hide file tree
Showing 38 changed files with 1,177 additions and 114 deletions.
24 changes: 0 additions & 24 deletions VHGithubNotifier/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,32 +119,8 @@ - (void)showMenu
}
else
{
// [self populate];
NOTIFICATION_POST(kNotifyWindowWillAppear);
NSRect statusItemFrame = [[self.statusItem.view window] convertRectToScreen:self.statusItem.view.frame];
// NSLog(@"%zd", [NSScreen screens].count);
// NSScreen *screen = [NSScreen mainScreen];
// NSLog(@"%@", [[[NSApp currentEvent] window] screen]);
// NSRect rect = [[[NSApp currentEvent] window] frame];
// NSLog(@"%f, %f, %f, %f",
// rect.origin.x,
// rect.origin.y,
// rect.size.width,
// rect.size.height);
//
// for(NSScreen* screen in [NSScreen screens])
// {
// NSRect cocoaScreenFrame = [screen frame];
// NSLog(@"Screen(%@) frame in Cocoa coordinate space: %@", screen, NSStringFromRect(cocoaScreenFrame));
// }
//
//// [self.menuWindow ]
// [self.menuWindow constrainFrameRect:NSMakeRect(statusItemFrame.origin.x + statusItemFrame.size.width / 2,
// statusItemFrame.origin.y - self.menuWindow.frame.size.height - 5,
// self.menuWindow.frame.size.width,
// self.menuWindow.frame.size.height)
// toScreen:[[[NSApp currentEvent] window] screen]];
// NSLog(@"Window changed to %@", self.menuWindow.screen);
[self.menuWindow updateArrowWithStatusItemCenterX:statusItemFrame.origin.x + statusItemFrame.size.width / 2
withStatusItemFrame:statusItemFrame];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "icon_github_url.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "icon_github_url@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "icon_github_url@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "icon_refresh.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "icon_refresh@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "icon_refresh@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "icon_user_placeholder.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "icon_user_placeholder@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "icon_user_placeholder@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions VHGithubNotifier/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>Gitee</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIconFile</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@

- (NSString *)urlFromRepositoryName:(NSString *)name;

- (NSUInteger)repositoriesPieTotalStarNumber;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@
#import "VHGithubNotifierManager+UserDefault.h"
#import "VHUtils.h"

static NSUInteger repositoriesPieTotalStarNumber = 0;

@implementation VHGithubNotifierManager (ChartDataProvider)

- (PieChartData *)userRepositoriesPieDataSet
{
__block NSMutableArray<PieChartDataEntry *> *array = [NSMutableArray arrayWithCapacity:self.user.ownerRepositories.count];
__block PieChartDataEntry *entry;
repositoriesPieTotalStarNumber = 0;
for (VHRepository *repository in self.user.ownerRepositories)
{
if (repository.starNumber >= [[VHGithubNotifierManager sharedManager] minimumStarNumberInPie])
{
repositoriesPieTotalStarNumber += repository.starNumber;
entry = [[PieChartDataEntry alloc] initWithValue:repository.starNumber label:repository.name];
[array addObject:entry];
}
Expand Down Expand Up @@ -70,4 +74,9 @@ - (NSString *)urlFromRepositoryName:(NSString *)name
return nil;
}

- (NSUInteger)repositoriesPieTotalStarNumber
{
return repositoriesPieTotalStarNumber;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@

- (NSString *)todayContributionsTimeString;

- (void)updateContributionChartLocally;

@end
17 changes: 16 additions & 1 deletion VHGithubNotifier/Model/Manager/VHGithubNotifierManager+Profile.m
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ - (NSString *)todayContributionsTimeString
return [dateFormatter stringFromDate:[contributionBlocks lastObject].date];
}

- (void)updateContributionChartLocally
{
dispatch_async(GLOBAL_QUEUE, ^{
if (contributionChartDrawer == nil)
{
contributionChartDrawer = [[VHContributionChartDrawer alloc] init];
}
[contributionChartDrawer readyForDrawingFromContributionBlocks:contributionBlocks];
NOTIFICATION_POST_IN_MAIN_THREAD(kNotifyContributionChartChanged);
});
}

#pragma mark - Private Methods

- (void)innerUpdateProfile
Expand Down Expand Up @@ -189,7 +201,10 @@ - (void)innerUpdateContributions
contributionBlocks = [blocks copy];
[self calculateYearContributions];

contributionChartDrawer = [[VHContributionChartDrawer alloc] init];
if (contributionChartDrawer == nil)
{
contributionChartDrawer = [[VHContributionChartDrawer alloc] init];
}
[contributionChartDrawer readyForDrawingFromContributionBlocks:contributionBlocks];

NOTIFICATION_POST_IN_MAIN_THREAD(kNotifyContributionBlocksLoadedSuccessfully);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@
*/
- (void)loadUser;

/**
Realm directory.
@return url of realm directory
*/
- (NSURL *)realmDirectory;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ - (void)loadUser
}
}

- (NSURL *)realmDirectory
{
return [[self realm].configuration.fileURL URLByDeletingLastPathComponent];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ - (BOOL)loadTrendChartInWebView:(WKWebView *)webView withTrendContentIndex:(NSUI

- (void)copyJsFiles
{
NSURL *toPath = [self realm].configuration.fileURL;
toPath = [toPath URLByDeletingLastPathComponent];
NSURL *toPath = [self realmDirectory];

[self copyFileFromPath:[[NSBundle mainBundle] pathForResource:@"echarts" ofType:@"js"]
toPath:[[toPath URLByAppendingPathComponent:@"echarts.js"] relativePath]];
Expand Down
2 changes: 2 additions & 0 deletions VHGithubNotifier/Model/Manager/VHGithubNotifierManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

- (void)updateBasicInfo;

- (void)updateAllTimer;

- (void)redirectLogToDocuments;

- (void)confirmUserAccount:(NSString *)username withPassword:(NSString *)password;
Expand Down
32 changes: 24 additions & 8 deletions VHGithubNotifier/Model/Manager/VHGithubNotifierManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
#import "UAGithubEngine.h"
#import "VHGithubNotifierManager_Private.h"
#import "VHGithubNotifierManager+UserDefault.h"
#import "VHGithubNotifierManager+Language.h"
#import "VHGithubNotifierManager+Trending.h"
#import "VHGithubNotifierManager+Realm.h"
#import "VHGithubNotifierManager+Notification.h"
#import "VHGithubNotifierManager+UserNotification.h"
#import "VHGithubNotifierManager+Trend.h"
#import "VHGithubNotifierManager+Profile.h"

static VHLoadStateType repositoriesLoadState = VHLoadStateTypeDidNotLoad;
static NSTimeInterval lastUpdateAllTime;

@interface VHGithubNotifierManager ()

Expand Down Expand Up @@ -58,6 +62,21 @@ - (void)updateBasicInfo
});
}

- (void)updateAllTimer
{
MUST_IN_MAIN_THREAD;
if ([[NSDate date] timeIntervalSince1970] - lastUpdateAllTime <= 10)
{
return;
}
lastUpdateAllTime = [[NSDate date] timeIntervalSince1970];
[self updateBasicInfo];
[self updateLanguages];
[self updateTrending];
[self updateNotification];
[self updateProfile];
}

- (void)redirectLogToDocuments
{
RELEASE_CODE(freopen([[[self logFileURL] path] cStringUsingEncoding:NSUTF8StringEncoding], "a+", stderr));
Expand Down Expand Up @@ -153,12 +172,11 @@ - (void)resetFromWakeNotification
- (NSURL *)logFileURL
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
[formatter setDateFormat:@"yyyy_MM_dd_HH_mm_ss"];
NSString *stringFromDate = [formatter stringFromDate:[NSDate date]];
NSURL *desktopUrl = [[NSFileManager defaultManager] URLForDirectory:NSDesktopDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
NSURL *directoryUrl = [desktopUrl URLByAppendingPathComponent:@"GithubNotifierLogs"];
NSURL *directoryUrl = [[self realmDirectory] URLByAppendingPathComponent:@"GiteeLogs"];
[[NSFileManager defaultManager] createDirectoryAtURL:directoryUrl withIntermediateDirectories:YES attributes:nil error:nil];
NSURL *fileUrl = [directoryUrl URLByAppendingPathComponent:[NSString stringWithFormat:@"GithubNotifierLog_%@.log", stringFromDate]];
NSURL *fileUrl = [directoryUrl URLByAppendingPathComponent:[NSString stringWithFormat:@"Gitee_Log_%@.log", stringFromDate]];
return fileUrl;
}

Expand Down Expand Up @@ -189,8 +207,7 @@ - (void)innerUpdateRepositories
dispatch_group_async(requestGroup, queue, ^{
dispatch_group_enter(requestGroup);
[[self engine] repositoriesForUser:[self userAccount] includeWatched:NO page:page success:^(id responseObject) {
RELEASE_CODE(BasicInfoLog(@"Update repositories in page %d successed: %@", page, responseObject));
DEBUG_CODE(BasicInfoLog(@"Update repositories in page %d successed", page));
BasicInfoLog(@"Update repositories in page %d successed", page);
allSuccessful = YES;
NSArray *array = SAFE_CAST(responseObject, [NSArray class]);
if (array != nil)
Expand Down Expand Up @@ -262,8 +279,7 @@ - (void)innerUpdateBasicInfo
dispatch_async(GLOBAL_QUEUE, ^{
// userWithSuccess spends a long time
[[self engine] userWithSuccess:^(id responseObject) {
RELEASE_CODE(BasicInfoLog(@"Update basic info successfully: %@", responseObject));
DEBUG_CODE(BasicInfoLog(@"Update basic info successfully"));
BasicInfoLog(@"Update basic info successfully");
NSArray *array = SAFE_CAST(responseObject, [NSArray class]);
if ([array count] != 0)
{
Expand Down
1 change: 1 addition & 0 deletions VHGithubNotifier/Utils/VHLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ extern "C"
#define NotificationLog(format,...) PermanentLog(@"Notification",format,##__VA_ARGS__)
#define ProfileLog(format,...) PermanentLog(@"Profile",format,##__VA_ARGS__)
#define ViewLog(format,...) PermanentLog(@"View",format,##__VA_ARGS__)
#define SettingsLog(format,...) PermanentLog(@"Settings",format,##__VA_ARGS__)

#endif /* VHLog_h */
4 changes: 4 additions & 0 deletions VHGithubNotifier/Utils/VHUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@

+ (void)openUrl:(NSString *)url;

+ (void)openURL:(NSURL *)url;

+ (void)resetWKWebViewExceptCookie;

+ (void)resetWKWebView;

+ (void)scrollViewToTop:(NSScrollView *)scrollView;

+ (NSArray<NSColor *> *)randomColors;

@end
26 changes: 24 additions & 2 deletions VHGithubNotifier/Utils/VHUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ + (BOOL)point:(CGPoint)point notOutOfRect:(CGRect)rect

+ (void)setRandomColor:(ChartDataSet *)chartDataSet withNumber:(NSInteger)count
{
[chartDataSet setColors:[VHUtils colors]];
[chartDataSet setColors:[VHUtils randomColors]];
}

+ (NSColor *)randomColor
Expand Down Expand Up @@ -81,6 +81,17 @@ + (void)openUrl:(NSString *)url
NOTIFICATION_POST(kNotifyWindowShouldHide);
}

+ (void)openURL:(NSURL *)url
{
if (url.absoluteString.length == 0)
{
return;
}
MUST_IN_MAIN_THREAD;
[[NSWorkspace sharedWorkspace] openURL:url];
NOTIFICATION_POST(kNotifyWindowShouldHide);
}

+ (void)resetWKWebViewExceptCookie
{
NSSet *websiteDataTypes = [NSSet setWithArray:@[
Expand Down Expand Up @@ -125,19 +136,30 @@ + (void)scrollViewToTop:(NSScrollView *)scrollView
[scrollView.documentView scrollPoint:NSMakePoint(0, 0)];
}

+ (NSArray<NSColor *> *)randomColors
{
NSMutableArray<NSColor *> *mColors = [NSMutableArray arrayWithCapacity:[self colors].count];
NSUInteger index = arc4random_uniform((int)[self colors].count);
for (int i = 0; i < [self colors].count; i++)
{
[mColors addObject:[colors objectAtIndex:(index + i) % colors.count]];
}
return [mColors copy];
}

#pragma mark - Private methods

+ (NSArray<NSString *> *)colorStrings
{
if (colorStrings == nil)
{
colorStrings = @[@"#F44336",
@"#3F51B5",
@"#673AB7",
@"#E91E63",
@"#9C27B0",
@"#03A9F4",
@"#009688",
@"#3F51B5",
@"#4CAF50",
@"#00BCD4",
@"#2196F3",
Expand Down
Loading

0 comments on commit 07754f7

Please sign in to comment.