switch go go-fpw --app mode instead

This commit is contained in:
idk
2022-10-19 23:54:27 -04:00
parent df2721a264
commit d82e11d081
4 changed files with 5 additions and 124 deletions

2
go.mod
View File

@ -4,7 +4,7 @@ go 1.19
require (
github.com/artdarek/go-unzip v1.0.0
github.com/eyedeekay/go-fpw v0.0.0-20221005063555-6b2eaf1b4a9c
github.com/eyedeekay/go-fpw v0.0.0-20221020035017-28fb80249c64
github.com/google/go-github v17.0.0+incompatible
)

4
go.sum
View File

@ -1,5 +1,5 @@
github.com/eyedeekay/go-fpw v0.0.0-20221005063555-6b2eaf1b4a9c h1:KduHw99EIyMIR5s5+gzQu3sqDNTo2DsG0fBYqeJANQk=
github.com/eyedeekay/go-fpw v0.0.0-20221005063555-6b2eaf1b4a9c/go.mod h1:OZD3uVWaZcd9uKc7JyZHXfFpEwkMg09EfcHmYjenVRw=
github.com/eyedeekay/go-fpw v0.0.0-20221020035017-28fb80249c64 h1:qEWwyrmY15uYX2a0o0vxspNKf2sho9eQkwatmWDIA/w=
github.com/eyedeekay/go-fpw v0.0.0-20221020035017-28fb80249c64/go.mod h1:OZD3uVWaZcd9uKc7JyZHXfFpEwkMg09EfcHmYjenVRw=
github.com/eyedeekay/go-unzip v0.0.0-20220914222511-f2936bba53c2 h1:2ugjFSEUAduRk1lp5dSw19771HTZL8e37QSXjiiC7P4=
github.com/eyedeekay/go-unzip v0.0.0-20220914222511-f2936bba53c2/go.mod h1:LRwT8AnFFHRm/oj++niZMHsi3o4rNDr1lN61xwHgFgI=
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=

4
run.go
View File

@ -53,12 +53,12 @@ func BrowseUsability(profileDir string, url ...string) {
func BrowseApp(profileDir string, url ...string) {
var profilePath string
var err error
profilePath, err = UnpackApp(profileDir)
profilePath, err = UnpackUsability(profileDir)
if err != nil {
log.Println(err)
return
}
FIREFOX, ERROR := fcw.BasicFirefox(profilePath, false, url...)
FIREFOX, ERROR := fcw.WebAppFirefox(profilePath, false, url...)
if ERROR != nil {
log.Println(ERROR)
return

View File

@ -5,7 +5,6 @@ import (
"log"
"os"
"path/filepath"
"strings"
"github.com/artdarek/go-unzip/pkg/unzip"
)
@ -54,121 +53,3 @@ func UnpackUsability(profileDir string) (string, error) {
}
return filepath.Join(profileDir, "i2p.firefox.usability.profile"), nil
}
// UnpackApp unpacks a "App" mode profile into the "profileDir" and returns the
// path to the profile and possibly, an error if something goes wrong. If everything
// works, the error will be nil
func UnpackApp(profileDir string) (string, error) {
log.Println(profileDir, "exists already")
os.MkdirAll(filepath.Dir(profileDir), 0755)
zipFile := filepath.Join(filepath.Dir(profileDir), "i2p.firefox.usability.profile.zip")
err := ioutil.WriteFile(zipFile, UsabilityProfile, 0644)
if err != nil {
return filepath.Join(profileDir, "i2p.firefox.app.profile"), err
}
uz := unzip.New()
_, err = uz.Extract(zipFile, profileDir)
unzippedFiles := strings.Replace(filepath.Join(profileDir, "i2p.firefox.usability.profile.zip"), ".zip", "", 1)
if !existsAlready(filepath.Join(profileDir, "i2p.firefox.app.profile")) {
if err = os.Rename(unzippedFiles, filepath.Join(profileDir, "i2p.firefox.app.profile")); err != nil {
return filepath.Join(profileDir, "i2p.firefox.app.profile"), err
}
}
if err := os.MkdirAll(filepath.Join(profileDir, "i2p.firefox.app.profile", "chrome"), 0755); err != nil {
return filepath.Join(profileDir, "i2p.firefox.app.profile"), err
}
if err := ForceUserChromeCSS(filepath.Join(profileDir, "i2p.firefox.app.profile", "chrome", "userChrome.css")); err != nil {
return filepath.Join(profileDir, "i2p.firefox.app.profile"), err
}
if err := AppifyUserJS(filepath.Join(profileDir, "i2p.firefox.app.profile", "user-overrides.js")); err != nil {
return filepath.Join(profileDir, "i2p.firefox.app.profile"), err
}
if err := AppifyUserJS(filepath.Join(profileDir, "i2p.firefox.app.profile", "user.js")); err != nil {
return filepath.Join(profileDir, "i2p.firefox.app.profile"), err
}
if err := AppifyUserJS(filepath.Join(profileDir, "i2p.firefox.app.profile", "prefs.js")); err != nil {
return filepath.Join(profileDir, "i2p.firefox.app.profile"), err
}
return filepath.Join(profileDir, "i2p.firefox.app.profile"), nil
}
func AppifyUserJS(profile string) error {
content, err := ioutil.ReadFile(profile)
if err != nil {
return err
}
lines := strings.Split(string(content), "\n")
for i, line := range lines {
if strings.Contains(line, "toolkit.legacyUserProfileCustomizations.stylesheets\"") {
if strings.Contains(line, "true") {
return nil
} else {
line = strings.Replace(line, "false", "true", 1)
}
}
lines[i] = line
}
out := strings.Join(lines, "\n")
if err := ioutil.WriteFile(profile, []byte(out), 0644); err != nil {
return err
}
return nil
}
func ForceUserChromeCSS(profile string) error {
var userChrome = `@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
/* only needed once */
@namespace html url("http://www.w3.org/1999/xhtml");
#PersonalToolbar,
#PanelUI-Button,
#PanelUI-menu-button,
#star-button,
#forward-button,
#home-button,
#bookmarks-toolbar-button,
#library-button,
#sidebar-button,
#pocket-button,
#fxa-toolbar-menu-button,
#reader-mode-button,
#identity-icon {
visibility: collapse;
}
#urlbar-background {
background-color: black !important;
}
/* Remove back button circle */
#back-button:not(:hover),
#back-button:not(:hover)>.toolbarbutton-icon {
background: transparent !important;
border: none !important;
box-shadow: none !important;
}
#back-button:hover,
#back-button:hover>.toolbarbutton-icon {
border: none !important;
border-radius: 2px !important;
}
#urlbar-container {
visibility: collapse !important
}
#TabsToolbar-customization-target {
min-width: 50vw;
max-width: 50vw;
width: 50vw;
}
`
if err := ioutil.WriteFile(profile, []byte(userChrome), 0644); err != nil {
return err
}
return nil
}