-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add CLI program * move logging * Remove extra logging * add small delay when we stop Lantern * clean-ups * clean-ups * fix formatting * use flashlight flags * Add comments * run go mod tidy * support running lantern desktop app * clean-ups * add cliClient and run go mod tidy * clean-ups * use go 1.22.6 * remove unused, merge latest, improve error handling * Fix test
- Loading branch information
Showing
6 changed files
with
241 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/signal" | ||
"sync" | ||
"syscall" | ||
"time" | ||
|
||
"github.com/getlantern/golog" | ||
"github.com/getlantern/lantern-client/desktop/app" | ||
|
||
"github.com/pterm/pterm" | ||
) | ||
|
||
var ( | ||
log = golog.LoggerFor("lantern") | ||
) | ||
|
||
type cliClient struct { | ||
app *app.App | ||
mu sync.Mutex | ||
} | ||
|
||
func main() { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
signalChan := make(chan os.Signal, 1) | ||
signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM) | ||
go func() { | ||
<-signalChan | ||
pterm.Warning.Println("Received shutdown signal.") | ||
cancel() | ||
}() | ||
|
||
client := &cliClient{} | ||
client.start(ctx) | ||
defer client.stop() | ||
|
||
<-ctx.Done() | ||
} | ||
|
||
func (client *cliClient) start(ctx context.Context) { | ||
client.mu.Lock() | ||
defer client.mu.Unlock() | ||
if client.app != nil { | ||
pterm.Warning.Println("Lantern is already running") | ||
return | ||
} | ||
|
||
// create new instance of Lantern app | ||
app, err := app.NewApp() | ||
if err != nil { | ||
pterm.Error.Printf("Unable to initialize app: %v", err) | ||
return | ||
} | ||
client.app = app | ||
|
||
// Run Lantern in the background | ||
go app.Run(ctx) | ||
} | ||
|
||
func (client *cliClient) stop() { | ||
client.mu.Lock() | ||
defer client.mu.Unlock() | ||
if client.app == nil { | ||
// Lantern is not running, no cleanup needed | ||
return | ||
} | ||
|
||
pterm.Info.Println("Stopping Lantern...") | ||
client.app.Exit(nil) | ||
client.app = nil | ||
|
||
// small delay to give Lantern time to cleanup | ||
time.Sleep(1 * time.Second) | ||
pterm.Success.Println("Lantern stopped successfully.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.