Skip to content

Commit

Permalink
don't use asar in dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Vendicated committed Jul 19, 2024
1 parent ba544a6 commit 9f8a013
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .idea/VencordInstaller.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 24 additions & 5 deletions github_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"io"
"net/http"
"os"
path "path/filepath"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -110,8 +111,21 @@ func InitGithubDownloader() {
Log.Debug("Latest hash is", LatestHash, "Local Install is", Ternary(LatestHash == InstalledHash, "up to date!", "outdated!"))
}()

// either .asar file or directory with main.js file (in DEV)
VencordFile := VencordDirectory

stat, err := os.Stat(VencordFile)
if err != nil {
return
}

// dev
if stat.IsDir() {
VencordFile = path.Join(VencordFile, "main.js")
}

// Check hash of installed version if exists
b, err := os.ReadFile(VencordAsarPath)
b, err := os.ReadFile(VencordFile)
if err != nil {
return
}
Expand All @@ -133,6 +147,11 @@ func InitGithubDownloader() {
func installLatestBuilds() (retErr error) {
Log.Debug("Installing latest builds...")

if IsDevInstall {
Log.Debug("Skipping due to dev install")
return
}

downloadUrl := ""
for _, ass := range ReleaseData.Assets {
if ass.Name == "desktop.asar" {
Expand All @@ -158,15 +177,15 @@ func installLatestBuilds() (retErr error) {
retErr = err
return
}
out, err := os.OpenFile(VencordAsarPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
out, err := os.OpenFile(VencordDirectory, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
Log.Error("Failed to create", VencordAsarPath+":", err)
Log.Error("Failed to create", VencordDirectory+":", err)
retErr = err
return
}
read, err := io.Copy(out, res.Body)
if err != nil {
Log.Error("Failed to download to", VencordAsarPath+":", err)
Log.Error("Failed to download to", VencordDirectory+":", err)
retErr = err
return
}
Expand All @@ -179,7 +198,7 @@ func installLatestBuilds() (retErr error) {
return
}

_ = FixOwnership(VencordAsarPath)
_ = FixOwnership(VencordDirectory)

InstalledHash = LatestHash
return
Expand Down
18 changes: 9 additions & 9 deletions patcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

var BaseDir string
var VencordAsarPath string
var VencordDirectory string

func init() {
if dir := os.Getenv("VENCORD_USER_DATA_DIR"); dir != "" {
Expand All @@ -30,11 +30,11 @@ func init() {
BaseDir = appdir.New("Vencord").UserConfig()
}

if dir := os.Getenv("VENCORD_ASAR_FILE"); dir != "" {
Log.Debug("Using VENCORD_ASAR_FILE")
VencordAsarPath = dir
if dir := os.Getenv("VENCORD_DIRECTORY"); dir != "" {
Log.Debug("Using VENCORD_DIRECTORY")
VencordDirectory = dir
} else {
VencordAsarPath = path.Join(BaseDir, "vencord.asar")
VencordDirectory = path.Join(BaseDir, "vencord.asar")
}
}

Expand Down Expand Up @@ -87,7 +87,7 @@ func patchAppAsar(dir string, isSystemElectron bool) (err error) {
}

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

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

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

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

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

0 comments on commit 9f8a013

Please sign in to comment.