Skip to content

Commit c8fccce

Browse files
committed
Add error dialogs on GUI error & refactor run.go
1 parent 1d15a95 commit c8fccce

File tree

5 files changed

+125
-59
lines changed

5 files changed

+125
-59
lines changed

install_linux.go

+11
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,14 @@ func osRunHookIfExists(scriptFile string) error {
9292
}
9393
return err
9494
}
95+
96+
func osShowRawErrorDialog(message string) (err error) {
97+
_, err = exec.Command(
98+
"zenity",
99+
"--error",
100+
"--title", "error",
101+
"--no-wrap",
102+
"--text", message,
103+
).Output()
104+
return
105+
}

resources/config.yml

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
variables:
33
company: ACME Inc.
44
company_short: ACME
5+
company_email: support@example.com
56
product: Example App
67
version: 8.18.0.0
78
applauncher: "{{.linux_app_launcher}}"
@@ -12,6 +13,7 @@ start_command: ExampleApp
1213
icon_file: ExampleApp.png
1314

1415
data_filename: data.zip
16+
log_filename: installer.log
1517

1618
gui_css: |
1719
window, dialog, button, entry {

resources/languages/de.yml

+13
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,16 @@ err_cli_mustacceptlicense: >
116116
err_gui_startup_failed: >
117117
Der graphische Installer konnte nicht gestartet werden. Die Installation per
118118
Kommandozeile akzeptiert folgende Parameter
119+
err_gui_startup_failed_nogtk: |
120+
Ihre Linuxversion unterstützt den graphischen
121+
Installationsmodus nicht (kein GTK3). Bitte
122+
installieren Sie via Kommandozeilenmodus, im
123+
Terminal.
124+
Um die Hilfe anzuzeigen geben Sie folgendes ein:
125+
{{.installerName}} -h
126+
err_gui_startup_internal_error: |
127+
Es ist ein unerwarter Fehler beim Laden des graphischen
128+
Installers aufgetreten. Bitte kontaktieren Sie den
129+
{{.company_short}}-Support und senden die
130+
installer.log-Datei mit wenn Sie können:
131+
{{.company_email}}

resources/languages/en.yml

+11
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,14 @@ err_cli_mustacceptlicense: >
112112
err_gui_startup_failed: >
113113
The graphical installer failed to start. The installation via command line uses the
114114
following parameters
115+
err_gui_startup_failed_nogtk: |
116+
Your Linux version does not support the graphical
117+
installation mode (no GTK3). Please install via
118+
command line mode, on the terminal.
119+
To show help, run:
120+
{{.installerName}} -h
121+
err_gui_startup_internal_error: |
122+
An unexpected error occurred while loading the GUI,
123+
please contact {{.company_short}} support, and provide
124+
the installer.log file if you can:
125+
{{.company_email}}

run.go

+88-59
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package linux_installer
22

33
import (
4-
// "io"
54
"flag"
65
"fmt"
76
"log"
@@ -16,20 +15,9 @@ const (
1615
// Linux terminal command string to clear the current line and reset the cursor
1716
clearLineVT100 = "\033[2K\r"
1817
cliInstallerMaxLineLen = 80
18+
logFilename = "installer.log"
1919
)
2020

21-
// startLogging sets up the logging
22-
func startLogging(logFilename string) *os.File {
23-
logfile, err := os.OpenFile(logFilename, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
24-
if err != nil {
25-
log.Fatal(err)
26-
}
27-
log.SetFlags(log.Ldate | log.Ltime)
28-
// log.SetOutput(io.MultiWriter(os.Stdout, logfile))
29-
log.SetOutput(logfile)
30-
return logfile
31-
}
32-
3321
// Run parses commandline options (if any) and starts one of two installer modes,
3422
// GUI or commandline mode.
3523
//
@@ -43,15 +31,18 @@ func startLogging(logFilename string) *os.File {
4331
// "silent" mode. -target and -accept-license are necessary to run commandline install.
4432
// -lang will also set the default GUI language.
4533
func Run() {
46-
logfile := startLogging("installer.log")
34+
logfile := startLogging(logFilename)
4735
defer logfile.Close()
4836

4937
openBoxes()
5038
config, err := NewConfig()
5139
if err != nil {
5240
return
5341
}
42+
config.Variables["installerName"] = os.Args[0]
5443
translator := NewTranslatorVar(config.Variables)
44+
installerTempPath := filepath.Join(os.TempDir(), "linux_installer")
45+
defer os.RemoveAll(installerTempPath)
5546

5647
target := flag.String("target", "", translator.Get("cli_help_target"))
5748
showLicense := flag.Bool("license", false, translator.Get("cli_help_showlicense"))
@@ -66,6 +57,7 @@ func Run() {
6657
fmt.Printf("Language '%s' not available", *lang)
6758
}
6859
}
60+
6961
if *showLicense {
7062
licenseFile, err := GetResource(
7163
fmt.Sprintf("licenses/license_%s.txt", translator.language),
@@ -82,85 +74,122 @@ func Run() {
8274
config.NoLauncher = true
8375
}
8476

85-
installerTempPath := filepath.Join(os.TempDir(), "linux_installer")
86-
defer os.RemoveAll(installerTempPath)
8777
if len(*target) > 0 {
8878
if *acceptLicense {
89-
installer := NewInstallerTo(*target, installerTempPath, config)
90-
installer.CreateLauncher = !config.NoLauncher
91-
c := make(chan os.Signal, 1)
92-
signal.Notify(c, os.Interrupt)
93-
installer.SetProgressFunction(func(status InstallStatus) {
94-
file := installer.NextFile().Target
95-
if len(file) > cliInstallerMaxLineLen {
96-
file = "..." + file[len(file)-(cliInstallerMaxLineLen-3):]
97-
}
98-
fmt.Print(clearLineVT100 + file)
99-
})
100-
fmt.Println(translator.Get("silent_installing"))
101-
installer.PreInstall()
102-
installer.StartInstall()
103-
go func() {
104-
for range c {
105-
installer.Rollback()
106-
}
107-
}()
108-
installer.WaitForDone()
109-
installer.PostInstall(
110-
translator.Variables,
111-
translator.GetAllStringsRaw(),
112-
)
113-
fmt.Println(clearLineVT100 + installer.SizeString())
114-
fmt.Println(translator.Get("silent_done"))
79+
RunCliInstall(installerTempPath, *target, translator, config)
11580
} else {
11681
fmt.Println(translator.Get("err_cli_mustacceptlicense"))
11782
}
11883
return
11984
}
12085

121-
var guiError error
122-
UnpackResourceDir("gui", filepath.Join(installerTempPath, "gui"))
123-
guiPlugin, guiError := plugin.Open(filepath.Join(installerTempPath, "gui", "gui.so"))
86+
guiError := RunGuiInstall(installerTempPath, translator, config)
12487
if guiError != nil {
125-
fmt.Println("load plugin")
126-
handleGuiErr(guiError, translator)
88+
RunTuiInstall(installerTempPath, translator)
89+
}
90+
}
91+
92+
// RunGuiInstall loads the gui.so plugin, and starts the installer GUI.
93+
func RunGuiInstall(
94+
installerTempPath string,
95+
translator *Translator,
96+
config *Config,
97+
) (err error) {
98+
UnpackResourceDir("gui", filepath.Join(installerTempPath, "gui"))
99+
guiPlugin, err := plugin.Open(filepath.Join(installerTempPath, "gui", "gui.so"))
100+
if err != nil {
101+
err = osShowRawErrorDialog(translator.Get("err_gui_startup_failed_nogtk"))
102+
if err != nil {
103+
handleGuiErr(err, translator.Get("err_gui_startup_failed_nogtk"))
104+
}
127105
return
128106
}
129107
NewGui, err := guiPlugin.Lookup("NewGui")
130108
if err != nil {
131-
fmt.Println("lookup NewGui")
132-
handleGuiErr(guiError, translator)
109+
osShowRawErrorDialog(translator.Get("err_gui_startup_internal_error"))
110+
handleGuiErr(err, "")
133111
return
134112
}
135113
RunGui, err := guiPlugin.Lookup("RunGui")
136114
if err != nil {
137-
fmt.Println("lookup RunGui")
138-
handleGuiErr(guiError, translator)
115+
osShowRawErrorDialog(translator.Get("err_gui_startup_internal_error"))
116+
handleGuiErr(err, "")
139117
return
140118
}
141119
installer := NewInstaller(installerTempPath, config)
142-
guiError = NewGui.(func(string, *Installer, *Translator, *Config) error)(
120+
err = NewGui.(func(string, *Installer, *Translator, *Config) error)(
143121
installerTempPath, installer, translator, config,
144122
)
145-
if guiError != nil {
146-
fmt.Println("NewGui()")
147-
handleGuiErr(guiError, translator)
123+
if err != nil {
124+
handleGuiErr(err, translator.Get("err_gui_startup_failed"))
148125
return
149126
} else {
150127
RunGui.(func())()
151128
}
152-
// if guiError != nil {
129+
return
130+
}
131+
132+
// RunCliInstall runs a "silent" installation, on the command line with no further user
133+
// interaction.
134+
func RunCliInstall(
135+
installerTempPath, target string, translator *Translator, config *Config,
136+
) {
137+
installer := NewInstallerTo(target, installerTempPath, config)
138+
installer.CreateLauncher = !config.NoLauncher
139+
cancelChannel := make(chan os.Signal, 1)
140+
signal.Notify(cancelChannel, os.Interrupt)
141+
installer.SetProgressFunction(func(status InstallStatus) {
142+
file := installer.NextFile().Target
143+
if len(file) > cliInstallerMaxLineLen {
144+
file = "..." + file[len(file)-(cliInstallerMaxLineLen-3):]
145+
}
146+
fmt.Print(clearLineVT100 + file)
147+
})
148+
fmt.Println(translator.Get("silent_installing"))
149+
installer.PreInstall()
150+
installer.StartInstall()
151+
go func() {
152+
for range cancelChannel {
153+
installer.Rollback()
154+
}
155+
}()
156+
installer.WaitForDone()
157+
installer.PostInstall(
158+
translator.Variables,
159+
translator.GetAllStringsRaw(),
160+
)
161+
fmt.Println(clearLineVT100 + installer.SizeString())
162+
fmt.Println(translator.Get("silent_done"))
163+
}
164+
165+
// RunTuiInstall starts a terminal curses-based UI (currently disabled).
166+
func RunTuiInstall(installerTempPath string, translator *Translator) {
153167
// tui, err := NewTui(installerTempPath, translator)
154168
// if err != nil {
155169
// log.Println(err)
156170
// } else {
157171
// tui.Run()
158172
// }
159-
// }
160173
}
161174

162-
func handleGuiErr(err error, translator *Translator) {
175+
// startLogging sets up the logging
176+
func startLogging(logFilename string) *os.File {
177+
logfile, err := os.OpenFile(logFilename, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
178+
if err != nil {
179+
log.Fatal(err)
180+
}
181+
log.SetFlags(log.Ldate | log.Ltime)
182+
// log.SetOutput(io.MultiWriter(os.Stdout, logfile))
183+
log.SetOutput(logfile)
184+
return logfile
185+
}
186+
187+
// handleGuiErr prints and logs GUI startup errors, and prints the commandline usage.
188+
func handleGuiErr(err error, msg string) {
163189
log.Println("Unable to load GUI:", err)
164-
fmt.Println(translator.Get("err_gui_startup_failed"))
190+
if len(msg) > 0 {
191+
log.Println(msg)
192+
fmt.Println(msg)
193+
}
165194
flag.PrintDefaults()
166195
}

0 commit comments

Comments
 (0)