Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
thororen1234 committed Jul 19, 2024
2 parents 570504d + ba544a6 commit 27fb1df
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 115 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ jobs:
name: Equilotl-windows
path: |
Equilotl.exe
Equilotl.exe
EquilotlCli.exe
release:
Expand Down Expand Up @@ -199,6 +199,6 @@ jobs:
prerelease: false
draft: false
files: |
linux/Equilotl-linux
linux/EquilotlCli-linux
macos/Equilotl.MacOS.zip
windows/Equilotl*.exe
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
vencordinstaller

equilotl
*.exe
*.syso
Expand Down
4 changes: 2 additions & 2 deletions app_asar.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ type asarEntry struct {

// Ported from https://github.com/GeopJr/asar-cr/blob/cd7695b7c913bf921d9fb6600eaeb1400e3ba225/src/asar-cr/pack.cr#L61

func WriteAppAsar(outFile string, patcherPath string) error {
func WriteAppAsar(outFile string, equicordAsarPath string) error {
header := make(map[string]map[string]asarEntry)
files := make(map[string]asarEntry)
header["files"] = files

fileContents := ""

patcherPathB, _ := json.Marshal(patcherPath)
patcherPathB, _ := json.Marshal(equicordAsarPath)
indexJsContents := "require(" + string(patcherPathB) + ")"
indexJsBytes := len([]byte(indexJsContents))
fileContents += indexJsContents
Expand Down
2 changes: 1 addition & 1 deletion cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func main() {

if *versionFlag {
fmt.Println("Equilotl Cli", buildinfo.InstallerTag, "("+buildinfo.InstallerGitHash+")")
fmt.Println("Copyright (C) 2023 Vendicated and Vencord contributors")
fmt.Println("Copyright (C) 2023 Equicord and contributors")
fmt.Println("License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.")
return
}
Expand Down
124 changes: 54 additions & 70 deletions github_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
package main

import (
"bufio"
"encoding/json"
"errors"
"io"
"net/http"
"os"
path "path/filepath"
"regexp"
"strconv"
"strings"
"sync"
)

type GithubRelease struct {
Expand Down Expand Up @@ -96,89 +94,75 @@ func InitGithubDownloader() {
}()

// Check hash of installed version if exists
f, err := os.Open(Patcher)
b, err := os.ReadFile(EquicordAsarPath)
if err != nil {
return
}
//goland:noinspection GoUnhandledErrorResult
defer f.Close()

Log.Debug("Found existing Equicord Install. Checking for hash...")
scanner := bufio.NewScanner(f)
if scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "// Equicord ") {
InstalledHash = line[11:]
Log.Debug("Existing hash is", InstalledHash)
} else {
Log.Debug("Didn't find hash")
}

re := regexp.MustCompile(`// Equicord (\w+)`)
match := re.FindSubmatch(b)
if match != nil {
InstalledHash = string(match[1])
Log.Debug("Existing hash is", InstalledHash)

} else {
Log.Debug("Didn't find hash")

}
}

func installLatestBuilds() (retErr error) {
Log.Debug("Installing latest builds...")

// create an empty package.json file in our files dir.
// without this, node will walk up the file tree and search for a package.json in the
// parent folders. This might lead to issues if the user for example has ~/package.json
// with type: "module" in it
pkgJsonFile := path.Join(FilesDir, "package.json")
err := os.WriteFile(pkgJsonFile, []byte("{}"), 0644)
if err != nil {
Log.Warn("Failed to create", pkgJsonFile, err)
downloadUrl := ""
for _, ass := range ReleaseData.Assets {
if ass.Name == "desktop.asar" {
downloadUrl = ass.DownloadURL
break
}
}

if downloadUrl == "" {
retErr = errors.New("Didn't find desktop.asar download link")
Log.Error(retErr)
return
}

var wg sync.WaitGroup
Log.Debug("Downloading desktop.asar")

for _, ass := range ReleaseData.Assets {
if strings.HasPrefix(ass.Name, "patcher.js") ||
strings.HasPrefix(ass.Name, "preload.js") ||
strings.HasPrefix(ass.Name, "renderer.js") ||
strings.HasPrefix(ass.Name, "renderer.css") {
wg.Add(1)
ass := ass // Need to do this to not have the variable be overwritten halfway through
go func() {
defer wg.Done()
Log.Debug("Downloading file", ass.Name)

res, err := http.Get(ass.DownloadURL)
if err == nil && res.StatusCode >= 300 {
err = errors.New(res.Status)
}
if err != nil {
Log.Error("Failed to download", ass.Name+":", err)
retErr = err
return
}
outFile := path.Join(FilesDir, ass.Name)
out, err := os.OpenFile(outFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
Log.Error("Failed to create", outFile+":", err)
retErr = err
return
}
read, err := io.Copy(out, res.Body)
if err != nil {
Log.Error("Failed to download to", outFile+":", err)
retErr = err
return
}
contentLength := res.Header.Get("Content-Length")
expected := strconv.FormatInt(read, 10)
if expected != contentLength {
err = errors.New("Unexpected end of input. Content-Length was " + contentLength + ", but I only read " + expected)
Log.Error(err.Error())
retErr = err
return
}
}()
}
res, err := http.Get(downloadUrl)
if err == nil && res.StatusCode >= 300 {
err = errors.New(res.Status)
}
if err != nil {
Log.Error("Failed to download desktop.asar:", err)
retErr = err
return
}
out, err := os.OpenFile(EquicordAsarPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
Log.Error("Failed to create", EquicordAsarPath+":", err)
retErr = err
return
}
read, err := io.Copy(out, res.Body)
if err != nil {
Log.Error("Failed to download to", EquicordAsarPath+":", err)
retErr = err
return
}
contentLength := res.Header.Get("Content-Length")
expected := strconv.FormatInt(read, 10)
if expected != contentLength {
err = errors.New("Unexpected end of input. Content-Length was " + contentLength + ", but I only read " + expected)
Log.Error(err.Error())
retErr = err
return
}

wg.Wait()
Log.Debug("Done!")
_ = FixOwnership(FilesDir)
_ = FixOwnership(EquicordAsarPath)

InstalledHash = LatestHash
return
Expand Down
25 changes: 3 additions & 22 deletions gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,21 +272,6 @@ func makeRadioOnChange(i int) func() {
}
}

func renderFilesDirErr() g.Widget {
return g.Layout{
g.Dummy(0, 50),
g.Style().
SetColor(g.StyleColorText, DiscordRed).
SetFontSize(30).
To(
g.Align(g.AlignCenter).To(
g.Label("Error: Failed to create: "+FilesDirErr.Error()),
g.Label("Resolve this error, then restart me!"),
),
),
}
}

func Tooltip(label string) g.Widget {
return g.Style().
SetStyle(g.StyleVarWindowPadding, 10, 8).
Expand Down Expand Up @@ -644,13 +629,13 @@ func loop() {
g.Dummy(0, 20),
g.Style().SetFontSize(20).To(
g.Row(
g.Label(Ternary(IsDevInstall, "Dev Install: ", "Files will be downloaded to: ")+FilesDir),
g.Label(Ternary(IsDevInstall, "Dev Install: ", "Equicord will be downloaded to: ")+EquicordAsarPath),
g.Style().
SetColor(g.StyleColorButton, DiscordBlue).
SetStyle(g.StyleVarFramePadding, 4, 4).
To(
g.Button("Open Directory").OnClick(func() {
g.OpenURL("file://" + FilesDir)
g.OpenURL("file://" + path.Dir(EquicordAsarPath))
}),
),
),
Expand All @@ -673,11 +658,7 @@ func loop() {
},
),

&CondWidget{
predicate: FilesDirErr != nil,
ifWidget: renderFilesDirErr,
elseWidget: renderInstaller,
},
renderInstaller(),
)

g.PopStyle()
Expand Down
30 changes: 13 additions & 17 deletions patcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ package main

import (
"errors"
"github.com/ProtonMail/go-appdir"
"os"
"os/exec"
path "path/filepath"
"strings"

"github.com/ProtonMail/go-appdir"
)

var BaseDir string
var FilesDir string
var FilesDirErr error
var Patcher string
var EquicordAsarPath string

func init() {
if dir := os.Getenv("EQUICORD_USER_DATA_DIR"); dir != "" {
Expand All @@ -31,16 +30,13 @@ func init() {
Log.Debug("Using UserConfig")
BaseDir = appdir.New("Equicord").UserConfig()
}
FilesDir = path.Join(BaseDir, "dist")
if !ExistsFile(FilesDir) {
FilesDirErr = os.MkdirAll(FilesDir, 0755)
if FilesDirErr != nil {
Log.Error("Failed to create", FilesDir, FilesDirErr)
} else {
FilesDirErr = FixOwnership(BaseDir)
}

if dir := os.Getenv("EQUICORD_ASAR_FILE"); dir != "" {
Log.Debug("Using EQUICORD_ASAR_FILE")
EquicordAsarPath = dir
} else {
EquicordAsarPath = path.Join(BaseDir, "equicord.asar")
}
Patcher = path.Join(FilesDir, "patcher.js")
}

type DiscordInstall struct {
Expand Down Expand Up @@ -92,7 +88,7 @@ func patchAppAsar(dir string, isSystemElectron bool) (err error) {
}

Log.Debug("Writing custom app.asar to", appAsar)
if err := WriteAppAsar(appAsar, Patcher); err != nil {
if err := WriteAppAsar(appAsar, EquicordAsarPath); err != nil {
return err
}

Expand Down Expand Up @@ -142,14 +138,14 @@ func (di *DiscordInstall) patch() error {
}
}

Log.Debug("This is a flatpak. Trying to grant the Flatpak access to", FilesDir+"...")
Log.Debug("This is a flatpak. Trying to grant the Flatpak access to", EquicordAsarPath+"...")

isSystemFlatpak := strings.HasPrefix(di.path, "/var")
var args []string
if !isSystemFlatpak {
args = append(args, "--user")
}
args = append(args, "override", name, "--filesystem="+FilesDir)
args = append(args, "override", name, "--filesystem="+EquicordAsarPath)
fullCmd := "flatpak " + strings.Join(args, " ")

Log.Debug("Running", fullCmd)
Expand All @@ -170,7 +166,7 @@ func (di *DiscordInstall) patch() error {
err = cmd.Run()
}
if err != nil {
return errors.New("Failed to grant Discord Flatpak access to " + FilesDir + ": " + err.Error())
return errors.New("Failed to grant Discord Flatpak access to " + EquicordAsarPath + ": " + err.Error())
}
}
return nil
Expand Down

0 comments on commit 27fb1df

Please sign in to comment.