forked from Automattic/wp-calypso
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move wp-desktop files to wp-calypso monorepo (Automattic#43324)
* Copy files from wp-desktop * Remove obsolete module replacements * Fix tests by upgrading express and deduplicating cookie pkg * Add ELECTRON_BUILDER_ARGS option to the build-desktop:app task * Desktop Server: eliminate node_modules and bundle all server modules into the output * Desktop: turn on minification for both server and client * AssetsWriter: ensure with mkdirp that the target dir exists * Make the repo compatible with both old- and new-style desktop build * Fix import paths for desktop modules * Setup build scripts and packages for the desktop app * Reformat imported wp-desktop files with Prettier * ESLint: Remove use strict from wp-desktop modules * ESLint: Fix issues in wp-desktop modules * Check the config/secrets.json file during build-desktop:config * Remove the desktop/ folder from the workspace tree * Install a desktop-specific packages root in desktop/
- Loading branch information
Showing
145 changed files
with
7,959 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
App Handlers | ||
===================== | ||
|
||
App handlers are bits of code that run before the app is started and the main window has opened. Code here cannot use window or dialog functions. | ||
|
||
The following handlers are available: | ||
|
||
- [Crash Reporting](crash-reporting/README.md) | ||
- [Exceptions](exceptions/README.md) | ||
- [Preferences](preferences/README.md) | ||
- [Printer](printer/README.md) | ||
- [Secrets](secrets/README.md) | ||
- [Updater](updater/README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Crash Reporting | ||
========= | ||
|
||
Uses the [Electron crash reporter module](https://github.com/atom/electron/blob/master/docs/api/crash-reporter.md) to send crashes to a remote URL. | ||
|
||
# Config | ||
|
||
Requires `crash_reporter` to be set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* External Dependencies | ||
*/ | ||
const { app, crashReporter } = require( 'electron' ); // eslint-disable-line import/no-extraneous-dependencies | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
const Config = require( 'desktop/lib/config' ); | ||
const log = require( 'desktop/lib/logger' )( 'desktop:crash-reporting' ); | ||
|
||
module.exports = function () { | ||
if ( Config.crash_reporter.electron ) { | ||
app.on( 'will-finish-launching', function () { | ||
log.info( 'Crash reporter started' ); | ||
|
||
crashReporter.start( { | ||
productName: Config.description, | ||
companyName: Config.author, | ||
submitURL: Config.crash_reporter.url, | ||
uploadToServer: true, | ||
} ); | ||
} ); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Exceptions | ||
========= | ||
|
||
Wraps exceptions in the app to provide a better experience. | ||
|
||
Uses the [crash tracker](../../lib/crash-tracker/README.md) to send crashes to a remote URL. | ||
|
||
When running in release mode the exception stack trace is hidden and replaced with a custom dialog that quits the app. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* External Dependencies | ||
*/ | ||
const { app, dialog } = require( 'electron' ); // eslint-disable-line import/no-extraneous-dependencies | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
const crashTracker = require( 'desktop/lib/crash-tracker' ); | ||
const system = require( 'desktop/lib/system' ); | ||
const log = require( 'desktop/lib/logger' )( 'desktop:exceptions', { handleExceptions: true } ); | ||
|
||
/** | ||
* Module variables | ||
*/ | ||
let isReady = false; | ||
let thereCanBeOnlyOne = false; | ||
|
||
// We ignore any of these errors as they are probably temporary | ||
const NETWORK_ERRORS = [ 'ETIMEDOUT', 'ENOTFOUND', 'ECONNREFUSED', 'ECONNRESET' ]; | ||
|
||
function exit() { | ||
if ( isReady ) { | ||
app.quit(); | ||
} else { | ||
process.exit( 1 ); // eslint-disable-line no-process-exit | ||
} | ||
} | ||
|
||
function showErrorAndExit( error ) { | ||
if ( thereCanBeOnlyOne ) { | ||
exit(); | ||
} | ||
|
||
thereCanBeOnlyOne = true; | ||
|
||
dialog.showErrorBox( | ||
'WordPress.com ran into an error', | ||
'Please restart the app and try again.' + | ||
'\n\n' + | ||
'If you continue to have issues, please contact us at [email protected] and mention the error details below:' + | ||
'\n\n' + | ||
error.stack + | ||
'\n\n' + | ||
'System info: ' + | ||
JSON.stringify( system.getVersionData() ) | ||
); | ||
|
||
exit(); | ||
} | ||
|
||
function isFatalError( error ) { | ||
return ! NETWORK_ERRORS.includes( error.code ); | ||
} | ||
|
||
function exceptionHandler( error ) { | ||
if ( ! isFatalError( error ) ) { | ||
return; | ||
} | ||
|
||
log.error( error ); | ||
|
||
if ( crashTracker.isEnabled() ) { | ||
crashTracker.track( | ||
'exception', | ||
{ name: error.name, message: error.message, stack: error.stack }, | ||
function () { | ||
showErrorAndExit( error ); | ||
} | ||
); | ||
} else { | ||
showErrorAndExit( error ); | ||
} | ||
} | ||
|
||
module.exports = function () { | ||
app.on( 'ready', function () { | ||
isReady = true; | ||
} ); | ||
|
||
process.on( 'uncaughtException', exceptionHandler ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const ipcHandler = require( './ipc-handler' ); | ||
|
||
module.exports = function () { | ||
ipcHandler.listen(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* External Dependencies | ||
*/ | ||
const { ipcMain: ipc } = require( 'electron' ); // eslint-disable-line import/no-extraneous-dependencies | ||
|
||
module.exports = { | ||
/** | ||
* JSON object that stores references to loggers initialized | ||
* by calls from the renderer process over IPC (keyed by `namespace`). | ||
*/ | ||
loggers: {}, | ||
|
||
/** | ||
* Gets the logging object for the provided `namespace` (and creates a logger | ||
* if one doesn't exist). Logger references are tracked in the `loggers` | ||
* object and keyed by `namespace`. | ||
* | ||
* @param {string} namespace Namespace of the logger to be used or initialized. | ||
* @param {object} options Logger configuration. | ||
* @returns {object} Logger instance. | ||
*/ | ||
getLogger: function ( namespace, options ) { | ||
let logger = this.loggers[ namespace ]; | ||
if ( ! logger ) { | ||
logger = require( 'desktop/lib/logger' )( namespace, options ); | ||
this.loggers[ namespace ] = logger; | ||
} | ||
return logger; | ||
}, | ||
|
||
/** | ||
* Registers an ipc listener on the `log` channel to relay logging | ||
* events from the renderer process. | ||
*/ | ||
listen: function () { | ||
ipc.on( 'log', ( _, level, namespace, options, message, meta ) => { | ||
const logger = this.getLogger( namespace, options ); | ||
|
||
switch ( level ) { | ||
case 'error': | ||
logger.error( message, meta ); | ||
break; | ||
case 'warn': | ||
logger.warn( message, meta ); | ||
break; | ||
case 'info': | ||
logger.info( message, meta ); | ||
break; | ||
case 'debug': | ||
logger.debug( message, meta ); | ||
break; | ||
case 'silly': | ||
logger.silly( message, meta ); | ||
break; | ||
} | ||
} ); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Preferences | ||
========= | ||
|
||
Monitors for preference IPC messages and updates the settings file. | ||
|
||
## IPC messages | ||
|
||
Listens for the following: | ||
|
||
- `preferences-changed-proxy-type` - proxy changed, tell user to restart the app | ||
- `preferences-changed` - a preference setting has changed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* External Dependencies | ||
*/ | ||
const { dialog, ipcMain: ipc } = require( 'electron' ); // eslint-disable-line import/no-extraneous-dependencies | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
const Settings = require( 'desktop/lib/settings' ); | ||
|
||
function promptForRestart( title, message ) { | ||
// Warn user they need to restart the app | ||
dialog.showMessageBox( | ||
{ | ||
buttons: [ 'OK' ], | ||
title: title, | ||
message: message, | ||
detail: 'The app needs to be restarted for this to take effect.', | ||
}, | ||
function () {} | ||
); | ||
} | ||
|
||
module.exports = function () { | ||
ipc.on( 'preferences-changed', function ( event, { name, value } ) { | ||
if ( 'proxy-type' === name ) { | ||
promptForRestart( 'Proxy changed', 'You have changed the proxy settings.' ); | ||
} else if ( 'spellcheck-enabled' === name ) { | ||
promptForRestart( | ||
value ? 'Spellchecker enabled' : 'Spellchecker disabled', | ||
'You have changed the spellchecker settings.' | ||
); | ||
} | ||
|
||
Settings.saveSetting( name, value ); | ||
} ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Printer | ||
========= | ||
|
||
Provides a way for Calypso to print. This is used for printing backup codes. | ||
|
||
## IPC messages | ||
|
||
Listens for the following: | ||
|
||
- `print` - print a given bit of HTML |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* External Dependencies | ||
*/ | ||
const { BrowserWindow, ipcMain: ipc } = require( 'electron' ); // eslint-disable-line import/no-extraneous-dependencies | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
const log = require( 'desktop/lib/logger' )( 'desktop:printer' ); | ||
|
||
module.exports = function () { | ||
ipc.on( 'print', function ( event, title, html ) { | ||
let printer = new BrowserWindow( { width: 350, height: 300, title: title } ); | ||
|
||
log.debug( 'Printing HTML' ); | ||
|
||
printer.loadURL( 'data:text/html,' + encodeURIComponent( html ) ); | ||
|
||
printer.webContents.on( 'dom-ready', function () { | ||
setTimeout( function () { | ||
printer.webContents.print(); | ||
}, 500 ); | ||
} ); | ||
|
||
printer.on( 'closed', function () { | ||
printer = null; | ||
} ); | ||
} ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Secrets | ||
========= | ||
|
||
Show a secret screen. Shhh. | ||
|
||
## IPC messages | ||
|
||
Listens for the following: | ||
|
||
- `secrets` - which secret to show |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* External Dependencies | ||
*/ | ||
const { ipcMain: ipc } = require( 'electron' ); // eslint-disable-line import/no-extraneous-dependencies | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
const WindowManager = require( 'desktop/lib/window-manager' ); | ||
|
||
ipc.on( 'secrets', function ( ev, which ) { | ||
which = parseInt( which, 10 ); | ||
|
||
if ( which === 0 ) { | ||
WindowManager.openSecret(); | ||
} else if ( which === 1 ) { | ||
WindowManager.openWapuu(); | ||
} | ||
} ); | ||
|
||
module.exports = function () {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Updater | ||
========= | ||
|
||
Uses either the manual or auto updater to check for updates. | ||
|
||
The config `updater.url` is used as the base URL and has the platform, version, and beta setting appended. | ||
|
||
The updater uses: | ||
|
||
- [Auto Updater](auto-updater/README.md) | ||
- [Manual Updater](manual-updater/README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Auto Updater | ||
========= | ||
|
||
Handles Squirrel auto-update events. Note that the app must be signed for this to work. | ||
|
||
## Functions | ||
|
||
`ping()` - checks for an update |
Oops, something went wrong.