Launcher: take app information from AppManager

Change-Id: I0dedd5a710adc4810feb9210b903655a3d2f5533
diff --git a/core/installer/welcome/launcher.go b/core/installer/welcome/launcher.go
index 6f40714..df4f863 100644
--- a/core/installer/welcome/launcher.go
+++ b/core/installer/welcome/launcher.go
@@ -7,6 +7,8 @@
 	"log"
 	"net/http"
 	"strings"
+
+	"github.com/giolekva/pcloud/core/installer"
 )
 
 //go:embed launcher-tmpl/launcher.html
@@ -16,23 +18,20 @@
 var files embed.FS
 
 type AppLauncherInfo struct {
-	Name        string
-	Description string
-	Icon        template.HTML
-	Help        []HelpDocument
-	Url         string
-}
-
-type HelpDocument struct {
-	Title    string
-	Contents string
-	Children []HelpDocument
+	Name string
+	Icon template.HTML
+	Help []installer.HelpDocument
+	Url  string
 }
 
 type AppDirectory interface {
 	GetAllApps() ([]AppLauncherInfo, error)
 }
 
+type AppManagerDirectory struct {
+	AppManager *installer.AppManager
+}
+
 type LauncherServer struct {
 	port         int
 	logoutUrl    string
@@ -78,6 +77,33 @@
 	return cleanName
 }
 
+func (d *AppManagerDirectory) GetAllApps() ([]AppLauncherInfo, error) {
+	allAppInstances, err := d.AppManager.FindAllInstances()
+	if err != nil {
+		return nil, err
+	}
+	var ret []AppLauncherInfo
+	for _, appInstance := range allAppInstances {
+		appLauncherInfo := AppLauncherInfo{
+			Name: appInstance.AppId,
+			Icon: template.HTML(appInstance.Icon),
+			Help: appInstance.Help,
+			Url:  appInstance.Url,
+		}
+		ret = append(ret, appLauncherInfo)
+	}
+	return ret, nil
+}
+
+func getLoggedInUser(r *http.Request) (string, error) {
+	if user := r.Header.Get("X-User"); user != "" {
+		return user, nil
+	} else {
+		return "", fmt.Errorf("unauthenticated")
+	}
+	// return "Username", nil
+}
+
 func (s *LauncherServer) Start() {
 	http.Handle("/static/", http.FileServer(http.FS(files)))
 	http.HandleFunc("/", s.homeHandler)
@@ -90,11 +116,14 @@
 }
 
 func (s *LauncherServer) homeHandler(w http.ResponseWriter, r *http.Request) {
-	loggedInUsername := "longusername"
+	loggedInUsername, err := getLoggedInUser(r)
+	if err != nil {
+		http.Error(w, "User Not Logged In", http.StatusUnauthorized)
+		return
+	}
 	allAppsInfo, err := s.appDirectory.GetAllApps()
 	if err != nil {
-		http.Error(w, err.Error(), http.StatusBadRequest)
-		return
+		http.Error(w, err.Error(), http.StatusInternalServerError)
 	}
 	data := homeHandlerData{
 		LoggedInUsername: loggedInUsername,