diff --git a/app/app.go b/app/app.go new file mode 100644 index 0000000..830ce7f --- /dev/null +++ b/app/app.go @@ -0,0 +1,33 @@ +package app + +import ( + "encoding/json" + "path/filepath" + + "github.com/promignis/knack/constants" + "github.com/promignis/knack/fs" + "github.com/promignis/knack/utils" +) + +type Manifest struct { + AppName string +} + +var manifest Manifest + +func parseManifest() Manifest { + if manifest == (Manifest{}) { + root := utils.GetRootPath() + manifestData := fs.GetFileData(filepath.Join(root, constants.Manifest)) + json.Unmarshal(manifestData, &manifest) + } + return manifest +} + +func GetAppName() string { + return parseManifest().AppName +} + +func GetUserDataPath() string { + return globalSettingFolder +} diff --git a/app/config.windows.go b/app/config.windows.go new file mode 100644 index 0000000..19a4090 --- /dev/null +++ b/app/config.windows.go @@ -0,0 +1,6 @@ +package app + +import "os" + +var systemSettingFolders = []string{os.Getenv("PROGRAMDATA")} +var globalSettingFolder = os.Getenv("APPDATA") diff --git a/app/config_darwin.go b/app/config_darwin.go new file mode 100644 index 0000000..217aeeb --- /dev/null +++ b/app/config_darwin.go @@ -0,0 +1,6 @@ +package app + +import "os" + +var systemSettingFolders = []string{"/Library/Application Support"} +var globalSettingFolder = os.Getenv("HOME") + "/Library/Application Support" diff --git a/app/config_xdg.go b/app/config_xdg.go new file mode 100644 index 0000000..256c854 --- /dev/null +++ b/app/config_xdg.go @@ -0,0 +1,27 @@ +// +build !windows,!darwin + +package app + +import ( + "os" + "path/filepath" + "strings" +) + +// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html + +var systemSettingFolders []string +var globalSettingFolder string + +func init() { + if os.Getenv("XDG_CONFIG_HOME") != "" { + globalSettingFolder = os.Getenv("XDG_CONFIG_HOME") + } else { + globalSettingFolder = filepath.Join(os.Getenv("HOME"), ".config") + } + if os.Getenv("XDG_CONFIG_DIRS") != "" { + systemSettingFolders = strings.Split(os.Getenv("XDG_CONFIG_DIRS"), ":") + } else { + systemSettingFolders = []string{"/etc/xdg"} + } +} diff --git a/js-runtime/runtime.js b/js-runtime/runtime.js index efb4389..ed4d6b8 100644 --- a/js-runtime/runtime.js +++ b/js-runtime/runtime.js @@ -110,9 +110,10 @@ function FileWalker(filePath, cb) { this.filePath = filePath this.cbId = _runtime.getCbId(cb) - - this.fileStat = new FileStat(filePath, (fileStat) => { - this.fileStat = fileStat + // TODO: Add webpack instead of using _this so that arrow functions can be used in windows + _this = this + this.fileStat = new FileStat(filePath, function(fileStat, _this){ + _this.fileStat = fileStat }) this.walk() } @@ -128,7 +129,8 @@ function FileStat(filePath, cb) { } FileStat.prototype.getFileStat = function() { - sendAction({type: 'file_stat', filePath: this.filePath, callbackId: this.cbId}, (fileStat) => { - this.fileStat = fileStat + _this = this + sendAction({type: 'file_stat', filePath: this.filePath, callbackId: this.cbId}, function(fileStat){ + _this.fileStat = fileStat }) } diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..844e62f --- /dev/null +++ b/manifest.json @@ -0,0 +1,3 @@ +{ + "appName": "test-app" +} diff --git a/persistance/jsonPersistance.go b/persistance/jsonPersistance.go new file mode 100644 index 0000000..2829828 --- /dev/null +++ b/persistance/jsonPersistance.go @@ -0,0 +1,42 @@ +package persistance + +import ( + "os" + "path/filepath" + "sync" + + "github.com/promignis/knack/app" + "github.com/promignis/knack/fs" +) + +var lock sync.Mutex +var userdataFilePath = filepath.Join(app.GetUserDataPath(), "/", app.GetAppName()) + +func init() { + + // In case the directory does not exist , create it before we start creating files inside it + if _, err := os.Stat(userdataFilePath); os.IsNotExist(err) { + err = os.MkdirAll(userdataFilePath, os.ModePerm) + if err != nil { + panic(err) + } + } +} + +func Set(filename string, stringifiedJson string) { + // Putting this here so that read and write on the same file can not happen. Can be clenaed up in future. + lock.Lock() + defer lock.Unlock() + name := filename + ".json" + path := filepath.Join(userdataFilePath, name) + fs.WriteFileData(path, []byte(stringifiedJson)) +} + +func Get(filename string) string { + lock.Lock() + defer lock.Unlock() + name := filename + ".json" + path := filepath.Join(userdataFilePath, name) + stringifiedJson := fs.GetFileData(path) + return string(stringifiedJson) +} diff --git a/run-app-dev.bat b/run-app-dev.bat new file mode 100644 index 0000000..c9055ae --- /dev/null +++ b/run-app-dev.bat @@ -0,0 +1,2 @@ +go build -o output-dev.exe +output-dev.exe diff --git a/run-app.bat b/run-app.bat new file mode 100644 index 0000000..637aedb --- /dev/null +++ b/run-app.bat @@ -0,0 +1,2 @@ +go build -ldflags="-H windowsgui" -o output.exe +output.exe