Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app.on('ready', async () => {
// Checking internet connection
onlineStatusWindow = new BrowserWindow({
width: 0,
height: 0,
show: false,
})
onlineStatusWindow.loadURL(`file://${resolveRootPath('./main/static/pages/online-status.html')}`)
// Update internet connection
ipcMain.on('online-status-changed', (event, status) => {
console.log(`connection: ${status.toUpperCase()}`)
process.env.CONNECTION = status
})
electronUtil.enforceMacOSAppLocation()
updater(app)
mixpanel.track(app, 'Launch App')
try {
tray = new Tray(resolveRootPath('./main/static/tray/iconTemplate.png'))
tray.setToolTip(config.APP_NAME)
} catch (err) {
Sentry.captureException(err)
/** @format */
// https://github.com/parcel-bundler/parcel/issues/1005#issuecomment-419688410
const Bundler = require('parcel-bundler')
const Server = require('express')()
const appRoot = require('app-root-path')
const options = {
outDir: appRoot.resolve('build/app/renderer/development'), // The out directory to put the build files in, defaults to dist
outFile: 'index.html', // The name of the outputFile
// publicUrl: './', // The url to server on, defaults to dist
watch: true, // whether to watch the files and rebuild them on change, defaults to process.env.NODE_ENV !== 'production'
cache: true, // Enabled or disables caching, defaults to true
cacheDir: appRoot.resolve('.cache'), // The directory cache gets put in, defaults to .cache
contentHash: false, // Disable content hash from being included on the filename
minify: false, // Minify files, enabled if process.env.NODE_ENV === 'production'
scopeHoist: false, // turn on experimental scope hoisting/tree shaking flag, for smaller production bundles
target: 'electron', // browser/node/electron, defaults to browser
https: false, // Serve files over https or http, defaults to false
logLevel: 3, // 3 = log everything, 2 = log warnings & errors, 1 = log errors
hmrPort: 0, // The port the HMR socket runs on, defaults to a random free port (0 in node.js resolves to a random free port)
sourceMaps: true, // Enable or disable sourcemaps, defaults to enabled (not supported in minified builds yet)
hmrHostname: '', // A hostname for hot module reload, default to ''
detailedReport: false // Prints a detailed report of the bundles, assets, filesizes and times, defaults to false, reports are only printed if watch is disabled
}
const runBundle = async (entrypoint, port) => {
// Initializes a bundler using the entrypoint location and options provided.
const bundler = new Bundler(entrypoint, options)
async deleteTmpFile (ctx) {
try {
const post = ctx.request.body || {}
const filePath = STATIC_URL + post.fileName
await deleteFile(appRoot.resolve(filePath))
ctx.send({
code: 0,
message: 'success',
data: 'delete suc'
})
} catch (err) {
console.log(err, 'delete err')
ctx.throwError({
message: err.message
})
}
}
}
function createIcon(path) {
return nativeImage.createFromPath(
resolve(`./static/touchbar/${path}.png`)
);
}
function getSourceDir() {
try { return path.dirname(require.resolve(appRoot)); }
catch (e) { return appRoot.resolve('src'); }
}
merge(defaults, {
output: {
path: appRoot.resolve('.tmp/webpack/watch')
},
devtool: '#eval-source-map',
plugins: [
new webpack.DllPlugin({
context: appRoot.toString(),
path: appRoot.resolve('.tmp/webpack/watch/[name].json'),
name: '__[name]__'
})
]
}),
merge(defaults, {
output: {
path: appRoot.resolve('.tmp/webpack/build')
},
plugins: [
new webpack.DllPlugin({
context: appRoot.toString(),
path: appRoot.resolve('.tmp/webpack/build/[name].json'),
name: '__[name]__'
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: { warnings: false, unused: true, 'dead_code': true },
output: { comments: false }
})
]
const root = dir => appRoot.resolve(dir || '');
'use strict';
const root = require('app-root-path');
module.exports = {
tmpDir: root.resolve('tmp'),
mapsDir: root.resolve('maps'),
distDir: root.resolve('dist'),
buildDir: root.resolve('build'),
pkgsDir: root.resolve('pkgs'),
tplDir: root.resolve('tpls'),
prevDir: root.resolve('previews')
};
['config', 'template'].forEach(function (key) {
if (config[key] && !fileExists[config[key]]) {
config[key] = appRoot.resolve(config[key]);
}
});
return config;