Skip to content

Commit

Permalink
Osx support
Browse files Browse the repository at this point in the history
  • Loading branch information
p1ratrulezzz committed May 21, 2022
1 parent 91017d6 commit 5c6f64f
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 34 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ require (
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
howett.net/plist v1.0.0 // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ github.com/inancgumus/screen v0.0.0-20190314163918-06e984b86ed3 h1:fO9A67/izFYFY
github.com/inancgumus/screen v0.0.0-20190314163918-06e984b86ed3/go.mod h1:Ey4uAp+LvIl+s5jRbOHLcZpUDnkjLBROl15fZLwPlTM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jackmordaunt/icns v0.0.0-20181231085925-4f16af745526/go.mod h1:UQkeMHVoNcyXYq9otUupF7/h/2tmHlhrS2zw7ZVvUqc=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/josephspurrier/goversioninfo v0.0.0-20200309025242-14b0ab84c6ca/go.mod h1:eJTEwMjXb7kZ633hO3Ln9mBUCOjX2+FlTljvpl9SYdE=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
Expand Down Expand Up @@ -400,6 +401,7 @@ gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand All @@ -414,5 +416,7 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
howett.net/plist v1.0.0 h1:7CrbWYbPPO/PyNy38b2EB/+gYbjCe2DXBxgtOOZbSQM=
howett.net/plist v1.0.0/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
21 changes: 11 additions & 10 deletions src/app/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ import (
)

var KeyList = map[string]string{
"appcode": "AppCode",
"clion": "Clion",
"datagrip": "Datagrip",
"goland": "GoLand",
"idea": "Idea",
"phpstorm": "PhpStorm",
"pycharm": "PyCharm",
"rider": "Rider",
"rubymine": "RubyMine",
"webstorm": "WebStorm",
"appcode": "AppCode",
"clion": "Clion",
"datagrip": "Datagrip",
"dataspell": "DataSpell",
"goland": "GoLand",
"idea": "Idea",
"phpstorm": "PhpStorm",
"pycharm": "PyCharm",
"rider": "Rider",
"rubymine": "RubyMine",
"webstorm": "WebStorm",
}

var KeyListSlugIndexed, KeyListNameIndexed []string
Expand Down
13 changes: 8 additions & 5 deletions src/app/menuloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"github.com/inancgumus/screen"
"reflect"
"sort"
"strconv"
)
Expand All @@ -21,8 +20,12 @@ func menu_loop() {
ITEM_EXIT: "Exit",
}

itemsKeys := reflect.ValueOf(items).MapKeys()
sort.SliceStable(itemsKeys, func(i, j int) bool {
var itemKeysIndex []byte
for i, _ := range items {
itemKeysIndex = append(itemKeysIndex, i)
}

sort.SliceStable(itemKeysIndex, func(i, j int) bool {
return i < j
})

Expand All @@ -32,8 +35,8 @@ func menu_loop() {
screen.Clear()
screen.MoveTopLeft()

for _, i := range itemsKeys {
fmt.Printf("%d. %s\n", i, items[byte(i.Uint())])
for _, i := range itemKeysIndex {
fmt.Printf("%d. %s\n", i, items[i])
}

var inbuf []byte
Expand Down
21 changes: 11 additions & 10 deletions src/patchers/abstract.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,17 @@ func (p *PatcherToolAbstract) GetExeList() *map[string]string {
}

var exeList = map[string]string{
"appcode": "AppCode",
"clion": "Clion",
"datagrip": "Datagrip",
"goland": "GoLand",
"idea": "Idea",
"phpstorm": "PhpStorm",
"pycharm": "PyCharm",
"rider": "Rider",
"rubymine": "RubyMine",
"webstorm": "WebStorm",
"appcode": "AppCode",
"clion": "Clion",
"datagrip": "Datagrip",
"dataspell": "DataSpell",
"goland": "GoLand",
"idea": "Idea",
"phpstorm": "PhpStorm",
"pycharm": "PyCharm",
"rider": "Rider",
"rubymine": "RubyMine",
"webstorm": "WebStorm",
}

exeListPtr = &exeList
Expand Down
81 changes: 81 additions & 0 deletions src/patchers/darwin.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,98 @@
package patchers

import (
"github.com/shirou/gopsutil/process"
"howett.net/plist"
"os"
"path/filepath"
"regexp"
)

type PatcherToolDarwin struct {
*PatcherToolAbstract
}

type ProductInfoPlist struct {
JVMOptions map[string]interface{} `plist:"JVMOptions"`
}

func (p *PatcherToolDarwin) FindVmoptionsFiles() []string {
homeDir, _ := os.UserHomeDir()
configDir := p.GetAppdataDir()
files := findVmoptionsFiles([]string{homeDir + "/Applications", "/Applications", configDir + "/Jetbrains/Toolbox"})

return files
}

func (p *PatcherToolDarwin) parsePlist(path string) (*ProductInfoPlist, error) {
file, err := os.OpenFile(path, os.O_RDONLY, 0744)
if err != nil {
return nil, err
}

decoder := plist.NewDecoder(file)
var infoPlist ProductInfoPlist
err = decoder.Decode(&infoPlist)
if err != nil {
return nil, err
}

return &infoPlist, nil
}

func (p *PatcherToolDarwin) FindVmoptionsFromProcesses() []ProductInfo {
var infos []ProductInfo

var exeList = *p.GetExeList()
reList := make(map[string]*regexp.Regexp)
for product, _ := range exeList {
re := regexp.MustCompile(`(?i)\.app/Contents/MacOS/` + product + "$")
reList[product] = re
}

pids, _ := process.Pids()
for _, pid := range pids {
proc, _ := process.NewProcess(pid)
exeNameConst, err := proc.Exe()
if err != nil {
continue
}

for product, re := range reList {
if re.MatchString(exeNameConst) {
productPath, _ := filepath.Abs(filepath.Join(exeNameConst, "../../"))
appFolderName, _ := filepath.Abs(filepath.Join(productPath, "../"))
toolboxVmoptionsPath := appFolderName + ".vmoptions"
plistPath := filepath.Join(productPath, "Info.plist")
plistInfo, err := p.parsePlist(plistPath)
if err != nil {
break
}

properties := plistInfo.JVMOptions["Properties"].(map[string]interface{})
pathSelector := properties["idea.paths.selector"].(string)

var info ProductInfo
info.ProductSlug = product
info.ProductName = exeList[product]
info.ProductFolder = productPath
info.VmoptionsSourcePath = filepath.Join(productPath, "bin", product+".vmoptions")
info.VmoptionsDestinationPath = filepath.Join(p.GetAppdataDir(), "JetBrains", pathSelector)

if !p.FileExists(info.VmoptionsSourcePath) {
break
}

if p.FileExists(toolboxVmoptionsPath) {
info.VmoptionsSourcePath = toolboxVmoptionsPath
info.VmoptionsDestinationPath = ""
}

infos = append(infos, info)
break
}
}
}

return infos
}
12 changes: 3 additions & 9 deletions src/patchers/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ type PatcherToolWindows struct {
*PatcherToolAbstract
}

type ProductInfoJsonLaunch struct {
VmOptionsFilePath string
}

type ProductInfoJson struct {
BuildNumber string
DataDirectoryName string
Name string
Launch []ProductInfoJsonLaunch
Launch []map[string]string `json:"launch"`
}

func (p *PatcherToolWindows) FindVmoptionsFiles() []string {
Expand Down Expand Up @@ -55,8 +51,6 @@ func (p *PatcherToolWindows) parseProductInfoJson(path string) (*ProductInfoJson
return nil, err
}

_ = err

return &dest, nil
}

Expand Down Expand Up @@ -95,12 +89,12 @@ func (p *PatcherToolWindows) FindVmoptionsFromProcesses() []ProductInfo {
}

infoJson, err := p.parseProductInfoJson(productInfoFilePath)
if err != nil || len(infoJson.Launch) == 0 {
if err != nil && len(infoJson.Launch) == 0 {
continue
}

var info ProductInfo
info.VmoptionsSourcePath = filepath.Join(productPath, infoJson.Launch[0].VmOptionsFilePath)
info.VmoptionsSourcePath = filepath.Join(productPath, infoJson.Launch[0]["vmOptionsFilePath"])
info.VmoptionsDestinationPath = filepath.Join(p.GetAppdataDir(), "JetBrains", infoJson.DataDirectoryName)
info.ProductFolder = infoJson.DataDirectoryName
info.ProductName = infoJson.Name
Expand Down

0 comments on commit 5c6f64f

Please sign in to comment.