Skip to content

Commit 31a546a

Browse files
committed
Several improvements.
Signed-off-by: elModo7 <elmodo7yt@gmail.com>
1 parent 0364d11 commit 31a546a

30 files changed

Lines changed: 9888 additions & 115 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
deprecated/
1+
notrack/

FireFlyFy.ahk

Lines changed: 71 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,99 @@
11
;@Ahk2Exe-SetName FireFlyFy
22
;@Ahk2Exe-SetDescription Changes monitor brightness based on active window.
3-
;@Ahk2Exe-SetVersion 0.0.1
3+
;@Ahk2Exe-SetVersion 1.0.0
44
;@Ahk2Exe-SetCopyright Copyright (c) 2025`, elModo7 - VictorDevLog
55
;@Ahk2Exe-SetOrigFilename FireFlyFy.exe
66
#NoEnv
77
#SingleInstance Force
88
#Persistent
9+
SetTitleMatchMode, 3
910
DetectHiddenWindows, On
1011
SetBatchLines -1
12+
CoordMode, Mouse, Screen
13+
global version := "0.1.3"
14+
global appName := "FireFlyFy"
15+
16+
; Libs
1117
#Include <Screen>
1218
#Include <cJSON>
13-
#Include <aboutScreen>
19+
#Include <Utils>
20+
#Include <AboutScreen>
1421
#Include <WindowsNightLight>
15-
global version := "0.1"
16-
global appName := "FireFlyFy"
17-
global appPrev, globalSettings, apps
1822

19-
gosub, configureTray
20-
gosub, createOrReadConfig
23+
; Globals
24+
global initialBrightness, appPrev, processPrev, globalConfig, appsConfig, isVisible := 1, fireFlyFyEnabled := 1
25+
26+
; Init
27+
createOrReadConfig()
28+
loadTranslations(globalConfig.language)
29+
installResources()
30+
setInitialBrigthness()
31+
configureTray()
2132
createNightFilter()
2233

23-
SetTimer, checkCurrentApp, 500
24-
;WinShow, nightFilter
25-
NightLight_Toggle()
26-
Sleep, 2000
27-
NightLight_Toggle()
28-
return
34+
Gui +LastFound
35+
hWnd := WinExist()
36+
DllCall("RegisterShellHookWindow", UInt, hWnd)
37+
registerWindowMessageId := DllCall("RegisterWindowMessage", Str, "SHELLHOOK")
38+
OnMessage(0x404, "trayEventsCapture")
2939

30-
checkCurrentApp:
31-
;WinGetActiveTitle, activeTitle
32-
;WinGet, activeProcess, ProcessName
33-
if (appCur != appPrev) {
34-
; setMonitorBrightnessProgressive(0)
35-
}
36-
appPrev := appCur
40+
enableFireFlyFy()
41+
gosub, initMouseFollower
3742
return
3843

39-
configureTray:
40-
Menu, Tray, NoStandard
41-
Menu, Tray, Tip, % appName "v" version
42-
Menu, Tray, Add,
43-
Menu, tray, add, % appName " Info", showAboutScreen
44-
;Menu tray, Icon, % appName " Info", % A_Temp "\" appName "\info.ico"
45-
Menu, Tray, Add, Exit, ExitSub
46-
;Menu tray, Icon, Exit, % A_Temp "\" appName "\close3.ico"
47-
return
44+
detectWindowChanged(wParam, lParam)
45+
{
46+
; https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms644991(v=vs.85)
47+
if ((wParam > 0 && wParam < 5) || wParam == 6 || wParam == 32772) {
48+
Settimer, checkCurrentApp, 100
49+
}
50+
}
4851

49-
createOrReadConfig:
50-
if (!FileExist("config/global.json")) {
51-
createConfig()
52-
} else {
53-
FileRead, globalSettings, config/global.json
54-
globalSettings := JSON.Load(globalSettings)
52+
checkCurrentApp:
53+
Settimer, checkCurrentApp, Off
54+
WinGetActiveTitle, appCur
55+
WinGet, processCur, ProcessName, A
56+
if (appCur != appPrev || processCur != processPrev) {
57+
appPrev := appCur
58+
processPrev := processCur
59+
for appK, appV in appsConfig.apps
60+
{
61+
if (appV.activeBy == "process") {
62+
if (processCur == appV.process) {
63+
applyFireFlyFy(appV)
64+
return
65+
}
66+
} else {
67+
if (appCur == appV.title) {
68+
applyFireFlyFy(appV)
69+
return
70+
}
71+
}
72+
}
73+
removeFireFlyFy()
5574
}
5675
return
5776

58-
createConfig() {
59-
globalSettings := {}
60-
globalSettings.language := "en-US"
61-
globalSettings.startWithWindows := 0
62-
FileAppend, % JSON.Dump(globalSettings), config/global.json
63-
}
77+
#Include <LabelUtils>
6478

65-
createNightFilter() {
66-
global
67-
Gui, nightFilter:+AlwaysOnTop +ToolWindow -Caption -DPIScale +E0x20
68-
Gui, nightFilter:Color, 0xFFFFEB
69-
Gui, nightFilter:Show, x0 y0 w1920 h1080 NoActivate Hide, nightFilter
70-
WinWait, nightFilter
71-
WinSet, Transparent, 35, nightFilter
72-
}
79+
^Esc::Reload
7380

74-
showAboutScreen:
75-
showAboutScreen(appName " v" version, "Changes your monitor brightness automatically based on the currently active window.")
76-
return
81+
/* TODO:
82+
Add window / process -> FireFly follows mouse when choosing, enter chooses, escape cancels
83+
title or processName (default by process)
84+
brightnessValue 0-100 (default 50)
85+
nightLightStrength 0-100 (default 50)
86+
Block that if you have by title of the same process, you can not add a rule by process unless you remove the ones by title before, maybe prompt of those that match and offer removing?
7787
78-
aboutGuiEscape:
79-
aboutGuiClose:
80-
AboutGuiClose()
81-
return
8288
83-
ExitSub:
84-
ExitApp
89+
application list
90+
91+
Start with windows (default no)
92+
Scheduler (default no)
93+
progressive change yes/no (default yes)
94+
multilingual
95+
Clear config
8596
86-
/*
87-
toggleable hotkey
88-
trayMenu
89-
title or processName
90-
brightnessValue 0-100
91-
progressive change yes/no
92-
add about
97+
Update, autoreplace running executable
98+
Add CLI
9399
*/

FireFlyFy.exe

2.25 MB
Binary file not shown.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# 🕯 FireFlyFy

config/apps.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"apps": [
3+
{
4+
"activeBy": "process",
5+
"brightness": 30,
6+
"changeBrightness": 1,
7+
"name": "Notepad",
8+
"process": "Notepad.exe",
9+
"readMode": 0,
10+
"nightLightStrength": 0,
11+
"title": "New text document"
12+
},
13+
{
14+
"activeBy": "process",
15+
"brightness": 50,
16+
"changeBrightness": 0,
17+
"name": "IntelliJ",
18+
"process": "idea64.exe",
19+
"readMode": 1,
20+
"nightLightStrength": 50,
21+
"title": "Whatever"
22+
},
23+
{
24+
"activeBy": "title",
25+
"brightness": 50,
26+
"changeBrightness": 1,
27+
"name": "Google Chrome",
28+
"process": "Chrome.exe",
29+
"readMode": 1,
30+
"nightLightStrength": 50,
31+
"title": "Wikipedia, la enciclopedia libre - Google Chrome"
32+
}
33+
]
34+
}

config/apps_win10.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"apps": [
3+
{
4+
"activeBy": "process",
5+
"brightness": 30,
6+
"changeBrightness": 1,
7+
"name": "Notepad",
8+
"process": "notepad.exe",
9+
"readMode": 0,
10+
"nightLightStrength": 0,
11+
"title": "New text document"
12+
},
13+
{
14+
"activeBy": "title",
15+
"brightness": 50,
16+
"changeBrightness": 1,
17+
"name": "Google Chrome",
18+
"process": "chrome.exe",
19+
"readMode": 1,
20+
"nightLightStrength": 25,
21+
"title": "YouTube - Google Chrome"
22+
},
23+
{
24+
"activeBy": "title",
25+
"brightness": 50,
26+
"changeBrightness": 1,
27+
"name": "Google Chrome",
28+
"process": "chrome.exe",
29+
"readMode": 1,
30+
"nightLightStrength": 50,
31+
"title": "Wikipedia, la enciclopedia libre - Google Chrome"
32+
}
33+
]
34+
}

config/global.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2-
"language": "en-US",
3-
"startWithWindows": false
2+
"experimentalReadFilter": 0,
3+
"language": "en-US",
4+
"lookForUpdates": 1,
5+
"progressive": 1,
6+
"startWithWindows": 0
47
}

lib/Chalk.ahk

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
class Chalker {
2+
; TODO: Background colors
3+
4+
static _colorCodes := { black: "", red: "", green: "", yellow: "", blue: "", magenta: "", cyan: "", white: "" }
5+
6+
static _bgColorCodes := { bgBlack: "", bgRed: "", bgGreen: "", bgYellow: "", bgBlue: "", bgMagenta: "", bgCyan: "", bgWhite: "" }
7+
8+
static _modifierCodes := { bold: "", dim: "", italic: "", underline: "", overline: "", inverse: "", hidden: "", strikethrough: "" }
9+
10+
static _reset := ""
11+
12+
_colorState := ""
13+
_bgColorState := ""
14+
_modifierState := { bold: false, dim: false, italic: false, underline: false, overline: false, inverse: false, hidden: false, strikethrough: false }
15+
16+
__Get(propName) {
17+
for k, v in Chalker._colorCodes {
18+
if (k == propName) {
19+
this._colorState := propName
20+
return this
21+
}
22+
}
23+
24+
for k, v in Chalker._bgColorCodes {
25+
if (k == propName) {
26+
this._bgColorState := propName
27+
return this
28+
}
29+
}
30+
31+
for k, v in Chalker._modifierCodes {
32+
if (k == propName) {
33+
this._modifierState[propName] := true
34+
return this
35+
}
36+
}
37+
38+
throw "Unknown property: " . propName
39+
}
40+
41+
__Call(methodName, str) {
42+
isColor := false
43+
for k, v in Chalker._colorCodes {
44+
if (k == methodName) {
45+
this._colorState := methodName
46+
isColor := true
47+
break
48+
}
49+
}
50+
51+
isBgColor := false
52+
for k, v in Chalker._bgColorCodes {
53+
if (k == methodName) {
54+
this._bgColorState := methodName
55+
isBgColor := true
56+
break
57+
}
58+
}
59+
60+
isModifier := false
61+
if (!isColor && !isBgColor) {
62+
for k, v in Chalker._modifierCodes {
63+
if (k == methodName) {
64+
this._modifierState[methodName] := true
65+
isModifier := true
66+
break
67+
}
68+
}
69+
}
70+
71+
if (!isColor && !isBgColor && !isModifier) {
72+
throw "Unknown method: " . methodName
73+
}
74+
75+
; Combine all specified colors and modifiers into a single prefix
76+
prefix := ""
77+
if (this._colorState != "") {
78+
prefix .= Chalker._colorCodes[this._colorState]
79+
}
80+
if (this._bgColorState != "") {
81+
prefix .= Chalker._bgColorCodes[this._bgColorState]
82+
}
83+
for k, v in this._modifierState {
84+
if (v == true) {
85+
prefix .= Chalker._modifierCodes[k]
86+
}
87+
}
88+
89+
; Reset state
90+
this._colorState := ""
91+
this._bgColorState := ""
92+
for k, v in this._modifierState {
93+
this._modifierState[k] := false
94+
}
95+
96+
; Return the final string
97+
return prefix str Chalker._reset
98+
}
99+
}

0 commit comments

Comments
 (0)