Skip to content

Commit

Permalink
fix: use electron-store
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jul 10, 2019
1 parent deacdbd commit 8d71775
Show file tree
Hide file tree
Showing 16 changed files with 159 additions and 178 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ app/out
_gsdata_/

/.idea/workspace.xml
/.idea/shelf/
/out/
Empty file modified build/icons/1024x1024.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified build/icons/128x128.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified build/icons/16x16.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified build/icons/24x24.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified build/icons/256x256.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified build/icons/32x32.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified build/icons/48x48.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified build/icons/512x512.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified build/icons/64x64.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified build/icons/96x96.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
}
},
"dependencies": {
"configstore": "^5.0.0",
"electron-store": "^4.0.0",
"electron-debug": "^3.0.0",
"electron-is-dev": "^1.1.0",
"electron-log": "^3.0.6",
Expand All @@ -53,7 +53,7 @@
"devDependencies": {
"@types/debug": "^4.1.4",
"electron": "5.0.6",
"electron-builder": "^21.0.3",
"electron-builder": "^21.0.14",
"rimraf": "^2.6.3",
"typescript": "^3.5.2"
}
Expand Down
47 changes: 14 additions & 33 deletions src/StateManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import * as os from "os"
import * as path from "path"
import ConfigStore = require("configstore")
import { isDev } from "./util"
import * as ConfigStore from "electron-store"

export const DEFAULT_URL = "https://cad.onshape.com/"

Expand All @@ -12,47 +9,31 @@ function defaultWindows() {
}

export class StateManager {
private store = new ConfigStore("onshape-unofficial", {windows: defaultWindows()})
private store = new ConfigStore()

private data: Config

constructor() {
if (os.platform() == "darwin") {
this.store.path = path.join(os.homedir(), "Library", "Preferences", "org.develar.onshape" + (isDev() ? "-dev" : "") + ".json")
}
}
private windows: Array<WindowItem> = defaultWindows()

restoreWindows(): void {
let data = this.getOrLoadData()
data.windows = defaultWindows()
this.store.all = data
}

private getOrLoadData(): Config {
let data = this.data
if (data == null) {
data = this.store.all
this.data = data
}
return data
this.store.delete("windows")
this.windows = defaultWindows()
}

getWindows(): Array<WindowItem> {
return this.getOrLoadData().windows
const result = this.store.get("windows")
if (result == null || !Array.isArray(result)) {
this.windows = defaultWindows()
}
else {
this.windows = result
}
return this.windows
}

save(): void {
const data = this.data
if (data != null) {
this.store.all = data
}
this.store.set("windows", this.windows)
}
}

interface Config {
windows: Array<WindowItem>
}

export interface WindowItem {
url: string
width?: number
Expand Down
13 changes: 2 additions & 11 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,12 @@
"removeComments": true,
"outDir": "out",
"newLine": "LF",
"noResolve": true,
"noEmitOnError": true,
"inlineSources": true,
"sourceMap": true,
"noUnusedLocals": true,
"skipLibCheck": true
"noUnusedLocals": true
},
"include": [
"node_modules/@types/*/*.d.ts",
"node_modules/electron/electron.d.ts",
"node_modules/electron-updater/out/*.d.ts",
"node_modules/electron-builder-http/out/*.d.ts",
"src/*.ts",
"typings/**/*.d.ts"
],
"exclude": [
"src/*.ts"
]
}
26 changes: 0 additions & 26 deletions typings/configstore.d.ts

This file was deleted.

Loading

0 comments on commit 8d71775

Please sign in to comment.