Skip to content

Commit

Permalink
Merge pull request #36 from icza/dev
Browse files Browse the repository at this point in the history
Public release of v1.3.0.
  • Loading branch information
icza authored Sep 26, 2017
2 parents 9fac1ec + 5ca5153 commit 9d69340
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: go

go:
- 1.7
- 1.8
- 1.9
- master
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: showcase -autoOpen=false -addr=":$PORT" -appName=""
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This one auto-opens itself in your default browser.

go run _examples/showcase/showcase.go

The Showcase of Features is also available live: http://iczapp.com:3434/gowut-demo/show
The Showcase of Features is also available live: https://gowut-demo.herokuapp.com/show

**2. A single window example.**

Expand Down
18 changes: 0 additions & 18 deletions _examples/showcase/showcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ package main

import (
"flag"
"fmt"
"log"
"os"

"github.com/icza/gowut/_examples/showcase/showcasecore"
)
Expand All @@ -38,20 +35,5 @@ var (
func main() {
flag.Parse()

// Allow app control from command line (in co-operation with the starter script):
log.Println("Type 'r' to restart, 'e' to exit.")
go func() {
var cmd string
for {
fmt.Scanf("%s", &cmd)
switch cmd {
case "r": // restart
os.Exit(1)
case "e": // exit
os.Exit(0)
}
}
}()

showcasecore.StartServer(*appName, *addr, *autoOpen)
}
1 change: 1 addition & 0 deletions _examples/simple/simple_demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main

import (
"fmt"

"github.com/icza/gowut/gwu"
)

Expand Down
4 changes: 2 additions & 2 deletions gwu/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,15 +388,15 @@ Source code: https://github.com/icza/gowut
Discussion forum: https://groups.google.com/d/forum/gowebuitoolkit
Live demo: http://iczapp.com:3434/gowut-demo/show
Live demo: https://gowut-demo.herokuapp.com/show
*/
package gwu

// Gowut version information.
const (
GowutVersion = "v1.2.2" // Gowut version: "v"major.minor.maintenance[-dev]
GowutVersion = "v1.3.0" // Gowut version: "v"major.minor.maintenance[-dev]
GowutReleaseDate = "2017-01-17 CET" // Gowut release date
GowutRelDateLayout = "2006-01-02 MST" // Gowut release date layout (for time.Parse())
)
15 changes: 15 additions & 0 deletions gwu/listbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ type ListBox interface {
// ListBox can be enabled/disabled.
HasEnabled

// Values returns the values.
Values() []string

// SetValues sets the values. Also clears the selection.
SetValues(values []string)

// Multi tells if multiple selections are allowed.
Multi() bool

Expand Down Expand Up @@ -102,6 +108,15 @@ func NewListBox(values []string) ListBox {
return c
}

func (c *listBoxImpl) Values() []string {
return c.values
}

func (c *listBoxImpl) SetValues(values []string) {
c.values = values
c.selected = make([]bool, len(values))
}

func (c *listBoxImpl) Multi() bool {
return c.multi
}
Expand Down
19 changes: 15 additions & 4 deletions gwu/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"path"
"strconv"
"strings"
"sync"
"time"
)

Expand Down Expand Up @@ -221,6 +222,8 @@ type serverImpl struct {
headers http.Header // Extra headers that will be added to all responses.
rootHeads []string // Additional head HTML texts of the window list page (app root)
appRootHandlerFunc AppRootHandlerFunc // App root handler function

sessMux sync.RWMutex // Mutex to protect state related to session handling
}

// NewServer creates a new GUI server in HTTP mode.
Expand Down Expand Up @@ -296,7 +299,9 @@ func (s *serverImpl) AddSessCreatorName(name, text string) {
}

func (s *serverImpl) AddSHandler(handler SessionHandler) {
s.sessMux.Lock()
s.sessionHandlers = append(s.sessionHandlers, handler)
s.sessMux.Unlock()
}

// newSession creates a new (private) Session.
Expand All @@ -315,6 +320,7 @@ func (s *serverImpl) newSession(e *eventImpl) Session {
e.shared.session = sess
}
// Store new session
s.sessMux.Lock()
s.sessions[sess.ID()] = sess

if s.logger != nil {
Expand All @@ -327,6 +333,7 @@ func (s *serverImpl) newSession(e *eventImpl) Session {
for _, handler := range s.sessionHandlers {
handler.Created(sess)
}
s.sessMux.Unlock()

return sess
}
Expand All @@ -337,14 +344,17 @@ func (s *serverImpl) newSession(e *eventImpl) Session {
// After this method Event.Session() will return the shared public session.
func (s *serverImpl) removeSess(e *eventImpl) {
if e.shared.session.Private() {
s.sessMux.Lock()
s.removeSess2(e.shared.session)
s.sessMux.Unlock()
e.shared.session = &s.sessionImpl
}
}

// removeSess2 removes (invalidates) the specified session.
// Only private sessions can be removed, calling this with the
// public session is a no-op.
// serverImpl.mux must be locked when this is called.
func (s *serverImpl) removeSess2(sess Session) {
if sess.Private() {
if s.logger != nil {
Expand Down Expand Up @@ -387,12 +397,13 @@ func (s *serverImpl) sessCleaner() {
for {
now := time.Now()

// TODO synchronization?
s.sessMux.Lock()
for _, sess := range s.sessions {
if now.Sub(sess.Accessed()) > sess.Timeout() {
s.removeSess2(sess)
}
}
s.sessMux.Unlock()

time.Sleep(sleep)
}
Expand Down Expand Up @@ -552,7 +563,9 @@ func (s *serverImpl) serveHTTP(w http.ResponseWriter, r *http.Request) {
var sess Session
c, err := r.Cookie(gwuSessidCookie)
if err == nil {
s.sessMux.RLock()
sess = s.sessions[c.Value]
s.sessMux.RUnlock()
}
if sess == nil {
sess = &s.sessionImpl
Expand Down Expand Up @@ -582,11 +595,9 @@ func (s *serverImpl) serveHTTP(w http.ResponseWriter, r *http.Request) {
}

if len(parts) >= 1 && parts[0] == pathSessCheck {
// Session check. Must not call sess.acess()
// Session check. Must not call sess.access()
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
sess.rwMutex().RLock()
remaining := sess.Timeout() - time.Now().Sub(sess.Accessed())
sess.rwMutex().RUnlock()
fmt.Fprintf(w, "%f", remaining.Seconds())
return
}
Expand Down
7 changes: 4 additions & 3 deletions gwu/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (s *sessionImpl) Private() bool {

func (s *sessionImpl) AddWin(w Window) error {
if len(w.Name()) == 0 {
return errors.New("Window name cannot be empty string!")
return errors.New("Window name cannot be empty string")
}
if _, exists := s.windows[w.Name()]; exists {
return errors.New("A window with the same name has already been added: " + w.Name())
Expand Down Expand Up @@ -214,6 +214,8 @@ func (s *sessionImpl) Created() time.Time {
}

func (s *sessionImpl) Accessed() time.Time {
s.rwMutexF.RLock()
defer s.rwMutexF.RUnlock()
return s.accessed
}

Expand All @@ -227,9 +229,8 @@ func (s *sessionImpl) SetTimeout(timeout time.Duration) {

func (s *sessionImpl) access() {
s.rwMutexF.Lock()
defer s.rwMutexF.Unlock()

s.accessed = time.Now()
s.rwMutexF.Unlock()
}

func (s *sessionImpl) clearNew() {
Expand Down
7 changes: 7 additions & 0 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"rootPath": "github.com/icza/gowut",
"heroku": {
"install": ["./_examples/showcase"],
"sync": false
}
}
2 changes: 1 addition & 1 deletion version-history/changes-v1.2.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changes and new features in v1.2.2:

-Moved the Showcase of Features live demo to: http://iczapp.com:3434/gowut-demo/show

-Added -addr and -autoOpen flags to the Showcase of Features demo.
-Added -appName, -addr and -autoOpen flags to the Showcase of Features demo.

-Added a missing check if a Server logger is set before using it.

Expand Down
10 changes: 10 additions & 0 deletions version-history/changes-v1.3.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

Changes and new features in v1.3.0:
-----------------------------------

-Added ListBox.Values() and ListBox.SetValues() methods to read / change items
of a ListBox.

-Fixed a number of data race issues at server session handling.

-Moved the Showcase of Features live demo to: https://gowut-demo.herokuapp.com/show

0 comments on commit 9d69340

Please sign in to comment.