From 95a98d991df78d6f16d4ea9664acbd1b4bf5b994 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 17 Jul 2011 17:30:40 -0700 Subject: [PATCH] open admin UI on windows Change-Id: I0df5042ddd9bb9058660468b862916a97b86c280 --- lib/go/camli/osutil/openurl.go | 36 ++++++++++++++++++++++++++++ server/go/camlistored/camlistored.go | 13 ++++++++++ 2 files changed, 49 insertions(+) create mode 100644 lib/go/camli/osutil/openurl.go diff --git a/lib/go/camli/osutil/openurl.go b/lib/go/camli/osutil/openurl.go new file mode 100644 index 000000000..b6418ddfb --- /dev/null +++ b/lib/go/camli/osutil/openurl.go @@ -0,0 +1,36 @@ +/* +Copyright 2011 Google Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package osutil + +import ( + "exec" + "runtime" + "os" +) + +func OpenURL(url string) os.Error { + if runtime.GOOS == "windows" { + return exec.Command("start", url).Run() + } + + if runtime.GOOS == "darwin" { + return exec.Command("open", url).Run() + } + + return exec.Command("xdg-open", url).Run() +} + diff --git a/server/go/camlistored/camlistored.go b/server/go/camlistored/camlistored.go index 23a10251e..6dccb754e 100644 --- a/server/go/camlistored/camlistored.go +++ b/server/go/camlistored/camlistored.go @@ -22,6 +22,7 @@ import ( "http" "log" "path/filepath" + "runtime" "strings" "os" @@ -194,6 +195,7 @@ func main() { handler: make(map[string]interface{}), } + uiPath := "" for prefix, vei := range prefixes { if !strings.HasPrefix(prefix, "/") { exitFailure("prefix %q doesn't start with /", prefix) @@ -221,8 +223,19 @@ func main() { conf: handlerArgs, } hl.config[prefix] = h + + if handlerType == "ui" { + uiPath = prefix + } } hl.setupAll() + ws.Listen() + + if runtime.GOOS == "windows" && uiPath != "" { + // Might be double-clicking an icon with no shell window? + // Just open the URL for them. + osutil.OpenURL(ws.BaseURL() + uiPath) + } ws.Serve() }