Documentation
¶
Overview ¶
Package app holds the services the frontend calls. They stay thin: the work happens in the other internal packages, which know nothing about the UI.
Index ¶
- Constants
- Variables
- func DevEnv(name string) string
- func HandleLink(s *ServerService, raw string, running bool)
- func LinkArg(args []string) string
- func ParseAddLink(raw string) (string, error)
- func Released() bool
- type BaseInstallRequest
- type BaseInstallResult
- type Branding
- type CheckResult
- type Host
- type LauncherUpdateProgress
- type LinkRequest
- type Overview
- type ProfileService
- type SendResult
- type ServerReport
- type ServerService
- func (s *ServerService) AddFromLink(ctx context.Context, profileURL string) (string, error)
- func (s *ServerService) AddServer(ctx context.Context, profileURL string) (string, error)
- func (s *ServerService) BaseSetup() core.BaseSetup
- func (s *ServerService) Branding(ctx context.Context, id string) Branding
- func (s *ServerService) CheckForUpdate(ctx context.Context) *updates.Release
- func (s *ServerService) Choices(ctx context.Context, id string) (core.Choices, error)
- func (s *ServerService) ChooseBase(ctx context.Context) (Overview, error)
- func (s *ServerService) ChooseInstallFolder() (string, error)
- func (s *ServerService) ClearBaseCache() error
- func (s *ServerService) DEP(ctx context.Context, id string) (core.DEP, error)
- func (s *ServerService) FinishWelcome(pins []string) error
- func (s *ServerService) InstallBase(ctx context.Context, req BaseInstallRequest) BaseInstallResult
- func (s *ServerService) InstallRosetta(ctx context.Context) error
- func (s *ServerService) InstallUpdate(ctx context.Context) error
- func (s *ServerService) Ladder(ctx context.Context, id string) (*core.Ladder, error)
- func (s *ServerService) LaunchDelay() int
- func (s *ServerService) LogIn(ctx context.Context, id string) (core.Login, error)
- func (s *ServerService) LogOut(id string) error
- func (s *ServerService) Login(ctx context.Context, id string) (core.Login, error)
- func (s *ServerService) News(ctx context.Context, id string) ([]core.NewsItem, error)
- func (s *ServerService) OpenServerFolder(id string) error
- func (s *ServerService) Overview(ctx context.Context) Overview
- func (s *ServerService) PendingLink() *LinkRequest
- func (s *ServerService) Play(ctx context.Context, id string) error
- func (s *ServerService) RemoveServer(id string) error
- func (s *ServerService) SetChannel(ctx context.Context, id, channel string) error
- func (s *ServerService) SetComponent(ctx context.Context, id, component, version string) error
- func (s *ServerService) SetD2GLResolutions(id, main, loader string) error
- func (s *ServerService) SetFavourite(id string, on bool) error
- func (s *ServerService) SetFavouriteOrder(ids []string) error
- func (s *ServerService) SetInstances(ctx context.Context, id string, n int, splitD2GL bool) error
- func (s *ServerService) SetLaunchDelay(ms int) error
- func (s *ServerService) SetSetting(ctx context.Context, id, setting string, value any) error
- func (s *ServerService) Settings(ctx context.Context, id string) ([]core.SettingValue, error)
- func (s *ServerService) SetupWine(ctx context.Context) WineSetupResult
- func (s *ServerService) Status(ctx context.Context, id string) core.Status
- func (s *ServerService) TurnOffDEP(ctx context.Context, id string) error
- func (s *ServerService) Update(ctx context.Context, id string, allowCopy bool) UpdateResult
- func (s *ServerService) Verify(ctx context.Context, id string) core.Status
- func (s *ServerService) Version() string
- func (s *ServerService) WineStatus(ctx context.Context) core.WineStatus
- type SupportService
- func (s *SupportService) LogFrontendError(message string)
- func (s *SupportService) OpenLogs() error
- func (s *SupportService) ReportContents() []report.Item
- func (s *SupportService) SaveReport() (string, error)
- func (s *SupportService) SendReport(ctx context.Context, id, message, contact string) SendResult
- func (s *SupportService) ServerReport(ctx context.Context, id string) (*ServerReport, error)
- func (s *SupportService) ShowSavedReport(path string) error
- type UpdateProgress
- type UpdateResult
- type WineSetupResult
Constants ¶
const LinkScheme = "diablo2org"
LinkScheme is the URL scheme the installer registers, so a web page can link to diablo2org://add?profile=<https URL of a server profile>.
Variables ¶
var Version = "dev"
Version is set at build time with -ldflags "-X github.com/diablo2org/launcher/internal/app.Version=v1.2.3".
Functions ¶
func DevEnv ¶
DevEnv returns a development setting from the environment, or "" in a release build. Each one points the launcher at other servers or another certificate, or opens its page to other programs: what a developer testing the launcher wants, and nothing a player should have. One set on a release is logged and ignored.
func HandleLink ¶
func HandleLink(s *ServerService, raw string, running bool)
HandleLink takes a link the launcher was started with, or sent while running, and queues it until the frontend asks for it. running says the window is up, to be told and brought to the front. An empty link is ignored, and a link the same as the last one queued isn't queued twice. It isn't a ServerService method so the frontend can't call it.
func LinkArg ¶
LinkArg returns the first command line argument that is one of the launcher's links, or "". Windows passes a clicked link as an argument.
func ParseAddLink ¶
ParseAddLink returns the profile URL an add link names. Only the URL is checked here; nothing is fetched until the player agrees.
Types ¶
type BaseInstallRequest ¶
type BaseInstallRequest struct {
Version string `json:"version"`
Dir string `json:"dir"`
ClassicKey string `json:"classicKey"`
ExpansionKey string `json:"expansionKey"`
Owner string `json:"owner"`
}
BaseInstallRequest is the "Install Diablo II for me" form.
type BaseInstallResult ¶
type BaseInstallResult struct {
OK bool `json:"ok"`
// Installed is set once the game is installed, even if something after
// that failed: the folder is then an existing install, not one to
// install into again.
Installed bool `json:"installed"`
Cancelled bool `json:"cancelled"`
Error string `json:"error"`
// Warnings are notes on the keys, such as one that doesn't decode.
Warnings []string `json:"warnings"`
// CacheBytes is the download cache the install left, which the player
// can delete.
CacheBytes int64 `json:"cacheBytes"`
}
BaseInstallResult is how an install ended.
type Branding ¶
type Branding struct {
Logo string `json:"logo"`
Icon string `json:"icon"`
Background string `json:"background"`
}
Branding is a server's images as data URLs, ready for the page.
type CheckResult ¶
type CheckResult struct {
OK bool `json:"ok"`
Name string `json:"name"`
Problems []string `json:"problems"`
}
CheckResult is what the frontend shows after checking a profile.
type Host ¶
type Host struct {
// Emit sends an event to the frontend.
Emit func(name string, data any)
// PickFolder asks the player for a folder; "" means cancelled.
PickFolder func(title string) (string, error)
// Updates fetches release information; nil turns update checks off.
Updates *fetch.Client
// OpenFolder shows a folder in the file manager.
OpenFolder func(path string) error
// UpdatesDir is the launcher's own folder for downloaded installers.
UpdatesDir string
// RunInstaller applies a downloaded update (updates.Apply): starts the
// installer on Windows, swaps in the new app on macOS and Linux.
RunInstaller func(path string) error
// Quit closes the launcher.
Quit func()
// SaveFile asks where to save a file; "" means cancelled.
SaveFile func(title, name string) (string, error)
// ShowFile shows a file, selected, in the file manager.
ShowFile func(path string) error
// Focus brings the launcher's window to the front.
Focus func()
// OpenURL opens a page in the player's browser, such as a server's login.
OpenURL func(url string) error
}
Host is what the service needs from the app window.
type LauncherUpdateProgress ¶
LauncherUpdateProgress is sent as the "launcher:update" event while the new launcher downloads.
type LinkRequest ¶
type LinkRequest struct {
// URL is the profile the link asks to add.
URL string `json:"url"`
// Host is where that profile comes from, for the player to see.
Host string `json:"host"`
// Error says why the link can't be used; URL is then empty.
Error string `json:"error"`
}
LinkRequest is a link waiting for the player to agree to it.
type Overview ¶
type Overview struct {
Base string `json:"base"`
Report install.Report `json:"report"`
Warning string `json:"warning"`
BaseError string `json:"baseError"`
Servers []core.ServerInfo `json:"servers"`
Favourites []string `json:"favourites"`
Error string `json:"error"`
// FirstRun asks the page to show the welcome screen.
FirstRun bool `json:"firstRun"`
// Wine is whether the game runs under Wine here, and if it's ready.
Wine core.WineStatus `json:"wine"`
}
Overview is the launcher's starting state.
type ProfileService ¶
type ProfileService struct {
// contains filtered or unexported fields
}
ProfileService lets the frontend check server profiles.
func NewProfileService ¶
func NewProfileService(example []byte) *ProfileService
NewProfileService returns a service that offers example as a starting point.
func (*ProfileService) Check ¶
func (s *ProfileService) Check(profile string) CheckResult
Check parses a profile and reports every problem found.
func (*ProfileService) Example ¶
func (s *ProfileService) Example() string
Example returns the example SlashDiablo profile.
type SendResult ¶
type SendResult struct {
// ID is the server's reference for the report, to quote when asking
// about it.
ID string `json:"id"`
// Message is anything else the server said.
Message string `json:"message"`
// Error says why the report wasn't sent.
Error string `json:"error"`
// SavedTo is where the report was saved instead, so the player can send
// it by hand.
SavedTo string `json:"savedTo"`
}
SendResult is how sending a report went.
type ServerReport ¶
type ServerReport struct {
// Host is where it is sent, for the player to see.
Host string `json:"host"`
// MaxBytes is the most the server accepts; the files are trimmed to fit.
MaxBytes int `json:"maxBytes"`
Items []report.Item `json:"items"`
}
ServerReport is a bug report that goes to a server rather than being saved.
type ServerService ¶
type ServerService struct {
// contains filtered or unexported fields
}
ServerService is how the frontend drives the launcher.
func NewServerService ¶
func NewServerService(m *core.Manager, host Host) *ServerService
NewServerService wraps a manager for the frontend.
func (*ServerService) AddFromLink ¶
AddFromLink adds the server a link named, once the player has agreed, pins it if there is room, and returns its id. A server that is already listed is just opened.
func (*ServerService) AddServer ¶
AddServer adds a server that isn't listed, by the URL of its profile.
func (*ServerService) BaseSetup ¶
func (s *ServerService) BaseSetup() core.BaseSetup
BaseSetup describes installing the base game.
func (*ServerService) Branding ¶
func (s *ServerService) Branding(ctx context.Context, id string) Branding
Branding fetches a server's images. Missing or bad images are left empty; the tab falls back to its plain style.
func (*ServerService) CheckForUpdate ¶
func (s *ServerService) CheckForUpdate(ctx context.Context) *updates.Release
CheckForUpdate reports a newer launcher release, if there is one. Errors are swallowed: being offline shouldn't show as a problem.
func (*ServerService) ChooseBase ¶
func (s *ServerService) ChooseBase(ctx context.Context) (Overview, error)
ChooseBase lets the player pick their Diablo II folder.
func (*ServerService) ChooseInstallFolder ¶
func (s *ServerService) ChooseInstallFolder() (string, error)
ChooseInstallFolder asks where to install Diablo II. A folder that isn't empty gets a Diablo II folder made inside it. "" means cancelled.
func (*ServerService) ClearBaseCache ¶
func (s *ServerService) ClearBaseCache() error
ClearBaseCache deletes the base game's download cache.
func (*ServerService) FinishWelcome ¶
func (s *ServerService) FinishWelcome(pins []string) error
FinishWelcome pins the servers picked on the welcome screen and stops it showing again.
func (*ServerService) InstallBase ¶
func (s *ServerService) InstallBase(ctx context.Context, req BaseInstallRequest) BaseInstallResult
InstallBase installs the base game, sending base:progress events, and makes it the Diablo II folder. Cancelling the call stops it.
func (*ServerService) InstallRosetta ¶
func (s *ServerService) InstallRosetta(ctx context.Context) error
InstallRosetta installs Rosetta 2 through macOS's administrator prompt.
func (*ServerService) InstallUpdate ¶
func (s *ServerService) InstallUpdate(ctx context.Context) error
InstallUpdate downloads the newest launcher's update file, checks it against the release's SHA-256, applies it, and closes the launcher. On Windows the player then finishes the installer; on macOS and Linux the new launcher replaces this one and starts by itself.
func (*ServerService) LaunchDelay ¶
func (s *ServerService) LaunchDelay() int
LaunchDelay is the wait between boxes, in milliseconds.
func (*ServerService) LogIn ¶
LogIn opens the server's login page in the browser and waits for the player to finish there.
func (*ServerService) LogOut ¶
func (s *ServerService) LogOut(id string) error
LogOut forgets the server's login.
func (*ServerService) Login ¶
Choices returns the player's picks for a server. Login is the server's login: whether it needs one, and who is logged in.
func (*ServerService) OpenServerFolder ¶
func (s *ServerService) OpenServerFolder(id string) error
OpenServerFolder shows a server's folder, for dropping in custom files.
func (*ServerService) Overview ¶
func (s *ServerService) Overview(ctx context.Context) Overview
Overview loads the base install check and every server. On the first run it also brings across the old SlashDiablo launcher's settings, then finds the Diablo II folder from the registry if it still isn't known.
func (*ServerService) PendingLink ¶
func (s *ServerService) PendingLink() *LinkRequest
PendingLink returns the oldest link waiting for the player, once, or nil.
func (*ServerService) Play ¶
func (s *ServerService) Play(ctx context.Context, id string) error
Play starts the server.
func (*ServerService) RemoveServer ¶
func (s *ServerService) RemoveServer(id string) error
RemoveServer forgets a server added by URL.
func (*ServerService) SetChannel ¶
func (s *ServerService) SetChannel(ctx context.Context, id, channel string) error
SetChannel switches release channel.
func (*ServerService) SetComponent ¶
func (s *ServerService) SetComponent(ctx context.Context, id, component, version string) error
SetComponent turns a component on at a version, or off with "".
func (*ServerService) SetD2GLResolutions ¶
func (s *ServerService) SetD2GLResolutions(id, main, loader string) error
SetD2GLResolutions sets the main and loader box window sizes.
func (*ServerService) SetFavourite ¶
func (s *ServerService) SetFavourite(id string, on bool) error
SetFavourite pins or unpins a server.
func (*ServerService) SetFavouriteOrder ¶
func (s *ServerService) SetFavouriteOrder(ids []string) error
SetFavouriteOrder saves the pinned servers' order after the player drags them in the rail.
func (*ServerService) SetInstances ¶
SetInstances sets the number of boxes and d2gl profile splitting.
func (*ServerService) SetLaunchDelay ¶
func (s *ServerService) SetLaunchDelay(ms int) error
SetLaunchDelay changes the wait between boxes.
func (*ServerService) SetSetting ¶
SetSetting changes one setting.
func (*ServerService) Settings ¶
func (s *ServerService) Settings(ctx context.Context, id string) ([]core.SettingValue, error)
Settings returns a server's declared settings with their values.
func (*ServerService) SetupWine ¶
func (s *ServerService) SetupWine(ctx context.Context) WineSetupResult
SetupWine downloads Wine and makes the prefix as needed, sending wine:progress events. Cancelling the call stops it.
func (*ServerService) TurnOffDEP ¶
func (s *ServerService) TurnOffDEP(ctx context.Context, id string) error
TurnOffDEP turns DEP off for a server's Game.exe.
func (*ServerService) Update ¶
func (s *ServerService) Update(ctx context.Context, id string, allowCopy bool) UpdateResult
Update installs or updates a server.
func (*ServerService) Verify ¶
Verify hashes every file in a server's folder again and reports what an update would repair.
func (*ServerService) Version ¶
func (s *ServerService) Version() string
Version is the launcher's version, shown in the corner.
func (*ServerService) WineStatus ¶
func (s *ServerService) WineStatus(ctx context.Context) core.WineStatus
WineStatus is whether the game needs Wine here, and whether it's ready.
type SupportService ¶
type SupportService struct {
// contains filtered or unexported fields
}
SupportService is the frontend's way to logs and bug reports.
func NewSupportService ¶
NewSupportService gives the frontend the logs in st's data folder.
func (*SupportService) LogFrontendError ¶
func (s *SupportService) LogFrontendError(message string)
LogFrontendError records an error the page didn't handle.
func (*SupportService) OpenLogs ¶
func (s *SupportService) OpenLogs() error
OpenLogs shows the logs folder.
func (*SupportService) ReportContents ¶
func (s *SupportService) ReportContents() []report.Item
ReportContents lists what a bug report would hold, for the player to see before making one.
func (*SupportService) SaveReport ¶
func (s *SupportService) SaveReport() (string, error)
SaveReport asks where to save a bug report, writes it there and shows it. It returns the file, or "" if the player cancelled.
func (*SupportService) SendReport ¶
func (s *SupportService) SendReport(ctx context.Context, id, message, contact string) SendResult
SendReport sends a bug report to server id, with what the player wrote. If it can't be sent, it is saved in the launcher's reports folder instead.
func (*SupportService) ServerReport ¶
func (s *SupportService) ServerReport(ctx context.Context, id string) (*ServerReport, error)
ServerReport lists what a report sent to server id would hold. It returns nil when the server takes no reports, so the player saves one instead.
func (*SupportService) ShowSavedReport ¶
func (s *SupportService) ShowSavedReport(path string) error
ShowSavedReport shows a report that SendReport saved instead of sending.
type UpdateProgress ¶
type UpdateProgress struct {
Server string `json:"server"`
Progress sync.Progress `json:"progress"`
}
UpdateProgress is sent as the "update:progress" event while updating.
type UpdateResult ¶
type UpdateResult struct {
OK bool `json:"ok"`
// NeedsCopy asks the player whether to copy the game archives, using
// CopyBytes of disk space.
NeedsCopy bool `json:"needsCopy"`
CopyBytes int64 `json:"copyBytes"`
Error string `json:"error"`
}
UpdateResult tells the frontend how an update went.