Skip to content

Commit

Permalink
Enhancements: server commands now coded in pure objective-c instead o…
Browse files Browse the repository at this point in the history
…f relying on an external shell script; invalid server settings now highlighted individually in GUI; changing server startup does not affect running server; auto-startup when any users logs-in is now supported (previously only current user). Bug-fixes: server sometimes briefly showed Started status before switching back to Retrying.
  • Loading branch information
mckenfra committed Aug 28, 2015
1 parent dea2196 commit 99a482f
Show file tree
Hide file tree
Showing 25 changed files with 1,391 additions and 1,715 deletions.
20 changes: 16 additions & 4 deletions PostgreSQL.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
20079E771B48061100521807 /* PGPrefsPane.h in Headers */ = {isa = PBXBuildFile; fileRef = 20079E6D1B48061100521807 /* PGPrefsPane.h */; };
20079E781B48061100521807 /* PGPrefsPane.m in Sources */ = {isa = PBXBuildFile; fileRef = 20079E6E1B48061100521807 /* PGPrefsPane.m */; };
20079E791B48061100521807 /* Common.h in Headers */ = {isa = PBXBuildFile; fileRef = 20079E701B48061100521807 /* Common.h */; };
20079E8A1B4807E200521807 /* PGPrefsPostgreSQL.sh in Resources */ = {isa = PBXBuildFile; fileRef = 20079E871B4807E200521807 /* PGPrefsPostgreSQL.sh */; };
20079E8B1B4807E200521807 /* PGPrefsRunAsAdmin.applescript in Sources */ = {isa = PBXBuildFile; fileRef = 20079E881B4807E200521807 /* PGPrefsRunAsAdmin.applescript */; };
20079E981B48086300521807 /* checking.png in Resources */ = {isa = PBXBuildFile; fileRef = 20079E8D1B48086300521807 /* checking.png */; };
20079E991B48086300521807 /* elephant.png in Resources */ = {isa = PBXBuildFile; fileRef = 20079E8E1B48086300521807 /* elephant.png */; };
Expand Down Expand Up @@ -46,6 +45,10 @@
20BBC29814AD1E7600BA0859 /* README.pod in Resources */ = {isa = PBXBuildFile; fileRef = 20BBC29714AD1E7600BA0859 /* README.pod */; };
20BBC29A14AD201A00BA0859 /* README.pod.html in Resources */ = {isa = PBXBuildFile; fileRef = 20BBC29914AD201A00BA0859 /* README.pod.html */; };
20BCE7351B775450000AA376 /* ServiceManagement.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 20BCE7341B775450000AA376 /* ServiceManagement.framework */; };
20D192BC1B8E109000F75981 /* PGFile.h in Headers */ = {isa = PBXBuildFile; fileRef = 20D192BA1B8E109000F75981 /* PGFile.h */; };
20D192BD1B8E109000F75981 /* PGFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 20D192BB1B8E109000F75981 /* PGFile.m */; };
20D192C01B8FA3DA00F75981 /* PGRights.h in Headers */ = {isa = PBXBuildFile; fileRef = 20D192BE1B8FA3DA00F75981 /* PGRights.h */; };
20D192C11B8FA3DA00F75981 /* PGRights.m in Sources */ = {isa = PBXBuildFile; fileRef = 20D192BF1B8FA3DA00F75981 /* PGRights.m */; };
20E969821B51574600013B0E /* PGServerDataStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 20E969801B51574600013B0E /* PGServerDataStore.h */; };
20E969831B51574600013B0E /* PGServerDataStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 20E969811B51574600013B0E /* PGServerDataStore.m */; };
20E9698A1B51AEB900013B0E /* PGData.h in Headers */ = {isa = PBXBuildFile; fileRef = 20E969881B51AEB900013B0E /* PGData.h */; };
Expand All @@ -59,7 +62,6 @@
20079E6D1B48061100521807 /* PGPrefsPane.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGPrefsPane.h; sourceTree = "<group>"; };
20079E6E1B48061100521807 /* PGPrefsPane.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGPrefsPane.m; sourceTree = "<group>"; };
20079E701B48061100521807 /* Common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Common.h; sourceTree = "<group>"; };
20079E871B4807E200521807 /* PGPrefsPostgreSQL.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = PGPrefsPostgreSQL.sh; sourceTree = "<group>"; };
20079E881B4807E200521807 /* PGPrefsRunAsAdmin.applescript */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.applescript; path = PGPrefsRunAsAdmin.applescript; sourceTree = "<group>"; };
20079E8D1B48086300521807 /* checking.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = checking.png; sourceTree = "<group>"; };
20079E8E1B48086300521807 /* elephant.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = elephant.png; sourceTree = "<group>"; };
Expand Down Expand Up @@ -102,6 +104,10 @@
20BBC29714AD1E7600BA0859 /* README.pod */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.pod; sourceTree = SOURCE_ROOT; };
20BBC29914AD201A00BA0859 /* README.pod.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = README.pod.html; sourceTree = "<group>"; };
20BCE7341B775450000AA376 /* ServiceManagement.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ServiceManagement.framework; path = System/Library/Frameworks/ServiceManagement.framework; sourceTree = SDKROOT; };
20D192BA1B8E109000F75981 /* PGFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGFile.h; sourceTree = "<group>"; };
20D192BB1B8E109000F75981 /* PGFile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGFile.m; sourceTree = "<group>"; };
20D192BE1B8FA3DA00F75981 /* PGRights.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGRights.h; sourceTree = "<group>"; };
20D192BF1B8FA3DA00F75981 /* PGRights.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGRights.m; sourceTree = "<group>"; };
20E969801B51574600013B0E /* PGServerDataStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGServerDataStore.h; sourceTree = "<group>"; };
20E969811B51574600013B0E /* PGServerDataStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGServerDataStore.m; sourceTree = "<group>"; };
20E969881B51AEB900013B0E /* PGData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGData.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -154,18 +160,21 @@
201A6A7C1B5C2F3F005B691B /* Debug.h */,
20E969881B51AEB900013B0E /* PGData.h */,
20E969891B51AEB900013B0E /* PGData.m */,
20D192BA1B8E109000F75981 /* PGFile.h */,
20D192BB1B8E109000F75981 /* PGFile.m */,
209E77841B60C38300E8AF69 /* PGLaunchd.h */,
209E77851B60C38300E8AF69 /* PGLaunchd.m */,
20B628C51B4973BE003F8557 /* PGProcess.h */,
20B628C61B4973BE003F8557 /* PGProcess.m */,
20D192BE1B8FA3DA00F75981 /* PGRights.h */,
20D192BF1B8FA3DA00F75981 /* PGRights.m */,
);
path = Utils;
sourceTree = "<group>";
};
20079E851B4807E200521807 /* Scripts */ = {
isa = PBXGroup;
children = (
20079E871B4807E200521807 /* PGPrefsPostgreSQL.sh */,
20079E881B4807E200521807 /* PGPrefsRunAsAdmin.applescript */,
);
path = Scripts;
Expand Down Expand Up @@ -268,9 +277,11 @@
20B628C11B495154003F8557 /* PGServer.h in Headers */,
20727F881B4C7971002BBCCC /* PGServerController.h in Headers */,
20079E771B48061100521807 /* PGPrefsPane.h in Headers */,
20D192BC1B8E109000F75981 /* PGFile.h in Headers */,
20079E751B48061100521807 /* PGPrefsController.h in Headers */,
20079E791B48061100521807 /* Common.h in Headers */,
209E77861B60C38300E8AF69 /* PGLaunchd.h in Headers */,
20D192C01B8FA3DA00F75981 /* PGRights.h in Headers */,
20E969821B51574600013B0E /* PGServerDataStore.h in Headers */,
2086E18F1B57B55800F2B292 /* PGSearchController.h in Headers */,
20E9698A1B51AEB900013B0E /* PGData.h in Headers */,
Expand Down Expand Up @@ -329,7 +340,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
20079E8A1B4807E200521807 /* PGPrefsPostgreSQL.sh in Resources */,
20079E9C1B48086300521807 /* refresh.png in Resources */,
20079EA21B48086300521807 /* stopped.png in Resources */,
20A43B401B5FF7F5000E7D8A /* stopping.png in Resources */,
Expand Down Expand Up @@ -369,12 +379,14 @@
files = (
20727F891B4C7971002BBCCC /* PGServerController.m in Sources */,
209E77871B60C38300E8AF69 /* PGLaunchd.m in Sources */,
20D192BD1B8E109000F75981 /* PGFile.m in Sources */,
20B628C21B495154003F8557 /* PGServer.m in Sources */,
2086E1901B57B55800F2B292 /* PGSearchController.m in Sources */,
20079E8B1B4807E200521807 /* PGPrefsRunAsAdmin.applescript in Sources */,
20E969831B51574600013B0E /* PGServerDataStore.m in Sources */,
20E9698B1B51AEB900013B0E /* PGData.m in Sources */,
20B628C81B4973BE003F8557 /* PGProcess.m in Sources */,
20D192C11B8FA3DA00F75981 /* PGRights.m in Sources */,
20079E781B48061100521807 /* PGPrefsPane.m in Sources */,
20079E761B48061100521807 /* PGPrefsController.m in Sources */,
);
Expand Down
4 changes: 3 additions & 1 deletion PostgreSQL/Classes/PGPrefsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@
@property (nonatomic, strong, readonly) PGServer *server;
@property (nonatomic, strong, readonly) NSArray *servers;

/// The current authorization if authorized, or NULL if not authorized
@property (nonatomic, readonly) AuthorizationRef authorization;
- (AuthorizationRights *)authorizationRights;
/// The rights required to perform controller actions
- (PGRights *)rights;

- (id)initWithViewController:(id<PGPrefsViewController>)viewController;

Expand Down
38 changes: 21 additions & 17 deletions PostgreSQL/Classes/PGPrefsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ - (void)viewDidDeauthorize

self.authorization = nil;
}
- (AuthorizationRights *)authorizationRights
- (PGRights *)rights
{
return self.serverController.authorizationRights;
return self.serverController.rights;
}


Expand Down Expand Up @@ -202,11 +202,13 @@ - (BOOL)userCanRenameServer:(NSString *)name
}
- (void)userDidRenameServer:(NSString *)name
{
PGServer *server = self.server;
if (!server) return;

AuthorizationRef authorization = [self authorize];
if (!authorization) return;

PGServer *server = self.server;
PGServerAction finalAction = self.server.status == PGServerStarted ? PGServerStart : PGServerCreate;
PGServerAction finalAction = server.status == PGServerStarted || server.status == PGServerRetrying ? PGServerStart : PGServerCreate;
BackgroundThread(^{
// First stop and delete the existing server
[self.serverController runAction:PGServerDelete server:server authorization:authorization succeeded:^{
Expand All @@ -220,7 +222,7 @@ - (void)userDidRenameServer:(NSString *)name
BOOL succeeded = [self.serverController setName:newName forServer:server];

// Save
if (succeeded) succeeded = [self.dataStore saveServer:self.server];
if (succeeded) succeeded = [self.dataStore saveServer:server];

// Save failed - restore backup
if (!succeeded) {
Expand Down Expand Up @@ -327,9 +329,9 @@ - (void)userDidStartStopServer
PGServer *server = self.server;
BackgroundThread(^{
[self.serverController runAction:action server:server authorization:authorization succeeded:^{

[self checkStatus:server];

BackgroundThreadAfterDelay(0.2, ^{
[self checkStatus:server];
});
} failed:nil];
});

Expand Down Expand Up @@ -377,11 +379,13 @@ - (void)userDidRevertSettings
}
- (void)userDidApplySettings
{
PGServer *server = self.server;
if (server.external) return;

AuthorizationRef authorization = [self authorize];
if (!authorization) return;

PGServer *server = self.server;
PGServerAction finalAction = self.server.status == PGServerStarted || self.server.status == PGServerRetrying ? PGServerStart : PGServerCreate;
PGServerAction finalAction = server.status == PGServerStarted || server.status == PGServerRetrying ? PGServerStart : PGServerCreate;
BackgroundThread(^{
if (!server.dirtySettings) return;

Expand Down Expand Up @@ -422,15 +426,16 @@ - (void)userDidApplySettings
}
- (void)userDidChangeServerStartup:(NSString *)startup
{
PGServer *server = self.server;
if (server.external) return;

// Revert startup in GUI if user cancelled authorization
AuthorizationRef authorization = [self authorize];
if (!authorization) {
[self.viewController prefsController:self didRevertServerStartup:self.server];
[self.viewController prefsController:self didRevertServerStartup:server];
return;
}

PGServer *server = self.server;

// Backup existing
PGServerStartup oldStartup = server.settings.startup;
PGServerStartup newStartup = ToServerStartup(startup);
Expand All @@ -449,9 +454,8 @@ - (void)userDidChangeServerStartup:(NSString *)startup
}

// Run script
PGServerAction action = server.status == PGServerStarted || server.status == PGServerRetrying ? PGServerStart : PGServerCreate;
BackgroundThread(^{
[self.serverController runAction:action server:server authorization:authorization succeeded:^{
[self.serverController runAction:PGServerCreate server:server authorization:authorization succeeded:^{

[self checkStatus:server];

Expand Down Expand Up @@ -622,7 +626,7 @@ - (void)pollServer:(PGServer *)server key:(id)key
if (!PGPrefsMonitorServersEnabled) return;

// Schedule re-run
BackgroundThreadAfterDelay(^{ [self pollServer:server key:key]; }, PGServersPollTime);
BackgroundThreadAfterDelay(PGServersPollTime, ^{ [self pollServer:server key:key]; });
}
- (void)startMonitoringLaunchd
{
Expand All @@ -645,7 +649,7 @@ - (void)pollLaunchd:(id)key
if (!PGPrefsMonitorServersEnabled) return;

// Schedule re-run
BackgroundThreadAfterDelay(^{ [self pollLaunchd:key]; }, PGServersPollTime);
BackgroundThreadAfterDelay(PGServersPollTime, ^{ [self pollLaunchd:key]; });
};

// Find servers in launchd
Expand Down
12 changes: 10 additions & 2 deletions PostgreSQL/Classes/PGPrefsPane.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@
@property (weak) IBOutlet NSTextField *dataDirectoryField;
@property (weak) IBOutlet NSTextField *logFileField;
@property (weak) IBOutlet NSTextField *portField;
@property (weak) IBOutlet NSButton *revertSettingsButton;
@property (weak) IBOutlet NSButton *applySettingsButton;
@property (weak) IBOutlet NSImageView *invalidUsernameImage;
@property (weak) IBOutlet NSImageView *invalidBinDirectoryImage;
@property (weak) IBOutlet NSImageView *invalidDataDirectoryImage;
@property (weak) IBOutlet NSImageView *invalidLogFileImage;
@property (weak) IBOutlet NSImageView *invalidPortImage;
@property (weak) IBOutlet NSButton *revertSettingsButton;
@property (weak) IBOutlet NSButton *applySettingsButton;
@end


Expand Down Expand Up @@ -124,6 +127,11 @@
@property (weak) IBOutlet NSTextField *dataDirectoryField;
@property (weak) IBOutlet NSTextField *logFileField;
@property (weak) IBOutlet NSTextField *portField;
@property (weak) IBOutlet NSImageView *invalidUsernameImage;
@property (weak) IBOutlet NSImageView *invalidBinDirectoryImage;
@property (weak) IBOutlet NSImageView *invalidDataDirectoryImage;
@property (weak) IBOutlet NSImageView *invalidLogFileImage;
@property (weak) IBOutlet NSImageView *invalidPortImage;
@property (weak) IBOutlet NSMatrix *startupMatrix;
@property (weak) IBOutlet NSButtonCell *startupAtBootCell;
@property (weak) IBOutlet NSButtonCell *startupAtLoginCell;
Expand Down
Loading

0 comments on commit 99a482f

Please sign in to comment.