2022-07-20 13:18:28 -04:00
//go:build !darwin
// +build !darwin
2022-02-14 23:42:08 -05:00
package main
import (
"context"
"fmt"
"log"
2022-03-04 12:52:40 -05:00
"os"
2022-02-14 23:42:08 -05:00
"time"
2022-04-11 11:12:21 -04:00
"fyne.io/systray"
2022-05-11 19:12:25 -04:00
"github.com/eyedeekay/go-i2pcontrol"
2022-02-14 23:42:08 -05:00
"i2pgit.org/idk/i2p.plugins.tor-manager/icon"
)
var running = false
var shutdown = false
func onReady ( ) {
systray . SetTemplateIcon ( icon . Data , icon . Data )
systray . SetTitle ( "Tor Manager for I2P" )
systray . SetTooltip ( "Tor and I2P integrated" )
// We can manipulate the systray in other goroutines
go func ( ) {
systray . SetTemplateIcon ( icon . Data , icon . Data )
systray . SetTitle ( "Tor Managing I2P Browser Plugin" )
systray . SetTooltip ( "Configures I2P and Tor in the same browser" )
mEnabled := systray . AddMenuItem ( "Online" , "I2P and Tor are both running" )
// Sets the icon of a menu item. Only available on Mac.
mEnabled . SetTemplateIcon ( icon . Data , icon . Data )
subMenuTop := systray . AddMenuItem ( "Launch a Browser" , "Launch a browser" )
subMenuBottom := subMenuTop . AddSubMenuItem ( "Launch Tor Browser configured for I2P" , "Modify and launch the Tor Browser Bundle for I2P" )
subMenuBottom2 := subMenuTop . AddSubMenuItem ( "Launch the Tor Browser" , "Launch the standard Tor Browser bundle" )
subMenuBottom3 := subMenuTop . AddSubMenuItem ( "Launch Hardened Firefox in Clearnet Mode" , "Launch the Tor Browser bundle, but without Tor" )
2022-05-11 19:12:25 -04:00
subMenuBottom4 := subMenuTop . AddSubMenuItem ( "Launch Offline Browser" , "Launch the Tor Browser bundle configured to have no access to the internet at all" )
2022-02-14 23:42:08 -05:00
systray . AddSeparator ( )
2022-03-03 23:37:47 -05:00
go onSnowflakeReady ( )
systray . AddSeparator ( )
2022-02-14 23:42:08 -05:00
mQuit := systray . AddMenuItem ( "Quit" , "Quit the whole app" )
// Sets the icon of a menu item. Only available on Mac.
mQuit . SetIcon ( icon . Data )
for {
select {
case <- mEnabled . ClickedCh :
mEnabled . SetTitle ( "I2P and Tor are both running" )
time . Sleep ( time . Second * 3 )
mEnabled . SetTitle ( "Online" )
case <- subMenuBottom . ClickedCh :
fmt . Println ( "Launching Tor Browser configured for I2P" )
if err := client . TBS . RunI2PBWithLang ( ) ; err != nil {
log . Println ( err )
}
case <- subMenuBottom2 . ClickedCh :
fmt . Println ( "Launching the Tor Browser" )
if err := client . TBS . RunTBWithLang ( ) ; err != nil {
log . Println ( err )
}
case <- subMenuBottom3 . ClickedCh :
fmt . Println ( "Launching Hardened Firefox in Clearnet Mode" )
2022-05-11 19:12:25 -04:00
if err := client . TBS . RunTBBWithOfflineClearnetProfile ( "profile.firefox" , false , true ) ; err != nil {
log . Println ( err )
}
case <- subMenuBottom4 . ClickedCh :
fmt . Println ( "Launching Hardened Firefox in Clearnet Mode" )
if err := client . TBS . RunTBBWithOfflineClearnetProfile ( "profile.firefox.offline" , true , true ) ; err != nil {
2022-02-14 23:42:08 -05:00
log . Println ( err )
}
case <- mQuit . ClickedCh :
systray . Quit ( )
fmt . Println ( "Quit now..." )
return
}
time . Sleep ( time . Second * 1 )
}
} ( )
}
func onExit ( ) {
2022-03-05 00:08:13 -05:00
if * snowflake {
snowflakeProxy . Stop ( )
}
2022-03-04 01:02:03 -05:00
if * password != "" {
log . Println ( "Encrypting directory with password" )
2022-03-05 00:08:13 -05:00
os . Remove ( * directory + ".tar.xz" )
2022-03-04 01:02:03 -05:00
EncryptTarXZip ( * directory , * password )
}
2022-02-14 23:42:08 -05:00
if shutdown {
i2pcontrol . Initialize ( "127.0.0.1" , "7657" , "" )
_ , err := i2pcontrol . Authenticate ( "itoopie" )
if err != nil {
log . Println ( err )
}
message , err := i2pcontrol . ShutdownGraceful ( )
if err != nil {
log . Println ( err )
}
2022-02-19 00:46:47 -05:00
ltc := 0
for {
tunnels , err := i2pcontrol . ParticipatingTunnels ( )
if err != nil {
log . Println ( err )
}
if ltc != tunnels {
log . Println ( "Participating tunnels:" , tunnels )
}
ltc = tunnels
if tunnels <= 0 {
break
}
}
2022-02-14 23:42:08 -05:00
log . Println ( message )
}
running = false
ctx , cancel := context . WithTimeout ( context . Background ( ) , 5 * time . Second )
defer cancel ( )
if err := client . Shutdown ( ctx ) ; err != nil {
2022-03-07 16:31:57 -05:00
log . Println ( err )
}
if * destruct {
OverwriteDirectoryContents ( * directory )
2022-02-14 23:42:08 -05:00
}
}
func runSysTray ( down bool ) {
if ! running {
running = true
shutdown = down
systray . Run ( onReady , onExit )
}
}