forked from firecore/Seas0nPass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSPFWButton.m
119 lines (91 loc) · 3.51 KB
/
SPFWButton.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//
// SPFWButton.m
// tetherKit
//
// Created by Kevin Bradley on 1/18/11.
// Copyright 2011 FireCore, LLC. All rights reserved.
//
#import "SPFWButton.h"
#import "tetherKitAppDelegate.h"
@implementation SPFWButton
- (void)mouseDown:(NSEvent *)theEvent
{
//NSLog(@"mouseDown: %i", [theEvent modifierFlags]);
if ([theEvent modifierFlags] == 262401){
NSPoint locationInWindow = [theEvent locationInWindow];
[self showMenu:locationInWindow];
}
[super mouseDown:theEvent];
}
- (void)rightMouseDown:(NSEvent *)theEvent
{
//NSLog(@"rightMouseDown: %@", theEvent);
NSPoint locationInWindow = [theEvent locationInWindow];
//NSLog(@"nsPoint: %@", NSStringFromPoint(locationInWindow));
[self showMenu:locationInWindow];
return [super rightMouseDown:theEvent];
}
- (IBAction)restoreLatest:(id)sender
{
[[NSApp delegate] itunesRestore:sender];
}
- (IBAction)saveSignatures:(id)sender
{
[[NSApp delegate] ifaithPayloadDump:sender];
}
- (IBAction)add:(id)sender
{
//NSLog(@"add: %@", [sender title]);
//[[NSUserDefaults standardUserDefaults] setObject:[sender title] forKey:@"lastUsedBundle"];
[[NSApp delegate] downloadBundle:[sender title]];
}
- (void)showMenu:(NSPoint)thePoint
{
NSGraphicsContext *theContext = [[self window] graphicsContext];
NSUInteger windowNumber = [[self window] windowNumber];
//NSRect frame = [(NSButton *)self frame];
// NSPoint menuOrigin = [[(NSButton *)self superview] convertPoint:NSMakePoint(frame.origin.x+10, frame.origin.y+20) toView:nil];
NSEvent *event = [NSEvent mouseEventWithType:NSRightMouseDown
location:thePoint
modifierFlags:NSRightMouseDownMask // 0x100
timestamp:0
windowNumber:windowNumber
context:theContext
eventNumber:0
clickCount:1
pressure:1];
NSArray *appBundles = [tetherKitAppDelegate filteredBundleNames];
//NSLog(@"appBundles: %@", appBundles);
NSEnumerator *bundleEnum = [appBundles objectEnumerator];
id currentObject = nil;
int i = 4;
NSMenu *menu = [[NSMenu alloc] init];
NSMenuItem *restoreLatest = [[NSMenuItem alloc] initWithTitle:@"Restore latest version in iTunes" action:@selector(restoreLatest:) keyEquivalent:@""];
NSMenuItem *saveSignatures = [[NSMenuItem alloc] initWithTitle:@"Save firmware signatures..." action:@selector(saveSignatures:) keyEquivalent:@""];
BOOL hasFirmware = [nitoUtility hasFirmware];
if (hasFirmware == TRUE)
{
// NSLog(@"has firmware!!!!!");
} else {
[restoreLatest setEnabled:FALSE];
[restoreLatest setAction:nil];
}
[menu insertItem:[restoreLatest autorelease] atIndex:0];
//[restoreLatest setEnabled:hasFirmware];
//[menu insertItemWithTitle:@"Restore latest version in iTunes" action:@selector(restoreLatest:) keyEquivalent:@"" atIndex:0];
NSMenuItem *dividerItem = [NSMenuItem separatorItem];
[menu insertItem:dividerItem atIndex:1];
[menu insertItem:[saveSignatures autorelease] atIndex:2];
[menu insertItem:[NSMenuItem separatorItem] atIndex:3];
while (currentObject = [bundleEnum nextObject])
{
// NSLog(@"addObject: %@", currentObject);
[menu insertItemWithTitle:currentObject
action:@selector(add:)
keyEquivalent:@""
atIndex:i];
i++;
}
[NSMenu popUpContextMenu:[menu autorelease] withEvent:event forView:(NSButton *)self];
}
@end