used typescript the way its supposed to be used
This commit is contained in:
parent
4590e90037
commit
a8dc524e6a
7 changed files with 330 additions and 332 deletions
61
src/main/base/utils.ts
Normal file
61
src/main/base/utils.ts
Normal file
|
@ -0,0 +1,61 @@
|
|||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import {jsonc} from "jsonc";
|
||||
import {Store} from "./store";
|
||||
import {BrowserWindow as bw} from "./browserwindow";
|
||||
|
||||
export class utils {
|
||||
|
||||
/**
|
||||
* Fetches the i18n locale for the given language.
|
||||
* @param language {string} The language to fetch the locale for.
|
||||
* @param key {string} The key to search for.
|
||||
* @returns {string | Object} The locale value.
|
||||
*/
|
||||
static getLocale(language: string, key?: string): string | object {
|
||||
let i18n: { [index: string]: Object } = jsonc.parse(fs.readFileSync(path.join(__dirname, "../../src/i18n/en_US.jsonc"), "utf8"));
|
||||
|
||||
if (language !== "en_US" && fs.existsSync(path.join(__dirname, `../../src/i18n/${language}.jsonc`))) {
|
||||
i18n = Object.assign(i18n, jsonc.parse(fs.readFileSync(path.join(__dirname, `../../src/i18n/${language}.jsonc`), "utf8")));
|
||||
}
|
||||
|
||||
if (key) {
|
||||
return i18n[key]
|
||||
} else {
|
||||
return i18n
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a store value
|
||||
* @param key
|
||||
* @returns store value
|
||||
*/
|
||||
static getStoreValue(key: string): any {
|
||||
return Store.cfg.get(key)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a store
|
||||
* @returns store
|
||||
*/
|
||||
static getStore(): Object {
|
||||
return Store.cfg.store
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a store value
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
static setStoreValue(key: string, value: any): void {
|
||||
Store.cfg.set(key, value)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the browser window
|
||||
*/
|
||||
static getWindow(): Electron.BrowserWindow {
|
||||
return bw.win
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue