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