Skip to content

Commit ce7ca4c

Browse files
committed
2 parents fee59cc + 8266cae commit ce7ca4c

File tree

6 files changed

+188
-117
lines changed

6 files changed

+188
-117
lines changed
3.06 MB
Binary file not shown.
Binary file not shown.
Lines changed: 21 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Net.Http;
4-
using System.Net.Http.Headers;
5-
using System.Threading.Tasks;
62

73
namespace AssistantComputerControl {
84
class AnalyticsSettings {
9-
const string sendDataUrl = "https://acc.albe.pw/api/ReceiveAnalyticsData.php";
10-
const string sendSharingUrl = "https://acc.albe.pw/api/IsSharing.php";
11-
public const string sentryToken = "https://[email protected]/1287269";
12-
private static readonly HttpClient client = new HttpClient();
5+
//ACC truly is open source, but for security reasons we will not share this one file with the whole world.
6+
//This file handles sending analytics to the developers' webserver and contains a few variables that contain -
7+
//sensitive access-tokens to integrations like Sentry.IO
8+
9+
//The public version of this file is exactly like the full version, but stripped of -
10+
//API-keys and sensitive information.
11+
//Cencored items have placeholders to ensure that everyone can fork and run the project without errors
12+
public const string sentryToken = "super_secret";
1313

1414
public static readonly string[] actions = new String[] { //No changing this order!
1515
"shutdown", //0
@@ -43,31 +43,13 @@ class AnalyticsSettings {
4343
"unknown",
4444
};
4545

46-
public static void UpdateSharing(bool doShare) {
47-
Properties.Settings.Default.SendAnonymousAnalytics = doShare;
48-
Properties.Settings.Default.Save();
49-
50-
//Notify server whether
51-
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", @"jmF}AXK6NH!#{@/:ZHV#qK6r#YxytM>K/W6#5q/}tEK!&*_Gd\_YNUBNN/$a+$r");
52-
53-
var parameters = new Dictionary<string, string> {
54-
["uid"] = Properties.Settings.Default.UID,
55-
["share"] = doShare ? "true" : "false"
56-
};
57-
58-
try {
59-
var response = client.PostAsync(sendSharingUrl, new FormUrlEncodedContent(parameters)).Result;
60-
var contents = response.Content.ReadAsStringAsync().Result;
61-
MainProgram.DoDebug("Posted user response");
62-
} catch (Exception e) {
63-
MainProgram.DoDebug("Failed to send analytics data - something wrong with the server?");
64-
MainProgram.DoDebug(e.ToString());
65-
}
66-
67-
SetupAnalytics();
46+
class KeyHandler {
47+
public bool Status { get; set; }
48+
public string Message { get; set; }
49+
public string Key { get; set; }
6850
}
6951

70-
public static void SetupAnalytics() {
52+
public static void SetupAnalyticsAsync() {
7153
//Unique user-ID
7254
if (Properties.Settings.Default.UID == "" || Properties.Settings.Default.UID == null) {
7355
string newUID = Guid.NewGuid().ToString("N");
@@ -113,22 +95,11 @@ public static void SetupAnalytics() {
11395
Properties.Settings.Default.Save();
11496
}
11597

116-
DateTime dateTime = DateTime.UtcNow.Date;
117-
string thisDay = dateTime.ToString("yyyy/MM/dd");
118-
if (Properties.Settings.Default.AnalyticsUnsentData && Properties.Settings.Default.AnalyticsThisDay == thisDay) {
119-
//Resume data for today
120-
ScheduleAnalyticsSend();
121-
} else if (Properties.Settings.Default.AnalyticsUnsentData && Properties.Settings.Default.AnalyticsThisDay != thisDay) {
122-
//Didn't send last time - sending now
123-
SendAnalyticsData();
124-
}
125-
12698
MainProgram.DoDebug("Annonymous analytics setup done");
12799
} else {
128100
MainProgram.DoDebug("Annonymous analytics are not being shared");
129101
}
130102
}
131-
132103
public static void PrintAnalytics() {
133104
int i = 0
134105
, totalCount = 0;
@@ -149,30 +120,18 @@ public static void AddCount(string action, string type) {
149120
int pos = Array.IndexOf(actions, action);
150121
if (pos > -1) {
151122
//MainProgram.DoDebug("Added +1 to " + action + " at pos " + pos);
152-
if (Properties.Settings.Default.TotalActionsExecuted.Length >= pos) {
153-
Properties.Settings.Default.TotalActionsExecuted[pos]++;
154-
155-
if (!Properties.Settings.Default.AnalyticsUnsentData) {
156-
Properties.Settings.Default.AnalyticsUnsentData = true;
157-
ScheduleAnalyticsSend();
158-
}
159-
Properties.Settings.Default.Save();
160-
} else {
161-
MainProgram.DoDebug("Index " + pos.ToString() + " exceeds 'TotalActionsExecuted' property, which has length; " + Properties.Settings.Default.TotalActionsExecuted.Length.ToString());
162-
}
123+
Properties.Settings.Default.TotalActionsExecuted[pos]++;
124+
Properties.Settings.Default.Save();
163125
} else {
164126
MainProgram.DoDebug("Could not find action \"" + action + "\" in action-array (analytics)");
165127
}
128+
129+
SendAnalyticsData();
166130
}
167131
public static void AddCount(int action, string type) {
168132
AddTypeCount(type);
169133
if (actions[action] != null) {
170134
Properties.Settings.Default.TotalActionsExecuted[action]++;
171-
172-
if (!Properties.Settings.Default.AnalyticsUnsentData) {
173-
Properties.Settings.Default.AnalyticsUnsentData = true;
174-
ScheduleAnalyticsSend();
175-
}
176135
Properties.Settings.Default.Save();
177136
} else {
178137
MainProgram.DoDebug("Could not find action with index \"" + action + "\" in action-array (analytics)");
@@ -194,67 +153,14 @@ private static void AddTypeCount(string type) {
194153
}
195154
}
196155

197-
static void ScheduleAnalyticsSend() {
198-
//Time when method needs to be called
199-
MainProgram.DoDebug("Analytics scheduled to be sent at 00:00");
200-
201-
DateTime dateTime = DateTime.UtcNow.Date;
202-
Properties.Settings.Default.AnalyticsThisDay = dateTime.ToString("yyyy/MM/dd");
203-
Properties.Settings.Default.Save();
204-
205-
var DailyTime = "00:00:00";
206-
var timeParts = DailyTime.Split(new char[1] { ':' });
207-
208-
var dateNow = DateTime.Now;
209-
var date = new DateTime(dateNow.Year, dateNow.Month, dateNow.Day,
210-
int.Parse(timeParts[0]), int.Parse(timeParts[1]), int.Parse(timeParts[2]));
211-
TimeSpan ts;
212-
if (date > dateNow)
213-
ts = date - dateNow;
214-
else {
215-
date = date.AddDays(1);
216-
ts = date - dateNow;
217-
}
218-
219-
Task.Delay(ts).ContinueWith((x) => SendAnalyticsData());
220-
}
221-
222156
public static string SendAnalyticsData() {
157+
//Sends analytics data to the server
223158
if (Properties.Settings.Default.SendAnonymousAnalytics) {
224-
if (MainProgram.HasInternet()) {
225-
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", @"jmF}AXK6NH!#{@/:ZHV#qK6r#YxytM>K/W6#5q/}tEK!&*_Gd\_YNUBNN/$a+$r");
226-
227-
var parameters = new Dictionary<string, string> {
228-
["uid"] = Properties.Settings.Default.UID,
229-
["actions"] = string.Join(",", Properties.Settings.Default.TotalActionsExecuted),
230-
["assistants"] = string.Join(",", Properties.Settings.Default.AssistantType),
231-
["start_with_windows"] = Properties.Settings.Default.StartWithWindows ? "true" : "false",
232-
["version"] = MainProgram.softwareVersion,
233-
["beta_program"] = Properties.Settings.Default.BetaProgram ? "true" : "false",
234-
["date"] = Properties.Settings.Default.AnalyticsThisDay
235-
};
236-
237-
try {
238-
var response = client.PostAsync(sendDataUrl, new FormUrlEncodedContent(parameters)).Result;
239-
var contents = response.Content.ReadAsStringAsync().Result;
240-
241-
//Success
242-
Properties.Settings.Default.AnalyticsUnsentData = false;
243-
Properties.Settings.Default.Save();
244-
MainProgram.DoDebug("Analytics successfully posted");
245-
return contents;
246-
} catch (Exception e) {
247-
MainProgram.DoDebug("Failed to send analytics data - something wrong with the server?");
248-
MainProgram.DoDebug(e.ToString());
249-
return "";
250-
}
251-
} else {
252-
MainProgram.DoDebug("Failed to send analytics data; no internet connection");
253-
return "";
254-
}
159+
//Do it (sensitive code)
255160
} else {
256-
return "";
161+
//Don't do it (does nothing here)
257162
}
163+
return "";
258164
}
259165
}
260166
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Runtime.InteropServices;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace AssistantComputerControl {
9+
public static class FlashWindow {
10+
[DllImport("user32.dll")]
11+
[return: MarshalAs(UnmanagedType.Bool)]
12+
private static extern bool FlashWindowEx(ref FLASHWINFO pwfi);
13+
14+
[StructLayout(LayoutKind.Sequential)]
15+
private struct FLASHWINFO {
16+
/// <summary>
17+
/// The size of the structure in bytes.
18+
/// </summary>
19+
public uint cbSize;
20+
/// <summary>
21+
/// A Handle to the Window to be Flashed. The window can be either opened or minimized.
22+
/// </summary>
23+
public IntPtr hwnd;
24+
/// <summary>
25+
/// The Flash Status.
26+
/// </summary>
27+
public uint dwFlags;
28+
/// <summary>
29+
/// The number of times to Flash the window.
30+
/// </summary>
31+
public uint uCount;
32+
/// <summary>
33+
/// The rate at which the Window is to be flashed, in milliseconds. If Zero, the function uses the default cursor blink rate.
34+
/// </summary>
35+
public uint dwTimeout;
36+
}
37+
38+
/// <summary>
39+
/// Stop flashing. The system restores the window to its original stae.
40+
/// </summary>
41+
public const uint FLASHW_STOP = 0;
42+
43+
/// <summary>
44+
/// Flash the window caption.
45+
/// </summary>
46+
public const uint FLASHW_CAPTION = 1;
47+
48+
/// <summary>
49+
/// Flash the taskbar button.
50+
/// </summary>
51+
public const uint FLASHW_TRAY = 2;
52+
53+
/// <summary>
54+
/// Flash both the window caption and taskbar button.
55+
/// This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
56+
/// </summary>
57+
public const uint FLASHW_ALL = 3;
58+
59+
/// <summary>
60+
/// Flash continuously, until the FLASHW_STOP flag is set.
61+
/// </summary>
62+
public const uint FLASHW_TIMER = 4;
63+
64+
/// <summary>
65+
/// Flash continuously until the window comes to the foreground.
66+
/// </summary>
67+
public const uint FLASHW_TIMERNOFG = 12;
68+
69+
70+
/// <summary>
71+
/// Flash the spacified Window (Form) until it recieves focus.
72+
/// </summary>
73+
/// <param name="form">The Form (Window) to Flash.</param>
74+
/// <returns></returns>
75+
public static bool Flash(System.Windows.Forms.Form form) {
76+
// Make sure we're running under Windows 2000 or later
77+
if (Win2000OrLater) {
78+
FLASHWINFO fi = Create_FLASHWINFO(form.Handle, FLASHW_ALL | FLASHW_TIMERNOFG, uint.MaxValue, 0);
79+
return FlashWindowEx(ref fi);
80+
}
81+
return false;
82+
}
83+
84+
private static FLASHWINFO Create_FLASHWINFO(IntPtr handle, uint flags, uint count, uint timeout) {
85+
FLASHWINFO fi = new FLASHWINFO();
86+
fi.cbSize = Convert.ToUInt32(Marshal.SizeOf(fi));
87+
fi.hwnd = handle;
88+
fi.dwFlags = flags;
89+
fi.uCount = count;
90+
fi.dwTimeout = timeout;
91+
return fi;
92+
}
93+
94+
/// <summary>
95+
/// Flash the specified Window (form) for the specified number of times
96+
/// </summary>
97+
/// <param name="form">The Form (Window) to Flash.</param>
98+
/// <param name="count">The number of times to Flash.</param>
99+
/// <returns></returns>
100+
public static bool Flash(System.Windows.Forms.Form form, uint count) {
101+
if (Win2000OrLater) {
102+
FLASHWINFO fi = Create_FLASHWINFO(form.Handle, FLASHW_ALL, count, 0);
103+
return FlashWindowEx(ref fi);
104+
}
105+
return false;
106+
}
107+
108+
/// <summary>
109+
/// Start Flashing the specified Window (form)
110+
/// </summary>
111+
/// <param name="form">The Form (Window) to Flash.</param>
112+
/// <returns></returns>
113+
public static bool Start(System.Windows.Forms.Form form) {
114+
if (Win2000OrLater) {
115+
FLASHWINFO fi = Create_FLASHWINFO(form.Handle, FLASHW_ALL, uint.MaxValue, 0);
116+
return FlashWindowEx(ref fi);
117+
}
118+
return false;
119+
}
120+
121+
/// <summary>
122+
/// Stop Flashing the specified Window (form)
123+
/// </summary>
124+
/// <param name="form"></param>
125+
/// <returns></returns>
126+
public static bool Stop(System.Windows.Forms.Form form) {
127+
if (Win2000OrLater) {
128+
FLASHWINFO fi = Create_FLASHWINFO(form.Handle, FLASHW_STOP, uint.MaxValue, 0);
129+
return FlashWindowEx(ref fi);
130+
}
131+
return false;
132+
}
133+
134+
/// <summary>
135+
/// A boolean value indicating whether the application is running on Windows 2000 or later.
136+
/// </summary>
137+
private static bool Win2000OrLater {
138+
get { return System.Environment.OSVersion.Version.Major >= 5; }
139+
}
140+
}
141+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Albert Møller Nielsen
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# AssistantComputerControl
22
Control your computer using your **Google Home**, **Amazon Alexa** and **Microsoft Cortana** assistants!
33

4+
_The git repository is currently not up to date. Having merging issues. Download from [acc.albe.pw](https://acc.albe.pw/)_
5+
46
This is a simple but powerful tool that allows you to perform tasks on your Windows computer like;
57
### Supported computer actions
8+
* **Full and better list of what ACC can do [can be found here](https://acc.albe.pw/#what-can-it-do)**
69
* Shutdown [[GH](https://ifttt.com/applets/W3b7fykE-acc-shut-down-computer)][[Alexa](https://ifttt.com/applets/pCPWA7je-acc-shut-down-computer)]
7-
* Open a file [[GH](https://ifttt.com/applets/Pny8DKBL-acc-open-file-example)][[Alexa](https://ifttt.com/applets/EsP6zWpe-acc-open-file-example)]
10+
* Open a file (or multiple) [[GH](https://ifttt.com/applets/Pny8DKBL-acc-open-file-example)][[Alexa](https://ifttt.com/applets/EsP6zWpe-acc-open-file-example)]
811
* Restart [[GH](https://ifttt.com/applets/nsvdVxZ9-acc-restart-computer)][[Alexa](https://ifttt.com/applets/kkwxdE9T-acc-restart-computer)]
912
* Sleep / Hibernate [[GH](https://ifttt.com/applets/mEbJCP8F-acc-sleep-computer)][[Alexa](https://ifttt.com/applets/Kagf93wH-acc-sleep-computer)]
1013
* Lock [[GH](https://ifttt.com/applets/epbqzfCa-acc-lock-computer)][[Alexa](https://ifttt.com/applets/Gv9Ts8ip-acc-lock-computer)]
@@ -23,7 +26,7 @@ This is a simple but powerful tool that allows you to perform tasks on your Wind
2326
This software only works on Windows and has yet only been tested on Windows 10, 8 & 7.
2427

2528
## Install
26-
Setting up AssistantComputerControl is a _piece of cake!_ It only takes about 2 minutes. You just [download the latest version](http://acc.albe.pw/download_latest.php?ref=https://github.com/AlbertMN/AssistantComputerControl) to your computer, open it and the setup guide will take you through the very short setup guide!
29+
Setting up AssistantComputerControl is a _piece of cake!_ It only takes about 2 minutes. You just [download the latest version](http://acc.albe.pw/) to your computer, open it and the setup guide will take you through the very short setup guide!
2730

2831
_Note: [IFTTT](https://ifttt.com/) and a [Dropbox](https://www.dropbox.com/) account is required for the default setup. Dropbox will need to be running at all times for ACC to work_
2932

0 commit comments

Comments
 (0)