Skip to content

Commit bc48c96

Browse files
committed
Implemented the service install routine, including adding and removing the service from ~/Library/Services.
1 parent f5a8538 commit bc48c96

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

pushmenu/en.lproj/MainMenu.xib

+16-1
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,14 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes>
14631463
</object>
14641464
<int key="connectionID">680</int>
14651465
</object>
1466+
<object class="IBConnectionRecord">
1467+
<object class="IBOutletConnection" key="connection">
1468+
<string key="label">installService</string>
1469+
<reference key="source" ref="976324537"/>
1470+
<reference key="destination" ref="707982924"/>
1471+
</object>
1472+
<int key="connectionID">681</int>
1473+
</object>
14661474
</object>
14671475
<object class="IBMutableOrderedSet" key="objectRecords">
14681476
<object class="NSArray" key="orderedObjects">
@@ -2152,7 +2160,7 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes>
21522160
<reference key="dict.values" ref="0"/>
21532161
</object>
21542162
<nil key="sourceID"/>
2155-
<int key="maxID">680</int>
2163+
<int key="maxID">681</int>
21562164
</object>
21572165
<object class="IBClassDescriber" key="IBDocument.Classes">
21582166
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -2247,6 +2255,7 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes>
22472255
<string>ProwlApikey</string>
22482256
<string>aboutWindow</string>
22492257
<string>credits</string>
2258+
<string>installService</string>
22502259
<string>pmMenu</string>
22512260
<string>prefWindow</string>
22522261
<string>window</string>
@@ -2260,6 +2269,7 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes>
22602269
<string>NSTextField</string>
22612270
<string>NSWindow</string>
22622271
<string>NSTextView</string>
2272+
<string>NSButtonCell</string>
22632273
<string>NSMenu</string>
22642274
<string>NSWindow</string>
22652275
<string>NSWindow</string>
@@ -2276,6 +2286,7 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes>
22762286
<string>ProwlApikey</string>
22772287
<string>aboutWindow</string>
22782288
<string>credits</string>
2289+
<string>installService</string>
22792290
<string>pmMenu</string>
22802291
<string>prefWindow</string>
22812292
<string>window</string>
@@ -2310,6 +2321,10 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes>
23102321
<string key="name">credits</string>
23112322
<string key="candidateClassName">NSTextView</string>
23122323
</object>
2324+
<object class="IBToOneOutletInfo">
2325+
<string key="name">installService</string>
2326+
<string key="candidateClassName">NSButtonCell</string>
2327+
</object>
23132328
<object class="IBToOneOutletInfo">
23142329
<string key="name">pmMenu</string>
23152330
<string key="candidateClassName">NSMenu</string>

pushmenu/pushmenuAppDelegate.h

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
IBOutlet NSTextView *credits;
4343
IBOutlet NSWindow *prefWindow;
4444
IBOutlet NSWindow *aboutWindow;
45+
IBOutlet NSButtonCell *installService;
4546

4647
// Prowl
4748
IBOutlet NSTextField *ProwlApikey;

pushmenu/pushmenuAppDelegate.m

+12-7
Original file line numberDiff line numberDiff line change
@@ -604,17 +604,22 @@ - (id)performDefaultImplementation {
604604
// Install the services menu entry
605605
//////////////////////////////////////////////////
606606
- (void) installService:(id) sender {
607-
607+
608608
NSFileManager *FM = [NSFileManager defaultManager];
609-
NSString *destination;
610609
NSString *serviceFile = [[NSBundle mainBundle] pathForResource:@"SendtoiPhone"
611610
ofType:@"workflow"];
611+
NSString *destination = [@"~/Library/Services/SendtoiPhone.workflow" stringByExpandingTildeInPath];
612612

613-
destination = [@"~/Library/Services/SendtoiPhone.workflow" stringByExpandingTildeInPath];
614-
615-
if ([FM fileExistsAtPath:serviceFile])
616-
{
617-
[FM copyItemAtPath:serviceFile toPath:destination error:Nil];
613+
if ([installService state] == NSOnState) {
614+
if (![FM fileExistsAtPath:destination])
615+
{
616+
[FM copyItemAtPath:serviceFile toPath:destination error:Nil];
617+
}
618+
} else { // User turned the service off
619+
if ([FM fileExistsAtPath:destination])
620+
{
621+
[FM removeItemAtPath:destination error:Nil];
622+
}
618623
}
619624
}
620625
@end

0 commit comments

Comments
 (0)