Skip to content
This repository was archived by the owner on Mar 11, 2024. It is now read-only.

Commit b9344b9

Browse files
committedNov 7, 2018
Manual/Auto inject mode?
1 parent 2d5f47c commit b9344b9

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed
 

‎InjectionIII.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
BB439B801FABA64300B4F50B /* SwiftEvalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB439B7F1FABA64300B4F50B /* SwiftEvalTests.swift */; };
1111
BB56393C1FD5C25A002FFCEF /* SignerService.m in Sources */ = {isa = PBXBuildFile; fileRef = BB67DBB61FB0D0F2000EAC8A /* SignerService.m */; };
1212
BB6306FE1FCD1A410021D30C /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = BB6306FD1FCD1A410021D30C /* Credits.rtf */; };
13+
BB877CE42186EB6E0070EEC7 /* DDHotKeyCenter.m in Sources */ = {isa = PBXBuildFile; fileRef = BB6306F51FCD16600021D30C /* DDHotKeyCenter.m */; };
14+
BB877CE52186EB6E0070EEC7 /* DDHotKeyUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = BB6306F61FCD16600021D30C /* DDHotKeyUtilities.m */; };
1315
BBB040641FB17A6C007DDD0A /* ScriptingBridge.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BBB040631FB1798A007DDD0A /* ScriptingBridge.framework */; };
1416
BBB64DC51FD450AF0020BE47 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = BB037DF31FAD808B004B267C /* README.md */; };
1517
BBB64DC61FD450B40020BE47 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = BB037DF41FAD80D0004B267C /* LICENSE */; };
@@ -606,6 +608,8 @@
606608
isa = PBXSourcesBuildPhase;
607609
buildActionMask = 2147483647;
608610
files = (
611+
BB877CE42186EB6E0070EEC7 /* DDHotKeyCenter.m in Sources */,
612+
BB877CE52186EB6E0070EEC7 /* DDHotKeyUtilities.m in Sources */,
609613
BBB64FEA1FD583B60020BE47 /* Xprobe.mm in Sources */,
610614
BBB64DD31FD56F570020BE47 /* XprobePluginMenuController.m in Sources */,
611615
BBB64DD41FD56F570020BE47 /* XprobeConsole.m in Sources */,

‎InjectionIII/AppDelegate.mm

+4-7
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
//#import "HelperInstaller.h"
1414
//#import "HelperProxy.h"
1515

16-
//#import <Carbon/Carbon.h>
17-
//#import <AppKit/NSEvent.h>
18-
//#import "DDHotKeyCenter.h"
16+
#import <Carbon/Carbon.h>
17+
#import <AppKit/NSEvent.h>
18+
#import "DDHotKeyCenter.h"
1919

2020
#import "InjectionIII-Swift.h"
2121
#import "UserDefaults.h"
@@ -55,11 +55,9 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
5555
: NSControlStateValueOff;
5656

5757
[self setMenuIcon:@"InjectionIdle"];
58-
#if 0
5958
[[DDHotKeyCenter sharedHotKeyCenter] registerHotKeyWithKeyCode:kVK_ANSI_Equal
6059
modifierFlags:NSEventModifierFlagControl
6160
target:self action:@selector(autoInject:) object:nil];
62-
#endif
6361
}
6462

6563
- (IBAction)openProject:sender {
@@ -125,6 +123,7 @@ - (IBAction)toggleState:(NSMenuItem *)sender {
125123
}
126124

127125
- (IBAction)autoInject:(NSMenuItem *)sender {
126+
[self.lastConnection injectPending];
128127
#if 0
129128
NSError *error = nil;
130129
// Install helper tool
@@ -180,10 +179,8 @@ - (IBAction)donate:sender {
180179

181180
- (void)applicationWillTerminate:(NSNotification *)aNotification {
182181
// Insert code here to tear down your application
183-
#if 0
184182
[[DDHotKeyCenter sharedHotKeyCenter] unregisterHotKeyWithKeyCode:kVK_ANSI_Equal
185183
modifierFlags:NSEventModifierFlagControl];
186-
#endif
187184
}
188185

189186
@end

‎InjectionIII/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>1.2</string>
2121
<key>CFBundleVersion</key>
22-
<string>1335</string>
22+
<string>1355</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string>public.app-category.developer-tools</string>
2525
<key>LSMinimumSystemVersion</key>

‎InjectionIII/InjectionServer.h

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
@interface InjectionServer : SimpleSocket
1515

1616
- (void)setProject:(NSString *)project;
17+
- (void)injectPending;
1718

1819
@end
1920

‎InjectionIII/InjectionServer.mm

+19-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
@implementation InjectionServer {
2828
void (^injector)(NSArray *changed);
2929
FileWatcher *fileWatcher;
30+
NSMutableArray *pending;
3031
}
3132

3233
+ (int)error:(NSString *)message {
@@ -111,6 +112,7 @@ - (void)runInBackground {
111112

112113
[appDelegate setMenuIcon:@"InjectionOK"];
113114
appDelegate.lastConnection = self;
115+
pending = [NSMutableArray new];
114116

115117
auto inject = ^(NSString *swiftSource) {
116118
NSControlStateValue watcherState = appDelegate.enableWatcher.state;
@@ -157,7 +159,6 @@ - (void)runInBackground {
157159
NSMutableDictionary<NSString *, NSArray *> *testCache = [NSMutableDictionary new];
158160

159161
injector = ^(NSArray *changed) {
160-
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
161162
NSMutableArray *changedFiles = [NSMutableArray arrayWithArray:changed];
162163

163164
if ([[NSUserDefaults standardUserDefaults] boolForKey:UserDefaultsTDDEnabled]) {
@@ -170,11 +171,16 @@ - (void)runInBackground {
170171
}
171172
}
172173

174+
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
173175
for (NSString *swiftSource in changedFiles)
174-
if (now > lastInjected[swiftSource].doubleValue + MIN_INJECTION_INTERVAL && now > pause) {
175-
lastInjected[swiftSource] = [NSNumber numberWithDouble:now];
176-
inject(swiftSource);
177-
}
176+
if (![pending containsObject:swiftSource])
177+
if (now > lastInjected[swiftSource].doubleValue + MIN_INJECTION_INTERVAL && now > pause) {
178+
lastInjected[swiftSource] = [NSNumber numberWithDouble:now];
179+
[pending addObject:swiftSource];
180+
}
181+
182+
if (appDelegate.enableWatcher.state == NSControlStateValueOn)
183+
[self injectPending];
178184
};
179185

180186
[self setProject:projectFile];
@@ -217,6 +223,14 @@ - (void)runInBackground {
217223
[appDelegate setMenuIcon:@"InjectionIdle"];
218224
}
219225

226+
- (void)injectPending {
227+
for (NSString *swiftSource in pending)
228+
dispatch_async(injectionQueue, ^{
229+
[self writeCommand:InjectionInject withString:swiftSource];
230+
});
231+
[pending removeAllObjects];
232+
}
233+
220234
- (void)setProject:(NSString *)project {
221235
if (!injector) return;
222236
[self writeCommand:InjectionProject withString:project];

0 commit comments

Comments
 (0)
This repository has been archived.