Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'electron-util' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
return new Promise((resolve, reject) => {
try {
let binPath = self._binaryPath,
options = {
stdio: ['pipe', 'pipe', 'pipe'],
env: {
'OONI_HOME': getHomeDir(),
}
}
if (is.windows) {
const isAscii = /^[ -~]+$/
let homeDir = os.homedir()
try {
// This is a workaround for the users home directory containing
// non-ascii characters.
// For more context see: https://github.com/nodejs/node/issues/17586
if (!isAscii.test(homeDir)) {
// eslint-disable-next-line no-console
log.info('detected non-ascii characters in homeDir', homeDir)
const shortHomeDir = GetHomeShortPath()
options.env['OONI_HOME'] = path.join(shortHomeDir, path.relative(homeDir, options.env.OONI_HOME))
}
} catch (err) {
// eslint-disable-next-line no-console
console.log('failed to determine the home shortpath. Things will break with user homes which contain non-ascii characters.')
}
currency = _.omit(currency, ['electrumServers']);
// Translate to exepcted mm v2 format
currency.etomic = currency.contractAddress;
delete currency.contractAddress;
return currency;
});
options = {
...options,
gui: 'hyperdex',
userhome: os.homedir(),
netid: 9999, // TODO: Set this to `0` when mm v2 is production ready
rpcport: port,
rpccors: is.development ? 'http://localhost:8080' : 'app://-',
coins,
};
this.port = options.rpcport;
if (options.seedPhrase) {
// eslint-disable-next-line camelcase
options.rpc_password = await sha256(options.seedPhrase);
options.passphrase = options.seedPhrase;
delete options.seedPhrase;
} else {
throw new Error('The `seedPhrase` option is required');
}
// NOTE: It's very important that this is a different directory than mm v1, as the database is not compatible
// TODO: Update the path here when mm v2 is production ready
const createHelpMenu = () => {
const helpSubmenu = [
{
label: t('help.debugMode'),
type: 'checkbox',
checked: isDevelopment,
enabled: !isNightlyBuild && !is.development, // Enable it only in production
click() {
config.set('isDebugMode', !isDevelopment);
app.relaunch();
app.quit();
},
},
{
type: 'separator',
},
openUrlMenuItem({
label: t('help.website'),
url: websiteUrl,
}),
openUrlMenuItem({
label: t('help.sourceCode'),
url: repoUrl,
)
}
},
{
label: 'View Logs',
visible: config.get(ConfigKey.DebugMode),
click() {
viewLogs()
}
}
]
}
]
// Add the develop menu when running in the development environment
if (is.development) {
applicationMenu.splice(-1, 0, {
label: 'Develop',
submenu: [
{
label: 'Clear Cache and Restart',
click() {
// Clear app config
config.clear()
// Restart without firing quitting events
app.relaunch()
app.exit(0)
}
}
]
})
}
this.setState(prevState => {
this.api.disableCurrency(coin);
const enabledCoins = prevState.enabledCoins.filter(enabledCoin => enabledCoin !== coin);
setCurrencies(prevState.portfolio.id, enabledCoins);
// TODO: Remove this when https://github.com/artemii235/SuperNET/issues/459 is fixed.
api.dialog.showMessageBox(activeWindow(), {
message: 'Marketmaker v2 cannot currently disable currencies when running, so you need to restart HyperDEX for it to take effect.',
});
return {enabledCoins};
}, () => {
this.events.emit('enabled-currencies-changed');
minHeight: 200,
alwaysOnTop: config.get('alwaysOnTop'),
titleBarStyle: 'hiddenInset',
autoHideMenuBar: config.get('autoHideMenuBar'),
darkTheme: isDarkMode, // GTK+3
webPreferences: {
preload: path.join(__dirname, 'browser.js'),
contextIsolation: true,
plugins: true
}
});
setUserLocale();
initRequestsFiltering();
darkMode.onChange(() => {
win.webContents.send('set-dark-mode');
});
if (is.macos) {
win.setSheetOffset(40);
}
win.loadURL(mainURL);
win.on('close', event => {
if (config.get('quitOnWindowClose')) {
app.quit();
return;
}
// Workaround for https://github.com/electron/electron/issues/20263
const logChannel = '__ELECTRON_TIMBER_LOG__';
const warnChannel = '__ELECTRON_TIMBER_WARN__';
const errorChannel = '__ELECTRON_TIMBER_ERROR__';
const updateChannel = '__ELECTRON_TIMBER_UPDATE__';
const defaultsNameSpace = '__ELECTRON_TIMBER_DEFAULTS__';
const filteredLoggers = process.env.TIMBER_LOGGERS && new Set(process.env.TIMBER_LOGGERS.split(','));
const preloadScript = path.resolve(__dirname, 'preload.js');
const logLevels = {
info: 0,
warn: 1,
error: 2
};
if (is.main) {
global[defaultsNameSpace] = {
ignore: null,
shouldHookConsole: false,
logLevel: is.development ? logLevels.info : logLevels.warn
};
}
// Flag to indicate whether the console has been hooked or not
let isConsoleHooked = false;
const _console = {};
const hookableMethods = ['log', 'warn', 'error', 'time', 'timeEnd'];
let longestNameLength = 0;
class Timber {
constructor(options = {}) {
static async setup() {
// https://github.com/sindresorhus/electron-util#enforcemacosapplocation-macos
enforceMacOSAppLocation()
// application exit.
app.on('will-quit', async (event) => {
logger.debug('Exiting...')
event.preventDefault()
await this.shutdown()
app.exit()
})
// windows closed, no more to do.
app.on('window-all-closed', () => {
app.quit()
})
// Constants
let onlineStatusWindow
let twitterLoginWindow
let tray
let isQuit = false
let loggedIn = false
let alreadyGetUser = false
const appLaunchTime = moment()
setupSentry(app)
store.setupNoti()
app.setName(config.APP_NAME)
// Hide dock icon (In production mode, it's setup on package.json. [key: LSUIElement])
if (isDev && electronUtil.is.macos) {
app.dock.hide()
}
if (firstRun()) {
app.setLoginItemSettings({ openAtLogin: true })
}
const gotTheLock = app.requestSingleInstanceLock()
if (!gotTheLock) {
app.quit()
}
// Process Cycle
app.on('ready', async () => {
// Checking internet connection
}
setLoggedInStatus()
// Set the application's name
app.setName('There')
// Make There start automatically on login
if (!isDev && firstRun()) {
app.setLoginItemSettings({ openAtLogin: true })
}
// Hide dock icon before the app starts
// This is only required for development because
// we're setting a property on the bundled app
// in production, which prevents the icon from flickering
if (isDev && electronUtils.is.macos) {
app.dock.hide()
}
// Makes sure where inheriting the correct path
// Within the bundled app, the path would otherwise be different
fixPath()
app.on('window-all-closed', () => {
if (!electronUtils.is.macos) {
app.quit()
}
})
const contextMenu = (tray, windows) => {
if (process.env.CONNECTION === 'offline') {
return outerMenu(app, tray, windows)