This commit is contained in:
Steven Tracey 2023-05-19 14:43:13 -04:00
parent 64863e6f02
commit d54a1abe2e
24 changed files with 284 additions and 75 deletions

3
.gitignore vendored
View File

@ -126,4 +126,5 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
config.ini
config.ini
public.cer

View File

@ -0,0 +1,20 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="GoUnhandledErrorResult" enabled="true" level="WARNING" enabled_by_default="true">
<methods>
<method importPath="hash" receiver="Hash" name="Write" />
<method importPath="strings" receiver="*Builder" name="Write" />
<method importPath="strings" receiver="*Builder" name="WriteByte" />
<method importPath="bytes" receiver="*Buffer" name="WriteRune" />
<method importPath="bytes" receiver="*Buffer" name="Write" />
<method importPath="bytes" receiver="*Buffer" name="WriteString" />
<method importPath="strings" receiver="*Builder" name="WriteString" />
<method importPath="bytes" receiver="*Buffer" name="WriteByte" />
<method importPath="strings" receiver="*Builder" name="WriteRune" />
<method importPath="math/rand" receiver="*Rand" name="Read" />
<method importPath="os" receiver="*File" name="Close" />
</methods>
</inspection_tool>
</profile>
</component>

7
.idea/vcs.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/ezconf" vcs="Git" />
</component>
</project>

61
Main.go
View File

@ -1,61 +0,0 @@
package main
import (
"crypto/tls"
"fmt"
"git.nevets.tech/Steven/ezconf"
"github.com/getlantern/systray"
"os"
"time"
)
var Config *ezconf.Configuration
var Connection *tls.Conn
func main() {
Config = ezconf.NewConfiguration("./config.ini")
Connection = New(Config.GetAsString("General.server"), Config.GetAsInt("General.port"))
systray.Run(onReady, onExit)
}
func onReady() {
systray.SetIcon(getIcon("assets/icon.ico"))
systray.SetTooltip("SimpleFileSync")
itemOne := systray.AddMenuItem("Item-1", "Highlighted Item 1")
systray.AddSeparator()
sync := systray.AddMenuItem("Sync", "Trigger Sync Now")
systray.AddSeparator()
quit := systray.AddMenuItem("Quit", "Quit")
go func() {
for {
select {
case <-itemOne.ClickedCh:
if itemOne.Checked() {
itemOne.Uncheck()
} else {
itemOne.Check()
}
case <-sync.ClickedCh:
sync.SetTitle("Syncing...")
time.Sleep(1000)
sync.SetTitle("Last sync at " + time.Now().Format(time.TimeOnly))
case <-quit.ClickedCh:
systray.Quit()
}
}
}()
}
func onExit() {
}
func getIcon(location string) []byte {
bytes, err := os.ReadFile(location)
if err != nil {
fmt.Print(err)
}
return bytes
}

BIN
assets/information.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
assets/warning.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

8
c_libs/.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

2
c_libs/.idea/c_libs.iml Normal file
View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />

4
c_libs/.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>

8
c_libs/.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/c_libs.iml" filepath="$PROJECT_DIR$/.idea/c_libs.iml" />
</modules>
</component>
</project>

6
c_libs/.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

9
c_libs/CMakeLists.txt Normal file
View File

@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.25)
project(c_libs C)
set(CMAKE_C_STANDARD 11)
include_directories(.)
add_executable(c_libs
notification.h notification.hpp notification.cpp cnotification.cpp)

0
c_libs/cnotification.cpp Normal file
View File

5
c_libs/notification.cpp Normal file
View File

@ -0,0 +1,5 @@
#include "notification.hpp"
void Notification::buildNotification(void) {
}

12
c_libs/notification.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef NOTIFICATION_H
#define NOTIFICATION_H
#include <stdio.h>
typedef struct Notification {
FILE *icon;
char title[16];
char message[];
} Notification;
int buildNotification(char title[], char message[], FILE *icon);
#endif

9
c_libs/notification.hpp Normal file
View File

@ -0,0 +1,9 @@
class Notification {
public:
FILE icon;
char title[16];
char message[];
Notification(FILE _icon, char _title[16], char _message[]):icon(_icon)title(_title){}
void buildNotification();
};

2
ezconf

@ -1 +1 @@
Subproject commit 397365ddd2fa6359058b7f6dd62eb516387e3994
Subproject commit e5bdaa67f6b2ad812b8aa5674316af02ae87e652

View File

@ -1 +1,25 @@
package main
import (
"fmt"
"net"
"os"
)
func testClient() {
conn, err := net.Dial("tcp", "localhost:2455")
if err != nil {
fmt.Printf("Error connecting to server: %v", err)
os.Exit(1)
}
_, err = conn.Write(NewSFS(254).ToBytes())
if err != nil {
fmt.Printf("Error sending data: %v", err)
os.Exit(1)
}
err = conn.Close()
if err != nil {
fmt.Printf("Error closing connection: %v", err)
os.Exit(1)
}
}

9
go.mod
View File

@ -7,9 +7,12 @@ replace git.nevets.tech/Steven/ezconf v0.0.0-20230501190348-397365ddd2fa => ./ez
require (
git.nevets.tech/Steven/ezconf v0.0.0-20230501190348-397365ddd2fa
github.com/getlantern/systray v1.2.1
github.com/sqweek/dialog v0.0.0-20220809060634-e981b270ebbf
)
require (
github.com/TheTitanrain/w32 v0.0.0-20200114052255-2654d97dbd3d // indirect
github.com/gen2brain/beeep v0.0.0-20230307103607-6e717729cb4f // indirect
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 // indirect
github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7 // indirect
github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7 // indirect
@ -17,8 +20,12 @@ require (
github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 // indirect
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9 // indirect
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect
golang.org/x/sys v0.8.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

19
go.sum
View File

@ -1,5 +1,11 @@
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf h1:FPsprx82rdrX2jiKyS17BH6IrTmUBYqZa/CXT4uvb+I=
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf/go.mod h1:peYoMncQljjNS6tZwI9WVyQB3qZS6u79/N3mBOcnd3I=
github.com/TheTitanrain/w32 v0.0.0-20200114052255-2654d97dbd3d h1:2xp1BQbqcDDaikHnASWpVZRjibOxu7y9LhAv04whugI=
github.com/TheTitanrain/w32 v0.0.0-20200114052255-2654d97dbd3d/go.mod h1:peYoMncQljjNS6tZwI9WVyQB3qZS6u79/N3mBOcnd3I=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gen2brain/beeep v0.0.0-20230307103607-6e717729cb4f h1:oRm7Hy2dQWfHgOuOWRaYZf+kZcWJst7fxAlq+yjdLss=
github.com/gen2brain/beeep v0.0.0-20230307103607-6e717729cb4f/go.mod h1:0W7dI87PvXJ1Sjs0QPvWXKcQmNERY77e8l7GFhZB/s4=
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 h1:NRUJuo3v3WGC/g5YiyF790gut6oQr5f3FBI88Wv0dx4=
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520/go.mod h1:L+mq6/vvYHKjCX2oez0CgEAJmbq1fbb/oNJIWQkBybY=
github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7 h1:6uJ+sZ/e03gkbqZ0kUG6mfKoqDb4XMAzMIwlajq19So=
@ -16,15 +22,28 @@ github.com/getlantern/systray v1.2.1 h1:udsC2k98v2hN359VTFShuQW6GGprRprw6kD6539J
github.com/getlantern/systray v1.2.1/go.mod h1:AecygODWIsBquJCJFop8MEQcJbWFfw/1yWbVabNgpCM=
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 h1:qZNfIGkIANxGv/OqtnntR4DfOY2+BgwR60cAcu/i3SE=
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4/go.mod h1:kW3HQ4UdaAyrUCSSDR4xUzBKW6O2iA4uHhk7AtyYp10=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sqweek/dialog v0.0.0-20220809060634-e981b270ebbf h1:pCxn3BCfu8n8VUhYl4zS1BftoZoYY0J4qVF3dqAQ4aU=
github.com/sqweek/dialog v0.0.0-20220809060634-e981b270ebbf/go.mod h1:/qNPSY91qTz/8TgHEMioAUc6q7+3SOybeKczHMXFcXw=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk=
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o=
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9 h1:YTzHMGlqJu67/uEo1lBv0n3wBXhXNeUbB1XfN2vmTm0=
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=

86
main.go Normal file
View File

@ -0,0 +1,86 @@
package main
import (
"crypto/tls"
"fmt"
"git.nevets.tech/Steven/ezconf"
"github.com/getlantern/systray"
"github.com/sqweek/dialog"
"os"
"time"
)
var Config *ezconf.Configuration
var Connection *tls.Conn
func main() {
Config = ezconf.NewConfiguration("./config.ini")
//var err error
//Connection, err = NewConnection(Config.GetAsString("General.server"), Config.GetAsInt("General.port"))
//if err != nil {
// fmt.Printf("Error establishing connection: %v", err)
// os.Exit(1)
//}
//_, err = Connection.Write(NewSFS(254).ToBytes())
//if err != nil {
// fmt.Printf("Error sending data: %v", err)
// os.Exit(1)
//}
//
//rawData := make([]byte, 1)
//_, err = Connection.Read(rawData)
//if err != nil {
// fmt.Printf("Error reading data: %v", err)
// os.Exit(1)
//}
//sfsData := NewSFSFromBytes(rawData)
//fmt.Printf("SFS Data: %v", sfsData)
//
//err = Connection.Close()
//if err != nil {
// fmt.Printf("Error closing connection: %v", err)
// os.Exit(1)
//}
sendNotification("Notification", "This is the message displayed!")
systray.Run(onReady, onExit)
}
func onReady() {
systray.SetIcon(getIcon("assets/icon.ico"))
systray.SetTooltip("SimpleFileSync")
itemOne := systray.AddMenuItem("Dialog", "Opens Dialog Box")
systray.AddSeparator()
sync := systray.AddMenuItem("Sync", "Trigger Sync Now")
systray.AddSeparator()
quit := systray.AddMenuItem("Quit", "Quit")
go func() {
for {
select {
case <-itemOne.ClickedCh:
dialog.Message("This is a popup from Simple File Sync!").Title("Simple File Sync").Info()
case <-sync.ClickedCh:
sync.SetTitle("Syncing...")
time.Sleep(1000)
sync.SetTitle("Last sync at " + time.Now().Format(time.TimeOnly))
case <-quit.ClickedCh:
systray.Quit()
}
}
}()
}
func onExit() {
Config.Save()
}
func getIcon(location string) []byte {
bytes, err := os.ReadFile(location)
if err != nil {
fmt.Print(err)
}
return bytes
}

7
notifications.go Normal file
View File

@ -0,0 +1,7 @@
package main
import "github.com/TheTitanrain/w32"
func sendNotification(title string, message string) {
w32.DialogBox()
}

View File

@ -20,32 +20,45 @@ type Credentials struct {
pass string
}
func New(host string, port int) *tls.Conn {
cert, err := os.ReadFile("./public.pem")
func NewConnection(host string, port int) (*tls.Conn, error) {
_, err := os.Stat("./public.cer")
if err != nil {
fmt.Printf("Error reading cert from ./public.pem: %v", err)
os.Exit(1)
getPublicKey()
}
cert, err := os.ReadFile("./public.cer")
if err != nil {
return nil, fmt.Errorf("error reading cert from ./public.cer: %v", err)
}
certPool := x509.NewCertPool()
if ok := certPool.AppendCertsFromPEM(cert); !ok {
fmt.Printf("Error loading certificate %v into cert pool", cert)
os.Exit(1)
return nil, fmt.Errorf("error loading certificate %v into cert pool", cert)
}
config := &tls.Config{RootCAs: certPool}
conn, err := tls.Dial("tcp", host+":"+string(rune(port)), config)
return conn
config := &tls.Config{
RootCAs: certPool,
CipherSuites: []uint16{
tls.TLS_AES_128_GCM_SHA256,
tls.TLS_AES_256_GCM_SHA384,
tls.TLS_CHACHA20_POLY1305_SHA256,
},
}
conn, err := tls.Dial("tcp", fmt.Sprintf("%s:%d", host, port), config)
if err != nil {
return nil, err
}
return conn, nil
}
func getPublicKey() {
out, err := os.Create("./public.pem")
out, err := os.Create("./public.cer")
if err != nil {
fmt.Printf("Error closing file writer: %v", err)
os.Exit(1)
}
defer out.Close()
resp, err := http.Get(Config.GetAsString("General.http-server") + "/public.pem")
resp, err := http.Get(Config.GetAsString("General.http-server") + "/public.cer")
if err != nil {
fmt.Printf("Error fetching public key: %v", err)
os.Exit(1)

23
sfsproto.go Normal file
View File

@ -0,0 +1,23 @@
package main
type SFSData struct {
length uint8
}
func NewSFSFromBytes(data []byte) *SFSData {
return &SFSData{
length: data[0],
}
}
func NewSFS(length uint8) *SFSData {
return &SFSData{
length: length,
}
}
func (sfs *SFSData) ToBytes() []byte {
return []byte{
sfs.length,
}
}