Skip to content

Commit db2cfb3

Browse files
authored
Initial import (#1)
1 parent 6ab65c4 commit db2cfb3

37 files changed

+3360
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.syso
2+
*.exe
3+
*.stackdump

bootstrap/bootstrap.go

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package bootstrap
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"io"
7+
"log"
8+
"os"
9+
"path/filepath"
10+
"runtime"
11+
12+
"github.com/pkg/errors"
13+
"github.com/rocketsoftware/open-web-launch/java"
14+
"github.com/rocketsoftware/open-web-launch/launcher"
15+
"github.com/rocketsoftware/open-web-launch/messaging"
16+
"github.com/rocketsoftware/open-web-launch/utils"
17+
)
18+
19+
func Run(productName, productTitle, productVersion string) {
20+
productWorkDir := filepath.Join(os.TempDir(), productName)
21+
productLogFile := filepath.Join(productWorkDir, productName+".log")
22+
fmt.Fprintf(os.Stderr, "%s %s\n", productTitle, productVersion)
23+
if err := utils.CreateProductWorkDir(productWorkDir); err != nil {
24+
log.Fatal(err)
25+
}
26+
logFile, err := utils.OpenOrCreateProductLogFile(productLogFile)
27+
if err != nil {
28+
log.Fatal(err)
29+
}
30+
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
31+
log.SetOutput(logFile)
32+
log.Printf("starting %s %s with arguments %v\n", productTitle, productVersion, os.Args)
33+
log.Printf("current platform is OS=%q Architecture=%q\n", runtime.GOOS, runtime.GOARCH)
34+
if len(os.Args) == 2 {
35+
filenameOrURL := os.Args[1]
36+
handleURLOrFilename(filenameOrURL, nil, productWorkDir, productTitle)
37+
} else if len(os.Args) == 3 && os.Args[1] == "-uninstall" {
38+
handleUninstallCommand(productWorkDir, productTitle)
39+
} else if len(os.Args) == 4 && os.Args[1] == "-javadir" {
40+
javaDir := os.Args[2]
41+
filenameOrURL := os.Args[3]
42+
var err error
43+
if javaDir, err = java.UseJavaDir(javaDir); err != nil {
44+
log.Fatal(err)
45+
}
46+
options := &launcher.Options{JavaDir: javaDir}
47+
handleURLOrFilename(filenameOrURL, options, productWorkDir, productTitle)
48+
} else {
49+
isRunningFromBrowser := len(os.Args) > 2
50+
options := &launcher.Options{IsRunningFromBrowser: isRunningFromBrowser}
51+
log.Printf("running from browser: %v\n", isRunningFromBrowser)
52+
listenForMessage(options, productWorkDir, productTitle)
53+
}
54+
}
55+
56+
func handleURLOrFilename(filenameOrURL string, options *launcher.Options, productWorkDir string, productTitle string) {
57+
myLauncher, byURL, err := launcher.FindLauncherForURLOrFilename(filenameOrURL)
58+
if err != nil {
59+
log.Fatal(err)
60+
}
61+
if err := myLauncher.CheckPlatform(); err != nil {
62+
log.Fatal(err)
63+
}
64+
myLauncher.SetWorkDir(productWorkDir)
65+
myLauncher.SetWindowTitle(productTitle)
66+
myLauncher.SetOptions(options)
67+
defer myLauncher.Wait()
68+
if byURL {
69+
if err := myLauncher.RunByURL(filenameOrURL); err != nil {
70+
log.Println(err)
71+
return
72+
}
73+
} else {
74+
if err := myLauncher.RunByFilename(filenameOrURL); err != nil {
75+
log.Println(err)
76+
return
77+
}
78+
}
79+
}
80+
81+
func listenForMessage(options *launcher.Options, productWorkDir string, productTitle string) {
82+
message, err := messaging.GetMessage(os.Stdin)
83+
if err != nil {
84+
if errors.Cause(err) != io.EOF {
85+
log.Fatal(err)
86+
}
87+
log.Println("exit because stdin has been closed")
88+
return
89+
}
90+
if message.Status != "" {
91+
response := fmt.Sprintf(`{"status": "installed"}`)
92+
if err := messaging.SendMessage(os.Stdout, response); err != nil {
93+
log.Fatal(err)
94+
}
95+
return
96+
}
97+
myLauncher, err := launcher.FindLauncherForURL(message.URL)
98+
if err != nil {
99+
log.Fatal(err)
100+
}
101+
if err := myLauncher.CheckPlatform(); err != nil {
102+
log.Fatal(err)
103+
}
104+
myLauncher.SetWorkDir(productWorkDir)
105+
myLauncher.SetWindowTitle(productTitle)
106+
myLauncher.SetOptions(options)
107+
defer myLauncher.Wait()
108+
if err := myLauncher.RunByURL(message.URL); err != nil {
109+
stringError := fmt.Sprintf("%v", err)
110+
jsonError, _ := json.Marshal(stringError)
111+
response := fmt.Sprintf(`{"status": %s}`, string(jsonError))
112+
log.Println(response)
113+
if err := messaging.SendMessage(os.Stdout, response); err != nil {
114+
log.Fatal(err)
115+
}
116+
return
117+
}
118+
response := fmt.Sprintf(`{"status": "ok"}`)
119+
if err := messaging.SendMessage(os.Stdout, response); err != nil {
120+
log.Fatal(err)
121+
}
122+
}
123+
124+
func handleUninstallCommand(productWorkDir string, productTitle string) {
125+
_ = os.Args[1] // -uninstall
126+
filenameOrURL := os.Args[2]
127+
myLauncher, byURL, err := launcher.FindLauncherForURLOrFilename(filenameOrURL)
128+
if err != nil {
129+
log.Fatal(err)
130+
}
131+
myLauncher.SetWorkDir(productWorkDir)
132+
myLauncher.SetWindowTitle(productTitle)
133+
if byURL {
134+
if err := myLauncher.UninstallByURL(filenameOrURL); err != nil {
135+
log.Println(err)
136+
return
137+
}
138+
} else {
139+
if err := myLauncher.UninstallByFilename(filenameOrURL); err != nil {
140+
log.Println(err)
141+
return
142+
}
143+
}
144+
}

cmd/openweblaunch/main.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
import (
4+
"github.com/rocketsoftware/open-web-launch/bootstrap"
5+
_ "github.com/rocketsoftware/open-web-launch/launcher/jnlp"
6+
)
7+
8+
//go:generate goversioninfo -o openweblaunch.syso
9+
10+
const (
11+
productName = "openweblaunch"
12+
productTitle = "Open Web Launch"
13+
)
14+
15+
var productVersion = "Dummy version number"
16+
17+
func main() {
18+
bootstrap.Run(productName, productTitle, productVersion)
19+
}

cmd/openweblaunch/resources/icon.ico

80.8 KB
Binary file not shown.

cmd/openweblaunch/versioninfo.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"FixedFileInfo": {
3+
"FileVersion": {
4+
"Major": 1,
5+
"Minor": 0,
6+
"Patch": 0,
7+
"Build": 0
8+
},
9+
"ProductVersion": {
10+
"Major": 1,
11+
"Minor": 0,
12+
"Patch": 0,
13+
"Build": 0
14+
},
15+
"FileFlagsMask": "3f",
16+
"FileFlags ": "00",
17+
"FileOS": "040004",
18+
"FileType": "01",
19+
"FileSubType": "00"
20+
},
21+
"StringFileInfo": {
22+
"Comments": "",
23+
"CompanyName": "Rocket Software Inc.",
24+
"FileDescription": "Open Web Launch",
25+
"FileVersion": "",
26+
"InternalName": "openweblaunch",
27+
"LegalCopyright": "©2019 Rocket Software Inc.",
28+
"LegalTrademarks": "",
29+
"OriginalFilename": "",
30+
"PrivateBuild": "",
31+
"ProductName": "Open Web Launch",
32+
"ProductVersion": "v1.0.0.0",
33+
"SpecialBuild": ""
34+
},
35+
"IconPath": "resources\\icon.ico",
36+
"ManifestPath": ""
37+
}

go.mod

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module github.com/rocketsoftware/open-web-launch
2+
3+
require (
4+
github.com/aarzilli/nucular v0.0.0-20190604155258-847327059ed7
5+
github.com/elazarl/go-bindata-assetfs v1.0.0
6+
github.com/go-ole/go-ole v1.2.4
7+
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
8+
github.com/pkg/errors v0.8.1
9+
golang.org/x/image v0.0.0-20190616094056-33659d3de4f5
10+
golang.org/x/mobile v0.0.0-20190607214518-6fa95d984e88
11+
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f
12+
)

go.sum

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
2+
github.com/BurntSushi/xgb v0.0.0-20160522221800-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
3+
github.com/aarzilli/nucular v0.0.0-20190604155258-847327059ed7 h1:hUPnGRVk7zIgDxQEzeETm9L45edIkyYlOR78rtrpYmA=
4+
github.com/aarzilli/nucular v0.0.0-20190604155258-847327059ed7/go.mod h1:kmRix5MpiU9CMTXlMppPUJ6FEza2no59rZZZWcF3xMU=
5+
github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk=
6+
github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
7+
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
8+
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
9+
github.com/golang/freetype v0.0.0-20161208064710-d9be45aaf745/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
10+
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
11+
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
12+
github.com/hashicorp/golang-lru v0.0.0-20160813221303-0a025b7e63ad h1:eMxs9EL0PvIGS9TTtxg4R+JxuPGav82J8rA+GFnY7po=
13+
github.com/hashicorp/golang-lru v0.0.0-20160813221303-0a025b7e63ad/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
14+
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
15+
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
16+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
17+
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
18+
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522 h1:OeRHuibLsmZkFj773W4LcfAGsSxJgfPONhr8cmO+eLA=
19+
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
20+
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
21+
golang.org/x/image v0.0.0-20190616094056-33659d3de4f5 h1:ngW7cqsJcNIFizl289rKwy+nVvw7TQS8z3ejrra6syo=
22+
golang.org/x/image v0.0.0-20190616094056-33659d3de4f5/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
23+
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
24+
golang.org/x/mobile v0.0.0-20190318164015-6bd122906c08/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
25+
golang.org/x/mobile v0.0.0-20190607214518-6fa95d984e88 h1:H6DkDrMSuEE2MQR7DgGwkzbXSY1lvMpEN5MDE1bo/5U=
26+
golang.org/x/mobile v0.0.0-20190607214518-6fa95d984e88/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
27+
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
28+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
29+
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
30+
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f h1:25KHgbfyiSm6vwQLbM3zZIe1v9p/3ea4Rz+nnM5K/i4=
31+
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
32+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
33+
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=

gui/assets/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bindata.go

gui/assets/Icon64.png

6.74 KB
Loading

gui/assets/index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Open Web Launch</title>
5+
<link rel="stylesheet" type="text/css" href="main.css"/>
6+
</head>
7+
<body>
8+
<div class="main">
9+
<div class="title">Open Web Launch</div>
10+
<div class="app-title"></div>
11+
<div class="progress-container">
12+
<div class="progress"></div>
13+
</div>
14+
<div class="text"></div>
15+
</div>
16+
<script src="main.js"></script>
17+
</body>
18+
</html>

gui/assets/main.css

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
* {
2+
font-family: Helvetica;
3+
}
4+
5+
body {
6+
display: flex;
7+
flex-direction: column;
8+
align-items: center;
9+
justify-content: center;
10+
}
11+
12+
.main {
13+
display: flex;
14+
width: 640px;
15+
height: 480px;
16+
align-items: center;
17+
border: 2px solid blue;
18+
border-radius: 2px;
19+
background-color: lightblue;
20+
justify-content: center;
21+
flex-direction: column;
22+
}
23+
24+
.title {
25+
display: flex;
26+
flex: 1 1 auto;
27+
justify-content: center;
28+
font-size: 3rem;
29+
font-weight: 800;
30+
height: 30%;
31+
align-items: center;
32+
}
33+
34+
.app-title {
35+
display: flex;
36+
justify-content: center;
37+
font-size: 1rem;
38+
font-weight: 600;
39+
min-height: 40px;
40+
}
41+
42+
.text {
43+
min-height: 40px;
44+
display: flex;
45+
font-weight: 400;
46+
justify-content: center;
47+
}
48+
49+
.progress-container {
50+
position: relative;
51+
display: flex;
52+
flex-direction: row;
53+
align-self: stretch;
54+
height: 30px;
55+
align-items: stretch;
56+
margin: 10px 7px 60px 7px;
57+
}
58+
59+
.progress {
60+
display: flex;
61+
flex-direction: row;
62+
width: 0;
63+
background-color: blue;
64+
border-radius: 3px;
65+
}

gui/assets/main.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
(function() {
2+
var socket = new WebSocket('ws://localhost:18485/status');
3+
var progress = 0;
4+
var progressMax = 0;
5+
6+
socket.onopen = function() {
7+
showMessage('Started');
8+
};
9+
10+
socket.onclose = function(event) {
11+
closeWindow();
12+
};
13+
14+
socket.onmessage = function(event) {
15+
var message = JSON.parse(event.data);
16+
if (message.type === 'close') {
17+
showMessage('Exiting...');
18+
closeWindow();
19+
} else if (message.type === 'progress_step') {
20+
progressStep();
21+
} else if (message.type === 'progress_max') {
22+
progressMax = +message.payload;
23+
} else if (message.type === 'title') {
24+
setTitle(message.payload);
25+
} else {
26+
showMessage(message.payload);
27+
}
28+
};
29+
30+
socket.onerror = function(error) {
31+
showMessage('Error: ' + error.message);
32+
};
33+
34+
function showMessage(message) {
35+
document.querySelector('div.text').innerText = message;
36+
}
37+
38+
function closeWindow() {
39+
setTimeout(function () {
40+
window.close();
41+
}, 500);
42+
}
43+
44+
function setTitle(title) {
45+
document.querySelector('div.app-title').innerText = title;
46+
}
47+
48+
function progressStep() {
49+
progress++;
50+
var width = String(progress/progressMax * 100) + '%';
51+
document.querySelector('div.progress').style.width = width;
52+
}
53+
})();

0 commit comments

Comments
 (0)