Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup Asteroids window #12

Merged
merged 108 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
ab06cfb
Update build.yml
eschan145 Dec 28, 2024
a79f322
Auto-build DLL files using g++
eschan145 Dec 28, 2024
0a91c2f
Setup asteroids files
eschan145 Dec 28, 2024
4a1e381
Rename WindowProc to TrayWindowProc
eschan145 Dec 28, 2024
6ada5b9
Auto-build DLL files using g++
eschan145 Dec 28, 2024
3c84682
Implement functionality for asteroids
eschan145 Dec 28, 2024
1335499
Missing include to `asteroids.h`
eschan145 Dec 28, 2024
2d1f9d0
Pass `running` as `std::ref`
eschan145 Dec 28, 2024
3af9db3
Remove redefinition
eschan145 Dec 28, 2024
53dea80
Fix mismatch in name
eschan145 Dec 28, 2024
7f53ca6
Reduce depth when fetching from GitHub
eschan145 Dec 28, 2024
92123f5
Remove redefinition
eschan145 Dec 28, 2024
0dd19b0
Implementation of `nid`
eschan145 Dec 28, 2024
5049097
Auto-build DLL files using g++
eschan145 Dec 28, 2024
f621375
Fix parameter name from `running` to `flag`
eschan145 Dec 28, 2024
6d007d9
Create menu for asteroids on right-click
eschan145 Dec 28, 2024
c89cc46
Suppress "-Wmissing-field-initializers"
eschan145 Dec 28, 2024
8ac27b7
Define `ID_TRAY_EXIT`
eschan145 Dec 28, 2024
a8bc4ab
Refactor asteroids into OOP class
eschan145 Dec 28, 2024
845349f
Fix several build errors
eschan145 Dec 28, 2024
a502a5c
Add missing declaration of `create()`
eschan145 Dec 28, 2024
e8b29f7
Fix missing parameter in declaration
eschan145 Dec 28, 2024
db7c37a
Auto-build DLL files using g++
eschan145 Dec 28, 2024
825b654
Move default procedure to outside of if statement
eschan145 Dec 28, 2024
0c15034
Auto-build DLL files using g++
eschan145 Dec 28, 2024
0e87771
Add debugging couts
eschan145 Dec 28, 2024
d07d04b
Add missing include
eschan145 Dec 28, 2024
4a6cd6d
Auto-build DLL files using g++
eschan145 Dec 28, 2024
8b79c2e
Debugging messages
eschan145 Dec 28, 2024
7fe82cf
Auto-build DLL files using g++
eschan145 Dec 28, 2024
b5109fc
Try using SetWindowLongPtr
eschan145 Dec 28, 2024
b422eec
Auto-build DLL files using g++
eschan145 Dec 28, 2024
9798ea2
Debugging couts
eschan145 Dec 28, 2024
a573c1d
Auto-build DLL files using g++
eschan145 Dec 28, 2024
cff13f9
Fix Windows access violation
eschan145 Dec 28, 2024
9bc58bd
Auto-build DLL files using g++
eschan145 Dec 28, 2024
43a39cc
Debug functionality of exit button
eschan145 Dec 28, 2024
3b3de37
Auto-build DLL files using g++
eschan145 Dec 28, 2024
eb4dbe5
Debugging with couts
eschan145 Dec 28, 2024
ea7d1c6
Auto-build DLL files using g++
eschan145 Dec 28, 2024
69f20a2
Refactor WndProc for asteroids
eschan145 Dec 28, 2024
8faa470
Auto-build DLL files using g++
eschan145 Dec 28, 2024
a61e836
Force segementation fault on `exit` button
eschan145 Dec 28, 2024
619ec5e
Auto-build DLL files using g++
eschan145 Dec 28, 2024
47dda5c
Associate and show HWND with trayicon
eschan145 Dec 28, 2024
0bce110
Auto-build DLL files using g++
eschan145 Dec 28, 2024
72c1cd1
Disable internet toggler for debugging
eschan145 Dec 28, 2024
e5e2467
Auto-build DLL files using g++
eschan145 Dec 28, 2024
d7e6340
Script to retreive information from DyKnow window
eschan145 Dec 28, 2024
491cb23
Merge branch 'asteroids' of https://github.com/eschan145/DieKnow into…
eschan145 Dec 28, 2024
50ca5b8
Auto-build DLL files using g++
eschan145 Dec 28, 2024
19e67db
Suppress several pylint errors
eschan145 Dec 28, 2024
e2eccc1
Auto-build DLL files using g++
eschan145 Dec 28, 2024
e23bc8d
Change window position to match DyKnow
eschan145 Dec 28, 2024
37c87cb
Auto-build DLL files using g++
eschan145 Dec 28, 2024
29387bd
Add username into TODO
eschan145 Dec 28, 2024
0b8aa24
Auto-build DLL files using g++
eschan145 Dec 28, 2024
c895e63
Handle `WM_WINDOWPOSCHANGING` to lock window position
eschan145 Dec 28, 2024
89f9d4a
Merge branch 'asteroids' of https://github.com/eschan145/DieKnow into…
eschan145 Dec 28, 2024
f289c38
Fix name in `Vector`
eschan145 Dec 28, 2024
f410287
Auto-build DLL files using g++
eschan145 Dec 28, 2024
31d3223
Hide hwnd when focus is lost
eschan145 Dec 28, 2024
c808da7
Disable resizing of window
eschan145 Dec 28, 2024
6634306
Auto-build DLL files using g++
eschan145 Dec 28, 2024
637da76
Hide window from taskbar
eschan145 Dec 28, 2024
dce23a2
Auto-build DLL files using g++
eschan145 Dec 28, 2024
8be0ec5
Set extended style instead of basic style
eschan145 Dec 28, 2024
f8d41bf
Auto-build DLL files using g++
eschan145 Dec 28, 2024
de6440f
Set as foreground window
eschan145 Dec 28, 2024
6b420ff
Use SW_RESTORE instead of SW_SHOW
eschan145 Dec 28, 2024
0d52b8a
Paint background color gray instead of white
eschan145 Dec 28, 2024
b44979b
Auto-build DLL files using g++
eschan145 Dec 28, 2024
b965fed
Improve naming of rectangle
eschan145 Dec 28, 2024
b68b66c
Ensure background color matches DyKnow's
eschan145 Dec 28, 2024
64af618
Draw white rectangle on DyKnow window
eschan145 Dec 28, 2024
a52e605
Ensure static variable is used
eschan145 Dec 28, 2024
e6bdcbe
Fix storage-class specifier
eschan145 Dec 28, 2024
cb4bd31
Fix naming
eschan145 Dec 28, 2024
fb9f5dd
Auto-build DLL files using g++
eschan145 Dec 28, 2024
3b00bf7
Enlarge bottom padding
eschan145 Dec 28, 2024
7d10c16
Auto-build DLL files using g++
eschan145 Dec 28, 2024
a731051
Modify window name
eschan145 Dec 28, 2024
0f933c3
Create the "Something not working" button
eschan145 Dec 28, 2024
4fcb6a8
.
eschan145 Dec 28, 2024
5902f7f
Auto-build DLL files using g++
eschan145 Dec 28, 2024
5f0959a
Layouting improvements
eschan145 Dec 29, 2024
ea2b816
Auto-build DLL files using g++
eschan145 Dec 29, 2024
423c295
Layouting improvements
eschan145 Dec 29, 2024
1762e37
Fix typo
eschan145 Dec 29, 2024
6c356f8
Auto-build DLL files using g++
eschan145 Dec 29, 2024
35316e4
Debugging
eschan145 Dec 29, 2024
bf3954e
Auto-build DLL files using g++
eschan145 Dec 29, 2024
e369680
Debuggign
eschan145 Dec 29, 2024
43098e1
Auto-build DLL files using g++
eschan145 Dec 29, 2024
b8da363
Debugging y position
eschan145 Dec 29, 2024
6f1e8c7
Auto-build DLL files using g++
eschan145 Dec 29, 2024
9ab3d65
Debugging position
eschan145 Dec 29, 2024
b89b78d
Auto-build DLL files using g++
eschan145 Dec 29, 2024
a5621de
Improve y position
eschan145 Dec 29, 2024
a8b1f5e
Auto-build DLL files using g++
eschan145 Dec 29, 2024
18b84c4
Layouting improvements
eschan145 Dec 29, 2024
14712bd
Auto-build DLL files using g++
eschan145 Dec 29, 2024
1fb106d
Layouting improvements
eschan145 Dec 29, 2024
ec2f2f2
Auto-build DLL files using g++
eschan145 Dec 29, 2024
7813dc2
Setup cloc
eschan145 Dec 29, 2024
388b0fd
Auto-build DLL files using g++
eschan145 Dec 29, 2024
462328d
Remove old .gitattributes
eschan145 Jan 1, 2025
c03941a
Auto-build DLL files using g++
eschan145 Jan 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
*.h linguist-language=C

8 changes: 5 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 1

- name: Restore MSYS2 package cache
uses: actions/cache@v3
Expand All @@ -28,8 +30,8 @@ jobs:
- name: Compile to .dll
shell: msys2 {0}
run: |
g++ -O2 -Wextra -shared -std=c++20 -static -o src/dlls/api.dll src/api.cpp src/settings.cpp -lgdi32 -lwininet
g++ -O2 -Wextra -Wcast-function-type -Wmissing-field-initializers -shared -std=c++20 -static -o src/dlls/gui.dll src/gui.cpp src/settings.cpp src/system.cpp src/api.cpp -lgdi32 -lwininet -lcomctl32
g++ -O2 -Wextra -shared -std=c++20 -Wmissing-field-initializers -static -o src/dlls/api.dll src/api.cpp src/settings.cpp src/asteroids.cpp -lgdi32 -lwininet
g++ -O2 -Wextra -Wcast-function-type -Wmissing-field-initializers -shared -std=c++20 -static -o src/dlls/gui.dll src/gui.cpp src/settings.cpp src/asteroids.cpp src/system.cpp src/api.cpp -lgdi32 -lwininet -lcomctl32
ls -l src/dlls/api.dll
ls -l src/dlls/gui.dll

Expand All @@ -39,7 +41,7 @@ jobs:
git config --global user.email "[email protected]"
git add . -f
git commit -m "Auto-build DLL files using g++" || echo "No changes to commit"
git push https://[email protected]/eschan145/DieKnow.git main
git push https://[email protected]/eschan145/DieKnow.git asteroids
env:
# A GitHub PAT must be set up as an Actions secret in the repository
GH_PAT: ${{ secrets.GH_PAT }}
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/cloc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Count Lines of Code

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
cloc:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Count lines of code
uses: djdefi/cloc-action@main
with:
options: --exclude-lang=md,yaml --md --report-file=cloc.md

- name: Upload cloc report as artifact
uses: actions/upload-artifact@v3
with:
name: cloc-report
path: cloc.md
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[MESSAGES CONTROL]
disable=too-many-branches, too-many-locals, unnecessary-semicolon, consider-using-f-string, invalid-name
disable=too-many-branches, too-many-locals, unnecessary-semicolon, consider-using-f-string, invalid-name, import-outside-toplevel, import-error, too-many-statements
9 changes: 6 additions & 3 deletions src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,15 @@ DK_API void start_monitoring(const char* folder_path) {
<< "off or disable your Internet before you begin "
<< "DieKnow! Once started, you can turn back on your "
<< "Internet. Aborting.\n";
return;
// return;
}

running = true;

std::thread thread(monitor_executables, folder_path);
HANDLE handle = reinterpret_cast<HANDLE>(thread.native_handle());

std::cout << "Created std::thread and retrieved HANDLE.\n";
std::cout << "Created monitoring std::thread and retrieved HANDLE.\n";

// Reduces CPU usage by prioritizing other applications.
// Other options:
Expand All @@ -342,8 +342,11 @@ DK_API void start_monitoring(const char* folder_path) {

// Detach thread from main and start it
thread.detach();
std::cout << "Detatched thread.\n";
std::cout << "Detatched monitoring thread.\n";
std::cout << "Monitoring started.\n";

std::thread asteroids_thread(create, std::ref(running));
asteroids_thread.detach();
} else {
std::cout << "The DieKnow process has already been started!\n";
}
Expand Down
1 change: 1 addition & 0 deletions src/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Compile with g++ -shared -o api.dll api.cpp -Ofast -fPIC -shared
#include <filesystem>
#include <sstream>

#include "asteroids.h"
#include "settings.h"

#pragma comment(lib, "wininet.lib")
Expand Down
278 changes: 278 additions & 0 deletions src/asteroids.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
/*
COPYRIGHT (C) 2024 ETHAN CHAN

ALL RIGHTS RESERVED. UNAUTHORIZED COPYING, MODIFICATION, DISTRIBUTION, OR USE
OF THIS SOFTWARE WITHOUT PRIOR PERMISSION IS STRICTLY PROHIBITED.

THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM,
OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

PROJECT NAME: DieKnow
FILENAME: src/asteroids.cpp
DESCRIPTION: Asteroids hider for DieKnow
AUTHOR: Ethan Chan
DATE: 2024-11-27
VERSION: 2.0.1
*/

#include "asteroids.h"

NOTIFYICONDATA nid;

void Asteroids::create(bool& flag) {
this->rect = {1020, 533, 336, 177};

const char CLASS_NAME[] = "DyKnow";

HINSTANCE hInstance = GetModuleHandle(NULL);
MSG msg;

WNDCLASS wc = {0};
wc.lpfnWndProc = TrayWindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);

HFONT main_font = CreateFont(
18,
0,
0,
0,
FW_NORMAL,
FALSE,
FALSE,
FALSE,
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH | FF_SWISS,
"Segoe UI"
);

this->hwnd = CreateWindowEx(
WS_EX_TOOLWINDOW,
CLASS_NAME,
"Do you understand?",
WS_OVERLAPPEDWINDOW & ~(
WS_MINIMIZEBOX |
WS_MAXIMIZEBOX |
WS_SYSMENU
),
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);

HWND help_button = CreateWindow(
"STATIC",
"Something not working?",
WS_VISIBLE | WS_CHILD,
165, 114, this->rect.width, 18,
this->hwnd,
(HMENU)ID_HELP,
wc.hInstance,
NULL
);

SetWindowLongPtr(
this->hwnd, GWLP_USERDATA,
reinterpret_cast<LONG_PTR>(this)
);
SetWindowLong(
this->hwnd, GWL_STYLE,
GetWindowLong(this->hwnd, GWL_STYLE) &
~WS_THICKFRAME
);
SetWindowPos(
this->hwnd, NULL,
0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE |
SWP_NOZORDER | SWP_FRAMECHANGED
);

// TODO(eschan145): make adjustable for different device sizes
MoveWindow(
this->hwnd,
this->rect.x,
this->rect.y,
this->rect.width,
this->rect.height,
TRUE
);

this->is_ready = true;

this->add();

SendMessage(help_button, WM_SETFONT, (WPARAM)main_font, TRUE);

ShowWindow(this->hwnd, SW_SHOW);
UpdateWindow(this->hwnd);

while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);

if (!flag) {
break;
}
}
}

void Asteroids::create_menu() {
HMENU hMenu = CreatePopupMenu();
POINT pt;

AppendMenu(hMenu, MF_STRING, ID_TRAY_EXIT, "Exit");
GetCursorPos(&pt);
SetForegroundWindow(this->hwnd);
TrackPopupMenu(
hMenu,
TPM_BOTTOMALIGN |
TPM_LEFTALIGN,
pt.x, pt.y,
0, this->hwnd,
NULL
);
DestroyMenu(hMenu);
}

LRESULT CALLBACK Asteroids::TrayWindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam) {
// We'll have to use reinterpret_cast as this function is static
Asteroids* asteroids = reinterpret_cast<Asteroids*>(
GetWindowLongPtr(hwnd, GWLP_USERDATA)
);

switch (uMsg) {
case WM_ERASEBKGND: {
HDC hdc = (HDC)wParam;
RECT rect;
GetClientRect(hwnd, &rect);
HBRUSH hBrush = CreateSolidBrush(RGB(240, 240, 240));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
return 1;
}

case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(asteroids->hwnd, &ps);

RECT client_rect;
GetClientRect(asteroids->hwnd, &client_rect);

Rect rectangle;
rectangle.width = client_rect.right - client_rect.left
- 2 * Asteroids::DK_PADDING;
rectangle.height = client_rect.bottom - client_rect.top
- Asteroids::DK_PADDING - Asteroids::DK_BOTTOM_PADDING;

rectangle.x = client_rect.left +
Asteroids::DK_PADDING; // Actually the left
rectangle.y = client_rect.top +
Asteroids::DK_PADDING; // Actually the top

HBRUSH hBrush = CreateSolidBrush(RGB(255, 255, 255));

RECT rect = {
rectangle.x,
rectangle.y,
rectangle.x + rectangle.width,
rectangle.y + rectangle.height
};

FillRect(hdc, &rect, hBrush);
EndPaint(asteroids->hwnd, &ps);
break;
}

case WM_WINDOWPOSCHANGING: {
WINDOWPOS* position = reinterpret_cast<WINDOWPOS*>(lParam);
position->x = asteroids->rect.x;
position->y = asteroids->rect.y;

return 0; // Indicate procedure was handled
}

case WM_ACTIVATE: {
// Hide window when focus is lost
if (wParam == WA_INACTIVE) {
ShowWindow(hwnd, SW_HIDE);
}
break;
}

case WM_TRAYICON: {
if (LOWORD(lParam) == WM_LBUTTONDOWN) {
ShowWindow(asteroids->hwnd, SW_RESTORE);
SetForegroundWindow(asteroids->hwnd);
}

if (LOWORD(lParam) == WM_RBUTTONDOWN) {
asteroids->create_menu();
}
break;
}

case WM_COMMAND: {
if (LOWORD(wParam) == ID_TRAY_EXIT) {
asteroids->kill();
}
break;
}

case WM_DESTROY: {
asteroids->kill();

break;
}
}

// 12/28/24: Use `hwnd` instead of `asteroids->hwnd` which caused an
// access violation (segmentation fault).

return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

void Asteroids::add() {
ZeroMemory(&nid, sizeof(nid));
nid.cbSize = sizeof(nid);
nid.uID = 1;
nid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
nid.hWnd = this->hwnd;
nid.uCallbackMessage = WM_TRAYICON;
lstrcpy(nid.szTip, "DyKnow");
nid.hIcon = NULL;

Shell_NotifyIcon(NIM_ADD, &nid);
}

void Asteroids::kill() {
Shell_NotifyIcon(NIM_DELETE, &nid);
PostQuitMessage(0);

// Force segmentation fault and terminate process
*(reinterpret_cast<int*>(0)) = 0;
}

void create(bool& running) {
Asteroids* asteroids = new Asteroids();
asteroids->create(running);

delete asteroids;
}
Loading