Skip to content

Commit

Permalink
wired core updated to 2.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
nark committed May 12, 2020
1 parent 7b5c8d5 commit 413f1df
Show file tree
Hide file tree
Showing 23 changed files with 1,279 additions and 1,477 deletions.
16 changes: 9 additions & 7 deletions Wired Server/WPExportManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ - (BOOL)importFromFile:(NSString *)file error:(WPError **)error {
}

files = [NSDictionary dictionaryWithObjectsAndKeys:
@"etc/wired.conf", WPExportManagerConfig,
@"etc/wired.conf", WPExportManagerConfig,
@"banner.png", WPExportManagerBanner,
@"database.sqlite3", WPExportManagerDatabase,
NULL];
Expand All @@ -178,22 +178,24 @@ - (BOOL)importFromFile:(NSString *)file error:(WPError **)error {
return NO;
}
}

data = [dictionary objectForKey:key];

if(!data)
continue;

zipfile = [NSFileManager temporaryPathWithPrefix:@"WiredSettings"];

if(![data writeToFile:zipfile options:0 error:error])
return NO;

task = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/unzip"
arguments:[NSArray arrayWithObjects:
@"-o",
zipfile,
NULL]];
@"-o",
zipfile,
@"-d",
[_wiredManager rootPath],
NULL]];

[task waitUntilExit];

Expand Down
55 changes: 33 additions & 22 deletions Wired Server/WSSettingsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ - (void)windowDidLoad {
url = [[NSBundle mainBundle] URLForResource:@"Wired Server Helper" withExtension:@"app"];

if([[WISettings settings] boolForKey:WPEnableMenuItem]) {
if(![WIStatusMenuManager isHelperRunning]) {
if(![WIStatusMenuManager isHelperRunning:WPHelperBundleID]) {
[WIStatusMenuManager startHelper:url];
}
}
Expand Down Expand Up @@ -283,9 +283,9 @@ - (void)awakeFromNib {
#pragma mark -

- (void)wiredStatusDidChange:(NSNotification *)notification {

[self _updateSettings];
[self _updateRunningStatus];

if([_wiredManager isRunning]) {
if ([[_hostTextField stringValue] length]==0){
[self loadInfo];
Expand All @@ -302,18 +302,19 @@ - (void)wiredStatusDidChange:(NSNotification *)notification {
}

- (void)saveInfo {

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if ([[_hostTextField stringValue] length] ==0) {

if ([[_hostTextField stringValue] length] == 0) {
[_hostTextField setStringValue:@"127.0.0.1"];
}

[prefs setObject:[_hostTextField stringValue] forKey:@"Host"];
[prefs synchronize];
}

- (void)loadInfo {

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

if ([[defaults objectForKey:@"Host"] length]!=0)
[_hostTextField setStringValue:[defaults stringForKey:@"Host"]];
else
Expand Down Expand Up @@ -695,14 +696,17 @@ - (IBAction)exportSettings:(id)sender {
[_activityProgressIndicator startAnimation:self];
[_activityTextField setStringValue:@"Export Settings..."];

NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
NSLog(@"exportSettings : %@", [[savePanel URL] path]);

[self _exportToFile:[[savePanel URL] path]];
[NSThread sleepForTimeInterval:1.0];
[self.window performSelectorOnMainThread:@selector(endSheet:) withObject:_activityWindow];
}];
[_queue addOperation:operation];
NSString *path = [[savePanel URL] path];

dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
[self _exportToFile:path];

dispatch_async(dispatch_get_main_queue(), ^{
[NSThread sleepForTimeInterval:1.0];
[_activityWindow orderOut:self];
[self.window endSheet:_activityWindow];
});
});
}
}];
}
Expand Down Expand Up @@ -739,14 +743,17 @@ - (IBAction)importSettings:(id)sender {
[_activityProgressIndicator startAnimation:self];
[_activityTextField setStringValue:@"Import Settings..."];

NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
[self _importFromFile:[[openPanel URL] path]];
[NSThread sleepForTimeInterval:1.0];
[self.window performSelectorOnMainThread:@selector(endSheet:) withObject:_activityWindow];

}];
NSString *path = [[openPanel URL] path];

[_queue addOperation:operation];
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
[self _importFromFile:path];

dispatch_async(dispatch_get_main_queue(), ^{
[NSThread sleepForTimeInterval:1.0];
[_activityWindow orderOut:self];
[self.window endSheet:_activityWindow];
});
});
}
}];
} else {
Expand Down Expand Up @@ -1257,9 +1264,13 @@ - (void)_importFromFile:(NSString *)file {
WPError *error;

if([_exportManager importFromFile:file error:&error])
[self _updateSettings];
dispatch_async(dispatch_get_main_queue(), ^{
[self _updateSettings];
});
else
[[error alert] beginSheetModalForWindow:[_importSettingsButton window]];
dispatch_async(dispatch_get_main_queue(), ^{
[[error alert] beginSheetModalForWindow:[_importSettingsButton window]];
});
}


Expand Down
2 changes: 1 addition & 1 deletion WiredFrameworks/WiredAppKit/WIStatusMenuManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

+ (void) startHelper:(NSURL *)itemURL;
+ (void) stopHelper: (NSURL *)itemURL;
+ (BOOL) isHelperRunning;
+ (BOOL) isHelperRunning:(NSString *)bundleID;

@end
7 changes: 3 additions & 4 deletions WiredFrameworks/WiredAppKit/WIStatusMenuManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ + (void)stopHelper:(NSURL *)itemURL {
system("killall 'Wired Server Helper'");
}

+ (BOOL)isHelperRunning
{
+ (BOOL)isHelperRunning:(NSString *)bundleID {
BOOL result = NO;
NSArray *running = [NSRunningApplication runningApplicationsWithBundleIdentifier:@"fr.read-write.Wired-Server-Helper"];
NSArray *running = [NSRunningApplication runningApplicationsWithBundleIdentifier:bundleID];
if ([running count] > 0) {
result = YES;;
}
Expand All @@ -32,6 +31,6 @@ + (BOOL)isHelperRunning
+ (void) setStartAtLogin:(NSString *)bundleID enabled:(BOOL)enabled
{
SMLoginItemSetEnabled((__bridge CFStringRef)bundleID, enabled);
}
}

@end
Loading

0 comments on commit 413f1df

Please sign in to comment.