mirror of
https://github.com/Macrame-App/Macrame
synced 2025-12-29 07:19:26 +00:00
WIP: Trayicon
This commit is contained in:
parent
13ea4bc4b2
commit
86f98cb8e5
6 changed files with 116 additions and 41 deletions
|
|
@ -1,21 +1,21 @@
|
||||||
/*
|
/*
|
||||||
Macrame is a program that enables the user to create keyboard macros and button panels.
|
Macrame is a program that enables the user to create keyboard macros and button panels.
|
||||||
The macros are saved as simple JSON files and can be linked to the button panels. The panels can
|
The macros are saved as simple JSON files and can be linked to the button panels. The panels can
|
||||||
be created with HTML and CSS.
|
be created with HTML and CSS.
|
||||||
|
|
||||||
Copyright (C) 2025 Jesse Malotaux
|
Copyright (C) 2025 Jesse Malotaux
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -96,7 +96,7 @@ func ApiPost(w http.ResponseWriter, r *http.Request) {
|
||||||
case "/macro/play":
|
case "/macro/play":
|
||||||
PlayMacro("", w, r)
|
PlayMacro("", w, r)
|
||||||
case "/device/server/ip":
|
case "/device/server/ip":
|
||||||
GetServerIP(w, r)
|
GetServerIP(w)
|
||||||
case "/device/list":
|
case "/device/list":
|
||||||
DeviceList(w, r)
|
DeviceList(w, r)
|
||||||
case "/device/access/check":
|
case "/device/access/check":
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,21 @@
|
||||||
/*
|
/*
|
||||||
Macrame is a program that enables the user to create keyboard macros and button panels.
|
Macrame is a program that enables the user to create keyboard macros and button panels.
|
||||||
The macros are saved as simple JSON files and can be linked to the button panels. The panels can
|
The macros are saved as simple JSON files and can be linked to the button panels. The panels can
|
||||||
be created with HTML and CSS.
|
be created with HTML and CSS.
|
||||||
|
|
||||||
Copyright (C) 2025 Jesse Malotaux
|
Copyright (C) 2025 Jesse Malotaux
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -35,11 +35,22 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetServerIP(w http.ResponseWriter, r *http.Request) {
|
func ListServerIP(w http.ResponseWriter) {
|
||||||
|
ip, err := GetServerIp()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
MCRMLog("GetServerIP err: ", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
json.NewEncoder(w).Encode(ip)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetServerIp() (string, error) {
|
||||||
ifs, err := net.Interfaces()
|
ifs, err := net.Interfaces()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
MCRMLog(err)
|
MCRMLog(err)
|
||||||
return
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ifi := range ifs {
|
for _, ifi := range ifs {
|
||||||
|
|
@ -78,10 +89,11 @@ func GetServerIP(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Found a good IP, return it
|
// Found a good IP, return it
|
||||||
json.NewEncoder(w).Encode(ip.String())
|
return ip.String(), nil
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return "", fmt.Errorf("No IP found")
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeviceList(w http.ResponseWriter, r *http.Request) {
|
func DeviceList(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,21 @@
|
||||||
/*
|
/*
|
||||||
Macrame is a program that enables the user to create keyboard macros and button panels.
|
Macrame is a program that enables the user to create keyboard macros and button panels.
|
||||||
The macros are saved as simple JSON files and can be linked to the button panels. The panels can
|
The macros are saved as simple JSON files and can be linked to the button panels. The panels can
|
||||||
be created with HTML and CSS.
|
be created with HTML and CSS.
|
||||||
|
|
||||||
Copyright (C) 2025 Jesse Malotaux
|
Copyright (C) 2025 Jesse Malotaux
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
||||||
61
be/app/systray.go
Normal file
61
be/app/systray.go
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"be/app/helper"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/getlantern/systray"
|
||||||
|
)
|
||||||
|
|
||||||
|
func InitSystray() {
|
||||||
|
go func() {
|
||||||
|
systray.Run(OnReady, OnExit)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
func OnReady() {
|
||||||
|
systray.SetIcon(getFavicon())
|
||||||
|
systray.SetTitle("Macrame")
|
||||||
|
systray.SetTooltip("Macrame - Server")
|
||||||
|
|
||||||
|
ip, _ := GetServerIp()
|
||||||
|
|
||||||
|
systray.AddMenuItem("IP: "+ip+":"+helper.EnvGet("MCRM__PORT"), "")
|
||||||
|
|
||||||
|
systray.AddSeparator()
|
||||||
|
|
||||||
|
addMCRMItem("Dashboard", "/")
|
||||||
|
addMCRMItem("Panels", "/panels")
|
||||||
|
addMCRMItem("Macros", "/macros")
|
||||||
|
addMCRMItem("Devices", "/devices")
|
||||||
|
|
||||||
|
systray.AddSeparator()
|
||||||
|
|
||||||
|
mQuit := systray.AddMenuItem("Quit Macrame", "Quit Macrame")
|
||||||
|
go func() {
|
||||||
|
<-mQuit.ClickedCh
|
||||||
|
os.Exit(0)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
func addMCRMItem(name, urlPath string) {
|
||||||
|
m := systray.AddMenuItem(name, name)
|
||||||
|
go func() {
|
||||||
|
<-m.ClickedCh
|
||||||
|
helper.OpenBrowser("http://localhost:" + helper.EnvGet("MCRM__PORT") + urlPath)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
func OnExit() {
|
||||||
|
systray.Quit()
|
||||||
|
}
|
||||||
|
|
||||||
|
func getFavicon() []byte {
|
||||||
|
favicon, err := os.ReadFile("favicon.ico")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
MCRMLog("getFavicon Error: ", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return favicon
|
||||||
|
}
|
||||||
BIN
be/favicon.ico
Normal file
BIN
be/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 191 KiB |
20
be/main.go
20
be/main.go
|
|
@ -1,21 +1,21 @@
|
||||||
/*
|
/*
|
||||||
Macrame is a program that enables the user to create keyboard macros and button panels.
|
Macrame is a program that enables the user to create keyboard macros and button panels.
|
||||||
The macros are saved as simple JSON files and can be linked to the button panels. The panels can
|
The macros are saved as simple JSON files and can be linked to the button panels. The panels can
|
||||||
be created with HTML and CSS.
|
be created with HTML and CSS.
|
||||||
|
|
||||||
Copyright (C) 2025 Jesse Malotaux
|
Copyright (C) 2025 Jesse Malotaux
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -48,6 +48,8 @@ func main() {
|
||||||
|
|
||||||
app.MCRMLog("Listening on http://localhost:" + helper.EnvGet("MCRM__PORT"))
|
app.MCRMLog("Listening on http://localhost:" + helper.EnvGet("MCRM__PORT"))
|
||||||
|
|
||||||
|
app.InitSystray()
|
||||||
|
|
||||||
app.MCRMLog(http.ListenAndServe(":"+helper.EnvGet("MCRM__PORT"), nil))
|
app.MCRMLog(http.ListenAndServe(":"+helper.EnvGet("MCRM__PORT"), nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue