Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update project to use Electron 22 and add a build for M1/M2 Macs #6

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
node_modules
/op1fun-darwin-x64
/op1fun-darwin-arm64
/dist
/op1fun-darwin-x64.zip
/op1fun-darwin-arm64.zip
/.vscode
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python 3.10
nodejs lts
20 changes: 20 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2017-2023 Jordan Sitkin and others

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
73 changes: 40 additions & 33 deletions api-client.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
const JsonApiDataStore = require('jsonapi-datastore').Store;
const Config = require('electron-config');
const ElectronStore = require('electron-store');
const https = require('https');

class ApiClient {
constructor() {
this.config = new Config();
this.config = new ElectronStore();
this.store = new JsonApiDataStore();
}

token() {
return this.config.get('token');
}

email() {
return this.config.get('email');
}

logIn(email, password, callback) {
var me = this;
const me = this;
this.config.set('email', email);
var req = https.request({
const req = https.request({
method: 'POST',
host: 'api.op1.fun',
path: '/v1/api_token',
Expand All @@ -28,53 +28,55 @@ class ApiClient {
'Accept': 'application/json'
}
}, function(res) {
var body = '';
res.on('data', function(d) { body += d; });
let body = '';
res.on('data', function(d) {
body += d;
});
res.on('end', function() {
var res = JSON.parse(body);
const res = JSON.parse(body);
if (res.api_token) {
me.config.set('token', res.api_token);
}
me.enableAppFeatureFlag();
callback(res);
});
});
req.write(JSON.stringify({ email: email, password: password }));
req.write(JSON.stringify({email: email, password: password}));
req.end();
}

enableAppFeatureFlag() {
this._post('feature_flags', { flags: { app: true } }, function() {});
this._post('feature_flags', {flags: {app: true}}, function() {});
}

logOut(callback) {
this.config.set('email', null);
this.config.set('token', null);
callback();
}

isLoggedIn() {
return (this.email() && this.token());
}

getPack(path, id, callback) {
var me = this;
const me = this;
this._get(path, function() {
var pack = me.store.find("packs", id);
const pack = me.store.find('packs', id);
callback(pack);
})
});
}

getPatch(path, id, callback) {
var me = this;
const me = this;
this._get(path, function() {
var patch = me.store.find("patches", id);
const patch = me.store.find('patches', id);
callback(patch);
})
});
}

_get(path, callback) {
var me = this;
const me = this;
return https.get({
host: 'api.op1.fun',
path: '/v1/' + path,
Expand All @@ -83,18 +85,19 @@ class ApiClient {
'X-User-Token': this.token()
}
}, function(res) {
var body = '';
res.on('data', function(d) { body += d; });
let body = '';
res.on('data', function(d) {
body += d;
});
res.on('end', function() {
me.store.sync(JSON.parse(body));
callback();
});
});
}

_post(path, data, callback) {
var me = this;
var req = https.request({
const req = https.request({
method: 'POST',
host: 'api.op1.fun',
path: '/v1/' + path,
Expand All @@ -105,9 +108,13 @@ class ApiClient {
'Accept': 'application/json'
}
}, function(res) {
var body = '';
res.on('data', function(d) { body += d; });
res.on('end', function() { callback(body); });
let body = '';
res.on('data', function(d) {
body += d;
});
res.on('end', function() {
callback(body);
});
});
console.log(data);
console.log(JSON.stringify(data));
Expand Down
Loading