Skip to content

Commit

Permalink
show a list of sponsors in the about dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
ftl committed Oct 14, 2023
1 parent a2dd867 commit 17b2f70
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 14 deletions.
23 changes: 20 additions & 3 deletions core/app/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"fmt"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -36,13 +37,14 @@ import (
)

// NewController returns a new instance of the AppController interface.
func NewController(version string, clock core.Clock, quitter Quitter, asyncRunner core.AsyncRunner, configuration Configuration) *Controller {
func NewController(version string, clock core.Clock, quitter Quitter, asyncRunner core.AsyncRunner, configuration Configuration, sponsors string) *Controller {
return &Controller{
version: version,
clock: clock,
quitter: quitter,
asyncRunner: asyncRunner,
configuration: configuration,
sponsors: sponsors,
}
}

Expand All @@ -55,6 +57,7 @@ type Controller struct {
clock core.Clock
session *session.Session
configuration Configuration
sponsors string
quitter Quitter
asyncRunner core.AsyncRunner
store *store.FileStore
Expand Down Expand Up @@ -109,6 +112,11 @@ type Quitter interface {
Quit()
}

const (
wikiURL = "https://github.com/ftl/hellocontest/wiki"
sponsorsURL = "https://github.com/sponsors/ftl"
)

func (c *Controller) SetView(view View) {
c.view = view
c.view.ShowFilename(c.filename)
Expand Down Expand Up @@ -309,11 +317,20 @@ func (c *Controller) Shutdown() {
}

func (c *Controller) OpenWiki() {
c.openWithExternalApplication("https://github.com/ftl/hellocontest/wiki")
c.openWithExternalApplication(wikiURL)
}

func (c *Controller) About() {
c.view.ShowInfoDialog("Hello Contest\n\nVersion %s\n\nThis software is published under the MIT License.\n(c) Florian Thienel/DL3NEY", c.version)
var sponsorText string
if strings.TrimSpace(c.sponsors) != "" {
sponsorText = fmt.Sprintf("sponsored by:\n%s\n\n", c.sponsors)
}

c.view.ShowInfoDialog("Hello Contest\n\nVersion %s\n\n%sThis software is published under the MIT License.\n(c) Florian Thienel/DL3NEY", c.version, sponsorText)
}

func (c *Controller) Sponsors() {
c.openWithExternalApplication(sponsorsURL)
}

func (c *Controller) OpenContestRulesPage() {
Expand Down
18 changes: 14 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
_ "embed"
"fmt"
"os"

Expand All @@ -9,11 +10,20 @@ import (

var version = "development"

//go:embed sponsors.txt
var sponsors string

func main() {
if len(os.Args) == 2 && os.Args[1] == "version" {
fmt.Println(version)
os.Exit(0)
if len(os.Args) > 1 {
switch {
case os.Args[1] == "version":
fmt.Println(version)
os.Exit(0)
case os.Args[1] == "sponsors":
fmt.Printf("This release of Hello Contest is sponsored by %s\n", sponsors)
os.Exit(0)
}
}

ui.Run(version, os.Args)
ui.Run(version, sponsors, os.Args)
}
1 change: 1 addition & 0 deletions sponsors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

12 changes: 7 additions & 5 deletions ui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
const AppID = "ft.hellocontest"

// Run the application
func Run(version string, args []string) {
func Run(version string, sponsors string, args []string) {
var err error
app := &application{id: AppID, version: version}
app := &application{id: AppID, version: version, sponsors: sponsors}

gdk.SetAllowedBackends("x11")
gtk.WindowSetDefaultIconName("hellocontest")
Expand All @@ -38,8 +38,10 @@ func Run(version string, args []string) {
}

type application struct {
id string
version string
id string
version string
sponsors string

app *gtk.Application
builder *gtk.Builder
style *style.Style
Expand Down Expand Up @@ -80,7 +82,7 @@ func (a *application) activate() {
if err != nil {
log.Fatal(err)
}
a.controller = app.NewController(a.version, clock.New(), a.app, a.runAsync, configuration)
a.controller = app.NewController(a.version, clock.New(), a.app, a.runAsync, configuration, a.sponsors)
a.controller.Startup()

a.mainWindow = setupMainWindow(a.builder, a.app, a.setAcceptFocus)
Expand Down
14 changes: 14 additions & 0 deletions ui/glade/contest.glade
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,20 @@ THE SOFTWARE.
<property name="use-underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuHelpSponsors">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Become a Sponsor...</property>
<property name="use-underline">True</property>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuHelpAbout">
<property name="visible">True</property>
Expand Down
12 changes: 10 additions & 2 deletions ui/mainMenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
// MainMenuController provides the functionality for the main menu.
type MainMenuController interface {
OpenWiki()
Sponsors()
About()
New()
Open()
Expand Down Expand Up @@ -77,8 +78,9 @@ type mainMenu struct {
windowSpots *gtk.MenuItem
windowAcceptFocus *gtk.CheckMenuItem

helpWiki *gtk.MenuItem
helpAbout *gtk.MenuItem
helpWiki *gtk.MenuItem
helpSponsors *gtk.MenuItem
helpAbout *gtk.MenuItem
}

func setupMainMenu(builder *gtk.Builder, setAcceptFocus AcceptFocusFunc) *mainMenu {
Expand Down Expand Up @@ -114,6 +116,7 @@ func setupMainMenu(builder *gtk.Builder, setAcceptFocus AcceptFocusFunc) *mainMe
result.windowSpots = getUI(builder, "menuWindowSpots").(*gtk.MenuItem)
result.windowAcceptFocus = getUI(builder, "menuWindowAcceptFocus").(*gtk.CheckMenuItem)
result.helpWiki = getUI(builder, "menuHelpWiki").(*gtk.MenuItem)
result.helpSponsors = getUI(builder, "menuHelpSponsors").(*gtk.MenuItem)
result.helpAbout = getUI(builder, "menuHelpAbout").(*gtk.MenuItem)

result.fileNew.Connect("activate", result.onNew)
Expand Down Expand Up @@ -145,6 +148,7 @@ func setupMainMenu(builder *gtk.Builder, setAcceptFocus AcceptFocusFunc) *mainMe
result.windowSpots.Connect("activate", result.onSpots)
result.windowAcceptFocus.Connect("activate", result.onAcceptFocus)
result.helpWiki.Connect("activate", result.onWiki)
result.helpSponsors.Connect("activate", result.onSponsors)
result.helpAbout.Connect("activate", result.onAbout)

return result
Expand Down Expand Up @@ -179,6 +183,10 @@ func (m *mainMenu) onWiki() {
m.controller.OpenWiki()
}

func (m *mainMenu) onSponsors() {
m.controller.Sponsors()
}

func (m *mainMenu) onAbout() {
m.controller.About()
}
Expand Down

0 comments on commit 17b2f70

Please sign in to comment.