mirror of
https://github.com/balena-io/etcher.git
synced 2025-08-03 16:37:44 +00:00
Don't use settings.getDefaults() in etcher.js
Change-type: patch
This commit is contained in:
parent
126b3fbb40
commit
66479739b9
@ -17,7 +17,7 @@
|
||||
import { app, remote } from 'electron';
|
||||
import { readFile, unlink, writeFile } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { promisify } from 'util';
|
||||
import { inspect, promisify } from 'util';
|
||||
|
||||
const readFileAsync = promisify(readFile);
|
||||
const writeFileAsync = promisify(writeFile);
|
||||
@ -67,19 +67,12 @@ const CONFIG_PATH = join(USER_DATA_DIR, 'config.json');
|
||||
* })
|
||||
*/
|
||||
async function readConfigFile(filename: string): Promise<any> {
|
||||
let contents = '{}';
|
||||
try {
|
||||
contents = await readFileAsync(filename, { encoding: 'utf8' });
|
||||
return JSON.parse(await readFileAsync(filename, { encoding: 'utf8' }));
|
||||
} catch (error) {
|
||||
if (error.code === 'ENOENT') {
|
||||
return {};
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
try {
|
||||
return JSON.parse(contents);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
console.error(
|
||||
`Failed to load settings from ${filename}: ${inspect(error)}`,
|
||||
);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
@ -28,9 +28,7 @@ const settings = require('./app/models/settings')
|
||||
const analytics = require('./app/modules/analytics')
|
||||
// eslint-disable-next-line node/no-missing-require
|
||||
const { getConfig } = require('./app/modules/utils')
|
||||
/* eslint-disable lodash/prefer-lodash-method */
|
||||
|
||||
const config = settings.getDefaults()
|
||||
/* eslint-disable lodash/prefer-lodash-method,func-style,space-before-function-paren,require-jsdoc */
|
||||
|
||||
const configUrl = settings.get('configUrl') || 'https://balena.io/etcher/static/config.json'
|
||||
|
||||
@ -57,10 +55,11 @@ const checkForUpdates = async (interval) => {
|
||||
|
||||
/**
|
||||
* @summary Create Etcher's main window
|
||||
* @param {Object} config - config
|
||||
* @example
|
||||
* electron.app.on('ready', createMainWindow)
|
||||
*/
|
||||
const createMainWindow = () => {
|
||||
const createMainWindow = (config) => {
|
||||
const mainWindow = new electron.BrowserWindow({
|
||||
// eslint-disable-next-line no-magic-numbers
|
||||
width: parseInt(config.width, 10) || 800,
|
||||
@ -141,18 +140,17 @@ electron.app.on('before-quit', () => {
|
||||
process.exit(EXIT_CODES.SUCCESS)
|
||||
})
|
||||
|
||||
settings.load().then((localSettings) => {
|
||||
Object.assign(config, localSettings)
|
||||
}).catch((error) => {
|
||||
// TODO: What do if loading the config fails?
|
||||
console.error('Error loading settings:')
|
||||
console.error(error)
|
||||
}).finally(() => {
|
||||
async function main() {
|
||||
const config = await settings.load()
|
||||
if (electron.app.isReady()) {
|
||||
createMainWindow()
|
||||
createMainWindow(config)
|
||||
} else {
|
||||
electron.app.on('ready', createMainWindow)
|
||||
electron.app.on('ready', () => {
|
||||
createMainWindow(config)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
console.time('ready-to-show')
|
||||
|
Loading…
x
Reference in New Issue
Block a user