Skip to content

Commit

Permalink
Fixed a nasty bug that still booted the app when AWS credentials were…
Browse files Browse the repository at this point in the history
… missing. Also apparently the download release dep's uzip dep can't unzip tar archives. Need to manually compress the packaged app for now.
  • Loading branch information
ejolly committed Oct 6, 2020
1 parent 9f32c3a commit 7fdd0af
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 33 deletions.
65 changes: 34 additions & 31 deletions main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,41 @@ const mainLog = log.scope('main');
let mainWindow;

// try to load aws credentials
let awsCredentials = {
accessKeyId: process.env.AWS_SECRET_ACCESS_KEY,
secretAccessKey: process.env.AWS_ACCESS_KEY_ID,
let awsCredentials;

// LOAD AWS CREDENTIALS
const loadAWS = () => {
awsCredentials = {
accessKeyId: process.env.AWS_SECRET_ACCESS_KEY,
secretAccessKey: process.env.AWS_ACCESS_KEY_ID,
};
if (awsCredentials.accessKeyId && awsCredentials.secretAccessKey) {
mainLog.info('AWS credentials loaded from environment variables.');
} else {
fs.readFile(`${app.getPath('home')}/.awscredentials.json`, (err, data) => {
if (err) {
mainLog.error('AWS credentials not configured');
dialog
.showMessageBox({
type: 'error',
title: 'No AWS Credentials',
message:
"Hmm I can't seem to find your AWS credentials. Are you sure you configured them? See the directions: https://eshinjolly.com/svelteturk/#/aws-credentials",
})
.then(() => {
mainLog.info('Exiting...');
app.exit(0);
process.abort();
});
} else {
awsCredentials = JSON.parse(data);
mainLog.info('AWS credentials loaded from file');
}
});
}
};


// Settings file location
const settingsFile = path.join(svelteturkPath, '.svelteturkrc');
// Default settings only applied if settings file doesn't exist
Expand Down Expand Up @@ -211,34 +241,6 @@ const checkForLatestVersion = async () => {
return updateAvailable;
};

// LOAD AWS CREDENTIALS
if (awsCredentials.accessKeyId && awsCredentials.secretAccessKey) {
mainLog.info('AWS credentials loaded from environment variables.');
} else {
fs.readFile(`${app.getPath('home')}/.awscredentials.json`, (err, data) => {
if (err) {
if (err.code === 'ENOENT') {
dialog
.showMessageBox({
type: 'error',
title: 'File not found',
message:
'No environment variables or config file were found for your AWS Credentials! Please configure them and restart the app',
})
.then(() => {
mainLog.error('No AWS environment variables or config file found. Exiting...');
app.exit(0);
process.abort();
});
} else {
throw err;
}
} else {
awsCredentials = JSON.parse(data);
mainLog.info('AWS credentials loaded from file');
}
});
}
// Create the browser window.
const createWindow = () => {
mainWindow = new BrowserWindow({
Expand Down Expand Up @@ -279,6 +281,7 @@ app.on('activate', () => {
// Send aws credentials and user settings
ipcMain.handle('initialize', async (ev) => {
mainLog.info('<--API: intialize');
loadAWS();
let updateAvailable;
let userWantsToUpdate = false;
try {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "SvelteTurk",
"productName": "SvelteTurk",
"version": "0.1.1",
"version": "0.1.2",
"description": "Control mturk via a simple gui app",
"main": "main/main.js",
"scripts": {
"start": "ls main/main.js | entr -r concurrently \"npm:svelte-dev\" \"electron-forge start\"",
"package": "rollup -c && electron-forge package && tar -zcf out/SvelteTurk-darwin-x64.zip out/SvelteTurk-darwin-x64",
"package": "rollup -c && electron-forge package && rm out/*.zip",
"prep-release": "./makerelease.sh",
"release": "npm run package && npm run prep-release",
"make": "electron-forge make",
Expand Down

0 comments on commit 7fdd0af

Please sign in to comment.