Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit986d3e3

Browse files
committed
Merge pull requestarduino#63 from arduino/killbrowser
Kill and restart the browser
2 parents1b8d7eb +58f468d commit986d3e3

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed

‎killbrowser.go‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package main
2+
3+
import (
4+
"errors"
5+
"net/http"
6+
7+
"github.com/gin-gonic/gin"
8+
)
9+
10+
funckillBrowserHandler(c*gin.Context) {
11+
12+
vardatastruct {
13+
Actionstring`json:"action"`
14+
Processstring`json:"process"`
15+
URLstring`json:"url"`
16+
}
17+
18+
c.BindJSON(&data)
19+
20+
ifdata.Process!="chrome"&&data.Process!="chrom" {
21+
c.JSON(http.StatusBadRequest,errors.New("You can't kill the process"+data.Process))
22+
return
23+
}
24+
25+
command,err:=findBrowser(data.Process)
26+
27+
iferr!=nil {
28+
c.JSON(http.StatusInternalServerError,err.Error())
29+
return
30+
}
31+
32+
ifdata.Action=="kill"||data.Action=="restart" {
33+
_,err:=killBrowser(data.Process)
34+
iferr!=nil {
35+
c.JSON(http.StatusInternalServerError,err.Error())
36+
return
37+
}
38+
}
39+
40+
ifdata.Action=="restart" {
41+
_,err:=startBrowser(command,data.URL)
42+
iferr!=nil {
43+
c.JSON(http.StatusInternalServerError,err.Error())
44+
return
45+
}
46+
}
47+
48+
}

‎killbrowser_darwin.go‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
3+
funcfindBrowser(processstring) ([]byte,error) {
4+
returnnil,nil
5+
}
6+
7+
funckillBrowser(processstring) ([]byte,error) {
8+
returnnil,nil
9+
}
10+
11+
funcstartBrowser(command []byte,urlstring) ([]byte,error) {
12+
returnnil,nil
13+
}

‎killbrowser_linux.go‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package main
2+
3+
import (
4+
"os/exec"
5+
"strings"
6+
)
7+
8+
funcfindBrowser(processstring) ([]byte,error) {
9+
ps:=exec.Command("ps","-A","-o","command")
10+
grep:=exec.Command("grep",process)
11+
head:=exec.Command("head","-n","1")
12+
13+
returnpipe_commands(ps,grep,head)
14+
}
15+
16+
funckillBrowser(processstring) ([]byte,error) {
17+
cmd:=exec.Command("pkill","-9",process)
18+
returncmd.Output()
19+
}
20+
21+
funcstartBrowser(command []byte,urlstring) ([]byte,error) {
22+
parts:=strings.Split(string(command)," ")
23+
cmd:=exec.Command(parts[0],url)
24+
returncmd.Output()
25+
}

‎killbrowser_windows.go‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package main
2+
3+
import"os/exec"
4+
5+
funcfindBrowser(processstring) ([]byte,error) {
6+
return []byte(process),nil
7+
}
8+
9+
funckillBrowser(processstring) ([]byte,error) {
10+
cmd:=exec.Command("Taskkill","/F","/IM",process+".exe")
11+
returncmd.Output()
12+
}
13+
14+
funcstartBrowser(command []byte,urlstring) ([]byte,error) {
15+
cmd:=exec.Command("cmd","/C","start",string(command),url)
16+
returncmd.Output()
17+
}

‎main.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ func main() {
241241
r.Handle("WS","/socket.io/",socketHandler)
242242
r.Handle("WSS","/socket.io/",socketHandler)
243243
r.GET("/info",infoHandler)
244+
r.POST("/killbrowser",killBrowserHandler)
245+
244246
gofunc() {
245247
// check if certificates exist; if not, use plain http
246248
if_,err:=os.Stat(filepath.Join(dest,"cert.pem"));os.IsNotExist(err) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp