Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
lacymorrow committed Mar 24, 2022
1 parent 74eb0e5 commit 8fe4746
Show file tree
Hide file tree
Showing 39 changed files with 2,932 additions and 290 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint unicorn/prefer-module: 0 */
// App entry
const main = require( './src/main.js' )
const main = require( './src/index.js' )

main()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"ava": "ava -v",
"lint": "xo --fix",
"test": "npm run lint",
"css": "sass src/index.scss:src/css/index.css src/preferences.scss:src/css/preferences.css -s compressed",
"css": "sass src/renderer/styles/index.scss:src/renderer/styles/dist/index.css src/renderer/styles/preferences.scss:src/renderer/styles/dist/preferences.css -s compressed",
"start": "npm run css && electron --trace-warnings . ",
"release": "np",
"release:snap": "snapcraft upload --release=CrossOver*.snap",
Expand Down
11 changes: 0 additions & 11 deletions snap/snapcraft.yaml

This file was deleted.

1 change: 1 addition & 0 deletions src/config/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint unicorn/prefer-module: 0 */

// Constants
const DEFAULT_THEME = 'dark'
const HOMEPAGE_URL = 'https://lacymorrow.github.io/crossover'
Expand Down
4 changes: 3 additions & 1 deletion src/config/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const config = require( './config.js' )
const EXIT_CODES = require( './exit-codes.js' )
const keycode = require( './keycode.js' )
const utils = require( './utils.js' )

module.exports = { config, EXIT_CODES }
module.exports = { config, EXIT_CODES, keycode, utils }
89 changes: 89 additions & 0 deletions src/config/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* eslint unicorn/prefer-module: 0 */

/* Utilities */
const debounce = ( func, delay ) => {

let debounceTimer

return function ( ...args ) {

clearTimeout( debounceTimer )

// Pass { abort: true } to cancel
if ( args[0] && args[0].abort ) {

return

}

debounceTimer = setTimeout( () => func.apply( this, args ), delay )

}

}

const checkboxTrue = ( value, key ) =>
// Console.log(value, key, typeof value === 'object', value.includes( key ))
( typeof value === 'object' && value.includes( key ) )

/* eslint-disable no-prototype-builtins */
/**
* Recursively Object.freeze() on objects and functions
* @see https://github.com/substack/deep-freeze
* @param o Object on which to lock the attributes
*/
const deepFreeze = o => {

Object.freeze( o )

for ( const prop of Object.getOwnPropertyNames( o ) ) {

if ( o.hasOwnProperty( prop )
&& o[prop] !== null
&& ( typeof o[prop] === 'object' || typeof o[prop] === 'function' )
&& !Object.isFrozen( o[prop] ) ) {

deepFreeze( o[prop] )

}

}

return o

}

/**
* Check for libappindicator1 support before creating tray icon
*/
const checkLinuxTraySupport = cb => {

const cp = require( 'child_process' )

// Check that we're on Ubuntu (or another debian system) and that we have
// libappindicator1. If WebTorrent was installed from the deb file, we should
// always have it. If it was installed from the zip file, we might not.
cp.exec( 'dpkg --get-selections libappindicator1', ( error, stdout ) => {

if ( error ) {

return cb( false )

}

// Unfortunately there's no cleaner way, as far as I can tell, to check
// whether a debian package is installed:
cb( stdout.endsWith( '\tinstall\n' ) )

} )

}

/* eslint-enable */

module.exports = {
checkboxTrue,
checkLinuxTraySupport,
debounce,
deepFreeze,
}
1 change: 0 additions & 1 deletion src/css/index.css

This file was deleted.

1 change: 0 additions & 1 deletion src/css/index.css.map

This file was deleted.

3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const main = require( './main.js' )

module.exports = main

0 comments on commit 8fe4746

Please sign in to comment.