Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert from Electron to Wails #381

Draft
wants to merge 4 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ dist/
node_modules/
thumbs.db
.idea/
app/
app/
build/bin
39 changes: 0 additions & 39 deletions .yarnclean

This file was deleted.

Binary file removed assets/images/splash.bmp
Binary file not shown.
40 changes: 40 additions & 0 deletions backend/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package backend

import (
"context"
"runtime"
)

// var dialogs = NewDialogManager()
// var paths = NewPathManager()

// App struct
type Backend struct {
ctx context.Context
dialogs *Dialogs
paths *Paths
}

// NewApp creates a new App application struct
func CreateBackend() *Backend {
created := &Backend{}
created.dialogs = NewDialogManager()
created.paths = NewPathManager()
return created
}

// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (d *Backend) SetContext(ctx context.Context) {
d.ctx = ctx
d.dialogs.SetContext(ctx)
d.paths.SetContext(ctx)
}

func (d *Backend) GetModules() []interface{} {
return []interface{}{d.dialogs, d.paths}
}

func (d *Backend) GetPlatform() string {
return runtime.GOOS
}
75 changes: 75 additions & 0 deletions backend/dialogs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package backend

import (
"context"
"installer/backend/utils"

"github.com/wailsapp/wails/v2/pkg/runtime"
)

// App struct
type Dialogs struct {
ctx context.Context
}

// NewApp creates a new App application struct
func NewDialogManager() *Dialogs {
return &Dialogs{}
}

// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (d *Dialogs) SetContext(ctx context.Context) {
d.ctx = ctx
}

// Greet returns a greeting for the given name
func (d *Dialogs) BrowseForDiscord(channel string) string {
selection, err := runtime.OpenDirectoryDialog(d.ctx, runtime.OpenDialogOptions{
Title: "Browsing to " + utils.GetChannelName(channel),
DefaultDirectory: utils.BrowsePath(channel),
ShowHiddenFiles: true,
TreatPackagesAsDirectories: true,
})

if err != nil || selection == "" {
return ""
}

return utils.ValidatePath(selection)
}

func (d *Dialogs) ConfirmAction(title string, message string) string {
result, err := runtime.MessageDialog(d.ctx, runtime.MessageDialogOptions{
Type: runtime.QuestionDialog,
Title: title,
Message: message,
DefaultButton: "No",
})

if err != nil {
return ""
}

return result
}

func (d *Dialogs) ShowNotice(dialog string, title string, message string) string {

dialogType := runtime.InfoDialog
if dialog == "error" {
dialogType = runtime.ErrorDialog
}

result, err := runtime.MessageDialog(d.ctx, runtime.MessageDialogOptions{
Type: dialogType,
Title: title,
Message: message,
})

if err != nil {
return ""
}

return result
}
27 changes: 27 additions & 0 deletions backend/paths.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package backend

import (
"context"

"installer/backend/utils"
)

// App struct
type Paths struct {
ctx context.Context
}

// NewApp creates a new App application struct
func NewPathManager() *Paths {
return &Paths{}
}

// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (d *Paths) SetContext(ctx context.Context) {
d.ctx = ctx
}

func (d *Paths) GetDiscordPath(channel string) string {
return utils.DiscordPath(channel)
}
90 changes: 90 additions & 0 deletions backend/utils/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package utils

import (
"time"
)

type Release struct {
URL string `json:"url"`
AssetsURL string `json:"assets_url"`
UploadURL string `json:"upload_url"`
HTMLURL string `json:"html_url"`
ID int `json:"id"`
Author struct {
Login string `json:"login"`
ID int `json:"id"`
NodeID string `json:"node_id"`
AvatarURL string `json:"avatar_url"`
GravatarID string `json:"gravatar_id"`
URL string `json:"url"`
HTMLURL string `json:"html_url"`
FollowersURL string `json:"followers_url"`
FollowingURL string `json:"following_url"`
GistsURL string `json:"gists_url"`
StarredURL string `json:"starred_url"`
SubscriptionsURL string `json:"subscriptions_url"`
OrganizationsURL string `json:"organizations_url"`
ReposURL string `json:"repos_url"`
EventsURL string `json:"events_url"`
ReceivedEventsURL string `json:"received_events_url"`
Type string `json:"type"`
SiteAdmin bool `json:"site_admin"`
} `json:"author"`
NodeID string `json:"node_id"`
TagName string `json:"tag_name"`
TargetCommitish string `json:"target_commitish"`
Name string `json:"name"`
Draft bool `json:"draft"`
Prerelease bool `json:"prerelease"`
CreatedAt time.Time `json:"created_at"`
PublishedAt time.Time `json:"published_at"`
Assets []struct {
URL string `json:"url"`
ID int `json:"id"`
NodeID string `json:"node_id"`
Name string `json:"name"`
Label interface{} `json:"label"`
Uploader struct {
Login string `json:"login"`
ID int `json:"id"`
NodeID string `json:"node_id"`
AvatarURL string `json:"avatar_url"`
GravatarID string `json:"gravatar_id"`
URL string `json:"url"`
HTMLURL string `json:"html_url"`
FollowersURL string `json:"followers_url"`
FollowingURL string `json:"following_url"`
GistsURL string `json:"gists_url"`
StarredURL string `json:"starred_url"`
SubscriptionsURL string `json:"subscriptions_url"`
OrganizationsURL string `json:"organizations_url"`
ReposURL string `json:"repos_url"`
EventsURL string `json:"events_url"`
ReceivedEventsURL string `json:"received_events_url"`
Type string `json:"type"`
SiteAdmin bool `json:"site_admin"`
} `json:"uploader"`
ContentType string `json:"content_type"`
State string `json:"state"`
Size int `json:"size"`
DownloadCount int `json:"download_count"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
BrowserDownloadURL string `json:"browser_download_url"`
} `json:"assets"`
TarballURL string `json:"tarball_url"`
ZipballURL string `json:"zipball_url"`
Body string `json:"body"`
Reactions struct {
URL string `json:"url"`
TotalCount int `json:"total_count"`
Num1 int `json:"+1"`
Num10 int `json:"-1"`
Laugh int `json:"laugh"`
Hooray int `json:"hooray"`
Confused int `json:"confused"`
Heart int `json:"heart"`
Rocket int `json:"rocket"`
Eyes int `json:"eyes"`
} `json:"reactions"`
}
46 changes: 46 additions & 0 deletions backend/utils/channels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package utils

import (
"runtime"
"strings"
)

func GetChannelName(channel string) string {
switch strings.ToLower(channel) {
case "stable":
return "Discord"
case "canary":
return "DiscordCanary"
case "ptb":
return "DiscordPTB"
default:
return ""
}
}

func GetExecutableName(channel string) string {
var name string
switch strings.ToLower(channel) {
case "stable":
name = "Discord"
case "canary":
name = "Discord Canary"
case "ptb":
name = "Discord PTB"
default:
name = ""
}

if name == "" {
return name
}

switch op := runtime.GOOS; op {
case "windows":
name = name + ".exe"
case "darwin", "linux":
name = strings.ReplaceAll(name, " ", "")
}

return name
}
Loading