This repository has been archived by the owner on Apr 3, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
deflector.d
69 lines (57 loc) · 2.24 KB
/
deflector.d
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
module deflector;
import common;
import std.uri: decodeComponent;
import std.conv: to;
version (free_version) {
import core.thread: Thread;
import core.time: seconds;
}
debug {
import core.stdc.stdio: getchar;
import std.stdio: writeln;
}
void main(string[] args) {
if (args.length <= 1) {
createErrorDialog(new Exception("Expected one URI argument, recieved: \n" ~ args.to!string()));
return;
}
const auto searchInfo = getSearchInfo(args[1]);
debug {
writeln("\nInitial launch URI:\n\t" ~ args[1] ~ "\n");
debug writeln("Decoded search information:");
debug writeln("Search Term: " ~ searchInfo.searchTerm);
debug writeln("Entered URL: " ~ searchInfo.enteredUrl);
debug writeln("Selected URL: " ~ searchInfo.selectedUrl);
}
try {
const string browserArgs = getBrowserArgs(
DeflectorSettings.browserPath,
DeflectorSettings.useProfile,
DeflectorSettings.profileName
);
string launchUrl;
if (searchInfo.enteredUrl !is null)
launchUrl = searchInfo.enteredUrl;
else if (searchInfo.selectedUrl !is null)
launchUrl = searchInfo.selectedUrl;
else if (searchInfo.searchTerm)
if (searchInfo.searchTerm.decodeComponent() == "!DisableDonationRequest") {
DeflectorSettings.disableNag = true;
DeflectorSettings.dump();
} else
launchUrl = DeflectorSettings.engineURL.formatString(["query": searchInfo.searchTerm]);
else
throw new Exception("There was an error deflecting your search. Passed URI is:\t" ~ args[1]);
openUri(DeflectorSettings.browserPath, browserArgs, launchUrl);
version (free_version) // Makes the donation prompt open on the 10th search and every 20 afterward
if ((!DeflectorSettings.disableNag && (DeflectorSettings.searchCount - 10) % 20 == 0)
|| DeflectorSettings.searchCount == 10) {
Thread.sleep(seconds(5));
openUri(DeflectorSettings.browserPath, browserArgs, WIKI_THANKS_URL);
}
} catch (Exception error) {
createErrorDialog(error);
debug writeln(error);
}
debug getchar();
}