diff --git a/conf/wide.go b/conf/wide.go index 1804b3c..563d922 100644 --- a/conf/wide.go +++ b/conf/wide.go @@ -19,9 +19,9 @@ import ( // 最后一次会话内容结构. type LatestSessionContent struct { - FileTree []string // 文件树展开的路径集 - Files []string // 编辑器打开的文件路径集 - CurrentFile string // 当前编辑器文件路径 + FileTree []string `json:"fileTree"` // 文件树展开的路径集 + Files []string `json:"files"` // 编辑器打开的文件路径集 + CurrentFile string `json:"currentFile"` // 当前编辑器文件路径 } // 用户结构. diff --git a/main.go b/main.go index 6173a34..cc11d4b 100644 --- a/main.go +++ b/main.go @@ -123,9 +123,9 @@ func indexHandler(w http.ResponseWriter, r *http.Request) { // 创建一个 Wide 会话 wideSession := session.WideSessions.New(httpSession) - wideSessions := session.WideSessions.GetByHTTPSession(httpSession) - username := httpSession.Values["username"].(string) + + wideSessions := session.WideSessions.GetByUsername(username) userConf := conf.Wide.GetUser(username) model := map[string]interface{}{"conf": conf.Wide, "i18n": i18n.GetAll(r), "locale": i18n.GetLocale(r), diff --git a/session/sessions.go b/session/sessions.go index 3788ea3..baed934 100644 --- a/session/sessions.go +++ b/session/sessions.go @@ -220,7 +220,11 @@ func (sessions *Sessions) Get(sid string) *WideSession { return nil } -// 移除 Wide 会话. +// 移除 Wide 会话,释放相关资源. +// 会话相关资源: +// 1. 用户事件队列 +// 2. 运行中的进程 +// 3. WebSocket 通道 func (sessions *Sessions) Remove(sid string) { mutex.Lock() defer mutex.Unlock() @@ -273,32 +277,18 @@ func (sessions *Sessions) Remove(sid string) { } } -// 获取 HTTP 会话关联的所有 Wide 会话. -func (sessions *Sessions) GetByHTTPSession(httpSession *sessions.Session) []*WideSession { +// 获取 username 指定的用户的所有 Wide 会话. +func (sessions *Sessions) GetByUsername(username string) []*WideSession { mutex.Lock() defer mutex.Unlock() ret := []*WideSession{} for _, s := range *sessions { - if s.HTTPSession.ID == httpSession.ID { + if s.Username == username { ret = append(ret, s) } } return ret } - -// 移除 HTTP 会话关联的所有 Wide 会话. -func (sessions *Sessions) RemoveByHTTPSession(httpSession *sessions.Session) { - mutex.Lock() - defer mutex.Unlock() - - for i, s := range *sessions { - if s.HTTPSession.ID == httpSession.ID { - *sessions = append((*sessions)[:i], (*sessions)[i+1:]...) - - glog.V(3).Infof("Has [%d] wide sessions currently", len(*sessions)) - } - } -} diff --git a/shell/shells.go b/shell/shells.go index 2d04f7b..0e25b92 100644 --- a/shell/shells.go +++ b/shell/shells.go @@ -39,12 +39,13 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) { // 创建一个 Wide 会话 wideSession := session.WideSessions.New(httpSession) + username := httpSession.Values["username"].(string) + model := map[string]interface{}{"conf": conf.Wide, "i18n": i18n.GetAll(r), "locale": i18n.GetLocale(r), "session": wideSession} - wideSessions := session.WideSessions.GetByHTTPSession(httpSession) + wideSessions := session.WideSessions.GetByUsername(username) - username := httpSession.Values["username"].(string) glog.V(3).Infof("User [%s] has [%d] sessions", username, len(wideSessions)) t, err := template.ParseFiles("view/shell.html") diff --git a/static/js/session.js b/static/js/session.js index da8c9be..2aed2a0 100644 --- a/static/js/session.js +++ b/static/js/session.js @@ -35,9 +35,9 @@ var session = { }, 5000); }, restore: function () { - var fileTree = config.latestSessionContent.FileTree, - files = config.latestSessionContent.Files, - currentFile = config.latestSessionContent.CurrentFile, + var fileTree = config.latestSessionContent.fileTree, + files = config.latestSessionContent.files, + currentFile = config.latestSessionContent.currentFile, id = "", nodesToOpen = []; diff --git a/view/index.html b/view/index.html index a91e4e7..644fbd6 100644 --- a/view/index.html +++ b/view/index.html @@ -61,6 +61,7 @@ +
  • {{.i18n.help}}