2016-01-24 13:20:29 +00:00
|
|
|
import 'source-map-support/register';
|
Revamp and move to TypeScript (#898)
## Breaking changes
- Require **Node >= 8.10.0 and npm 5.6.0**
- Move to **Electron 8.1.1**.
- That's it. Lots of care went into breaking CLI & programmatic behavior
as little as possible. **Please report regressions**.
- Known issue: build may fail behind a proxy. Get in touch if you use one:
https://github.com/jiahaog/nativefier/issues/907#issuecomment-596144768
## Changes summary
Nativefier didn't get much love recently, to the point that it's
becoming hard to run on recent Node, due to old dependencies.
Also, some past practices now seem weird, as better expressible
by modern JS/TS, discouraging contributions including mine.
Addressing this, and one thing leading to another, came a
bigger-than-expected revamp, aiming at making Nativefier more
**lean, stable, future-proof, user-friendly and dev-friendly**,
while **not changing the CLI/programmatic interfaces**. Highlights:
- **Require Node>=8**, as imposed by many of our dependencies. Node 8
is twice LTS, and easily available even in conservative Linux distros.
No reason not to demand it.
- **Default to Electron 8**.
- **Bump** all dependencies to latest version, including electron-packager.
- **Move to TS**. TS is great. As of today, I see no reason not to use it,
and fight interface bugs at runtime rather than at compile time.
With that, get rid of everything Babel/Webpack.
- **Move away from Gulp**. Gulp's selling point is perf via streaming,
but for small builds like Nativefier, npm tasks are plenty good
and less dependency bloat. Gulp was the driver for this PR: broken
on Node 12, and I didn't feel like just upgrading and keeping it.
- Add tons of **verbose logs** everywhere it makes sense, to have a
fine & clear trace of the program flow. This will be helpful to
debug user-reported issues, and already helped me fix a few bugs.
- With better simple logging, get rid of the quirky and buggy
progress bar based on package `progress`. Nice logging (minimal
by default, the verbose logging mentioned above is only used
when passing `--verbose`) is better and one less dependency.
- **Dump `async` package**, a relic from old callback-hell early Node.
Also dump a few other micro-packages unnecessary now.
- A first pass of code **cleanup** thanks to modern JS/TS features:
fixes, simplifications, jsdoc type annotations to types, etc.
- **Remove GitHub integrations Hound & CodeClimate**, which are more
exotic than good'ol'linters, and whose signal-to-noise ratio is too low.
- Quality: **Add tests** and add **Windows + macOS CI builds**.
Also, add a **manual test script**, helping to quickly verify the
hard-to-programatically-test stuff before releases, and limit regressions.
- **Fix a very small number of existing bugs**. The goal of this PR was
*not* to fix bugs, but to get Nativefier in better shape to do so.
Bugfixes will come later. Still, these got addressed:
- Add common `Alt`+`Left`/`Right` for previous/next navigation.
- Improve #379: fix zoom with `Ctrl` + numpad `+`/`-`
- Fix pinch-to-zoom (see https://github.com/jiahaog/nativefier/issues/379#issuecomment-598612128 )
2020-03-15 20:50:01 +00:00
|
|
|
|
2016-01-29 14:04:41 +00:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
Revamp and move to TypeScript (#898)
## Breaking changes
- Require **Node >= 8.10.0 and npm 5.6.0**
- Move to **Electron 8.1.1**.
- That's it. Lots of care went into breaking CLI & programmatic behavior
as little as possible. **Please report regressions**.
- Known issue: build may fail behind a proxy. Get in touch if you use one:
https://github.com/jiahaog/nativefier/issues/907#issuecomment-596144768
## Changes summary
Nativefier didn't get much love recently, to the point that it's
becoming hard to run on recent Node, due to old dependencies.
Also, some past practices now seem weird, as better expressible
by modern JS/TS, discouraging contributions including mine.
Addressing this, and one thing leading to another, came a
bigger-than-expected revamp, aiming at making Nativefier more
**lean, stable, future-proof, user-friendly and dev-friendly**,
while **not changing the CLI/programmatic interfaces**. Highlights:
- **Require Node>=8**, as imposed by many of our dependencies. Node 8
is twice LTS, and easily available even in conservative Linux distros.
No reason not to demand it.
- **Default to Electron 8**.
- **Bump** all dependencies to latest version, including electron-packager.
- **Move to TS**. TS is great. As of today, I see no reason not to use it,
and fight interface bugs at runtime rather than at compile time.
With that, get rid of everything Babel/Webpack.
- **Move away from Gulp**. Gulp's selling point is perf via streaming,
but for small builds like Nativefier, npm tasks are plenty good
and less dependency bloat. Gulp was the driver for this PR: broken
on Node 12, and I didn't feel like just upgrading and keeping it.
- Add tons of **verbose logs** everywhere it makes sense, to have a
fine & clear trace of the program flow. This will be helpful to
debug user-reported issues, and already helped me fix a few bugs.
- With better simple logging, get rid of the quirky and buggy
progress bar based on package `progress`. Nice logging (minimal
by default, the verbose logging mentioned above is only used
when passing `--verbose`) is better and one less dependency.
- **Dump `async` package**, a relic from old callback-hell early Node.
Also dump a few other micro-packages unnecessary now.
- A first pass of code **cleanup** thanks to modern JS/TS features:
fixes, simplifications, jsdoc type annotations to types, etc.
- **Remove GitHub integrations Hound & CodeClimate**, which are more
exotic than good'ol'linters, and whose signal-to-noise ratio is too low.
- Quality: **Add tests** and add **Windows + macOS CI builds**.
Also, add a **manual test script**, helping to quickly verify the
hard-to-programatically-test stuff before releases, and limit regressions.
- **Fix a very small number of existing bugs**. The goal of this PR was
*not* to fix bugs, but to get Nativefier in better shape to do so.
Bugfixes will come later. Still, these got addressed:
- Add common `Alt`+`Left`/`Right` for previous/next navigation.
- Improve #379: fix zoom with `Ctrl` + numpad `+`/`-`
- Fix pinch-to-zoom (see https://github.com/jiahaog/nativefier/issues/379#issuecomment-598612128 )
2020-03-15 20:50:01 +00:00
|
|
|
|
2018-11-05 02:03:52 +00:00
|
|
|
import { app, crashReporter, globalShortcut } from 'electron';
|
2017-04-29 14:52:12 +00:00
|
|
|
import electronDownload from 'electron-dl';
|
|
|
|
|
Revamp and move to TypeScript (#898)
## Breaking changes
- Require **Node >= 8.10.0 and npm 5.6.0**
- Move to **Electron 8.1.1**.
- That's it. Lots of care went into breaking CLI & programmatic behavior
as little as possible. **Please report regressions**.
- Known issue: build may fail behind a proxy. Get in touch if you use one:
https://github.com/jiahaog/nativefier/issues/907#issuecomment-596144768
## Changes summary
Nativefier didn't get much love recently, to the point that it's
becoming hard to run on recent Node, due to old dependencies.
Also, some past practices now seem weird, as better expressible
by modern JS/TS, discouraging contributions including mine.
Addressing this, and one thing leading to another, came a
bigger-than-expected revamp, aiming at making Nativefier more
**lean, stable, future-proof, user-friendly and dev-friendly**,
while **not changing the CLI/programmatic interfaces**. Highlights:
- **Require Node>=8**, as imposed by many of our dependencies. Node 8
is twice LTS, and easily available even in conservative Linux distros.
No reason not to demand it.
- **Default to Electron 8**.
- **Bump** all dependencies to latest version, including electron-packager.
- **Move to TS**. TS is great. As of today, I see no reason not to use it,
and fight interface bugs at runtime rather than at compile time.
With that, get rid of everything Babel/Webpack.
- **Move away from Gulp**. Gulp's selling point is perf via streaming,
but for small builds like Nativefier, npm tasks are plenty good
and less dependency bloat. Gulp was the driver for this PR: broken
on Node 12, and I didn't feel like just upgrading and keeping it.
- Add tons of **verbose logs** everywhere it makes sense, to have a
fine & clear trace of the program flow. This will be helpful to
debug user-reported issues, and already helped me fix a few bugs.
- With better simple logging, get rid of the quirky and buggy
progress bar based on package `progress`. Nice logging (minimal
by default, the verbose logging mentioned above is only used
when passing `--verbose`) is better and one less dependency.
- **Dump `async` package**, a relic from old callback-hell early Node.
Also dump a few other micro-packages unnecessary now.
- A first pass of code **cleanup** thanks to modern JS/TS features:
fixes, simplifications, jsdoc type annotations to types, etc.
- **Remove GitHub integrations Hound & CodeClimate**, which are more
exotic than good'ol'linters, and whose signal-to-noise ratio is too low.
- Quality: **Add tests** and add **Windows + macOS CI builds**.
Also, add a **manual test script**, helping to quickly verify the
hard-to-programatically-test stuff before releases, and limit regressions.
- **Fix a very small number of existing bugs**. The goal of this PR was
*not* to fix bugs, but to get Nativefier in better shape to do so.
Bugfixes will come later. Still, these got addressed:
- Add common `Alt`+`Left`/`Right` for previous/next navigation.
- Improve #379: fix zoom with `Ctrl` + numpad `+`/`-`
- Fix pinch-to-zoom (see https://github.com/jiahaog/nativefier/issues/379#issuecomment-598612128 )
2020-03-15 20:50:01 +00:00
|
|
|
import { createLoginWindow } from './components/loginWindow';
|
|
|
|
import { createMainWindow } from './components/mainWindow';
|
|
|
|
import { createTrayIcon } from './components/trayIcon';
|
|
|
|
import { isOSX } from './helpers/helpers';
|
|
|
|
import { inferFlashPath } from './helpers/inferFlash';
|
2016-01-24 13:20:29 +00:00
|
|
|
|
Revamp and move to TypeScript (#898)
## Breaking changes
- Require **Node >= 8.10.0 and npm 5.6.0**
- Move to **Electron 8.1.1**.
- That's it. Lots of care went into breaking CLI & programmatic behavior
as little as possible. **Please report regressions**.
- Known issue: build may fail behind a proxy. Get in touch if you use one:
https://github.com/jiahaog/nativefier/issues/907#issuecomment-596144768
## Changes summary
Nativefier didn't get much love recently, to the point that it's
becoming hard to run on recent Node, due to old dependencies.
Also, some past practices now seem weird, as better expressible
by modern JS/TS, discouraging contributions including mine.
Addressing this, and one thing leading to another, came a
bigger-than-expected revamp, aiming at making Nativefier more
**lean, stable, future-proof, user-friendly and dev-friendly**,
while **not changing the CLI/programmatic interfaces**. Highlights:
- **Require Node>=8**, as imposed by many of our dependencies. Node 8
is twice LTS, and easily available even in conservative Linux distros.
No reason not to demand it.
- **Default to Electron 8**.
- **Bump** all dependencies to latest version, including electron-packager.
- **Move to TS**. TS is great. As of today, I see no reason not to use it,
and fight interface bugs at runtime rather than at compile time.
With that, get rid of everything Babel/Webpack.
- **Move away from Gulp**. Gulp's selling point is perf via streaming,
but for small builds like Nativefier, npm tasks are plenty good
and less dependency bloat. Gulp was the driver for this PR: broken
on Node 12, and I didn't feel like just upgrading and keeping it.
- Add tons of **verbose logs** everywhere it makes sense, to have a
fine & clear trace of the program flow. This will be helpful to
debug user-reported issues, and already helped me fix a few bugs.
- With better simple logging, get rid of the quirky and buggy
progress bar based on package `progress`. Nice logging (minimal
by default, the verbose logging mentioned above is only used
when passing `--verbose`) is better and one less dependency.
- **Dump `async` package**, a relic from old callback-hell early Node.
Also dump a few other micro-packages unnecessary now.
- A first pass of code **cleanup** thanks to modern JS/TS features:
fixes, simplifications, jsdoc type annotations to types, etc.
- **Remove GitHub integrations Hound & CodeClimate**, which are more
exotic than good'ol'linters, and whose signal-to-noise ratio is too low.
- Quality: **Add tests** and add **Windows + macOS CI builds**.
Also, add a **manual test script**, helping to quickly verify the
hard-to-programatically-test stuff before releases, and limit regressions.
- **Fix a very small number of existing bugs**. The goal of this PR was
*not* to fix bugs, but to get Nativefier in better shape to do so.
Bugfixes will come later. Still, these got addressed:
- Add common `Alt`+`Left`/`Right` for previous/next navigation.
- Improve #379: fix zoom with `Ctrl` + numpad `+`/`-`
- Fix pinch-to-zoom (see https://github.com/jiahaog/nativefier/issues/379#issuecomment-598612128 )
2020-03-15 20:50:01 +00:00
|
|
|
// Entrypoint for Squirrel, a windows update framework. See https://github.com/jiahaog/nativefier/pull/744
|
|
|
|
if (require('electron-squirrel-startup')) {
|
2019-04-19 17:21:36 +00:00
|
|
|
app.exit();
|
Support packaging nativefier applications into Squirrel-based installers (#744)
[Squirrel](https://github.com/Squirrel/Squirrel.Windows) is *"an installation and update
framework for Windows desktop apps "*.
This PR adds `electron-squirrel-startup`, allowing to package nativefier applications
into squirrel-based setup installers. Squirrel require this entrypoint to perform
desktop and startup menu creations, without showing the UI on setup launches.
- References: https://github.com/mongodb-js/electron-squirrel-startup
- Resolves `electron-winstaller` and `electron-installer-windows` support of desktop / startup menu shortcuts for nativefier packaged applications.
- The `electron-squirrel-startup` entrypoint has no effect on both Linux and Darwin, only on Windows
- Supporting it directly inside `nativefier` avoids having to "hack" around the existing `main.js`
and including dependencies from `electron-squirrel-startup` in an intermediate package
to be included in a third layer for the final installer executable
- The following script based on both `nativefier` and `electron-winstaller` templates
represents a portable proof of concept for this merge request :
```js
var nativefier = require('nativefier').default;
var electronInstaller = require('electron-winstaller');
var options = {
name: 'Web WhatsApp',
targetUrl: 'http://web.whatsapp.com',
platform: 'windows',
arch: 'x64',
version: '0.36.4',
out: '.',
overwrite: false,
asar: false,
counter: false,
bounce: false,
width: 1280,
height: 800,
showMenuBar: false,
fastQuit: false,
userAgent: 'Mozilla ...',
ignoreCertificate: false,
ignoreGpuBlacklist: false,
enableEs3Apis: false,
insecure: false,
honest: false,
zoom: 1.0,
singleInstance: false,
fileDownloadOptions: {
saveAs: true
},
processEnvs: {
GOOGLE_API_KEY: '<your-google-api-key>'
}
};
nativefier(options, function(error, appPath) {
if (error) {
console.error(error);
return;
}
console.log('App has been nativefied to', appPath);
resultPromise = electronInstaller.createWindowsInstaller({
appDirectory: 'Web WhatsApp-win32-x64',
outputDirectory: './',
authors: 'Web WhatsApp',
exe: 'Web WhatsApp.exe'
});
resultPromise.then(() => console.log('It worked!'), e => console.log(`No dice: ${e.message}`));
});
```
2019-02-08 14:57:32 +00:00
|
|
|
}
|
|
|
|
|
2016-01-22 11:57:39 +00:00
|
|
|
const APP_ARGS_FILE_PATH = path.join(__dirname, '..', 'nativefier.json');
|
2016-01-29 14:04:41 +00:00
|
|
|
const appArgs = JSON.parse(fs.readFileSync(APP_ARGS_FILE_PATH, 'utf8'));
|
2015-07-06 02:31:09 +00:00
|
|
|
|
Revamp and move to TypeScript (#898)
## Breaking changes
- Require **Node >= 8.10.0 and npm 5.6.0**
- Move to **Electron 8.1.1**.
- That's it. Lots of care went into breaking CLI & programmatic behavior
as little as possible. **Please report regressions**.
- Known issue: build may fail behind a proxy. Get in touch if you use one:
https://github.com/jiahaog/nativefier/issues/907#issuecomment-596144768
## Changes summary
Nativefier didn't get much love recently, to the point that it's
becoming hard to run on recent Node, due to old dependencies.
Also, some past practices now seem weird, as better expressible
by modern JS/TS, discouraging contributions including mine.
Addressing this, and one thing leading to another, came a
bigger-than-expected revamp, aiming at making Nativefier more
**lean, stable, future-proof, user-friendly and dev-friendly**,
while **not changing the CLI/programmatic interfaces**. Highlights:
- **Require Node>=8**, as imposed by many of our dependencies. Node 8
is twice LTS, and easily available even in conservative Linux distros.
No reason not to demand it.
- **Default to Electron 8**.
- **Bump** all dependencies to latest version, including electron-packager.
- **Move to TS**. TS is great. As of today, I see no reason not to use it,
and fight interface bugs at runtime rather than at compile time.
With that, get rid of everything Babel/Webpack.
- **Move away from Gulp**. Gulp's selling point is perf via streaming,
but for small builds like Nativefier, npm tasks are plenty good
and less dependency bloat. Gulp was the driver for this PR: broken
on Node 12, and I didn't feel like just upgrading and keeping it.
- Add tons of **verbose logs** everywhere it makes sense, to have a
fine & clear trace of the program flow. This will be helpful to
debug user-reported issues, and already helped me fix a few bugs.
- With better simple logging, get rid of the quirky and buggy
progress bar based on package `progress`. Nice logging (minimal
by default, the verbose logging mentioned above is only used
when passing `--verbose`) is better and one less dependency.
- **Dump `async` package**, a relic from old callback-hell early Node.
Also dump a few other micro-packages unnecessary now.
- A first pass of code **cleanup** thanks to modern JS/TS features:
fixes, simplifications, jsdoc type annotations to types, etc.
- **Remove GitHub integrations Hound & CodeClimate**, which are more
exotic than good'ol'linters, and whose signal-to-noise ratio is too low.
- Quality: **Add tests** and add **Windows + macOS CI builds**.
Also, add a **manual test script**, helping to quickly verify the
hard-to-programatically-test stuff before releases, and limit regressions.
- **Fix a very small number of existing bugs**. The goal of this PR was
*not* to fix bugs, but to get Nativefier in better shape to do so.
Bugfixes will come later. Still, these got addressed:
- Add common `Alt`+`Left`/`Right` for previous/next navigation.
- Improve #379: fix zoom with `Ctrl` + numpad `+`/`-`
- Fix pinch-to-zoom (see https://github.com/jiahaog/nativefier/issues/379#issuecomment-598612128 )
2020-03-15 20:50:01 +00:00
|
|
|
const fileDownloadOptions = { ...appArgs.fileDownloadOptions };
|
2018-01-26 14:59:58 +00:00
|
|
|
electronDownload(fileDownloadOptions);
|
|
|
|
|
2017-08-16 14:20:43 +00:00
|
|
|
if (appArgs.processEnvs) {
|
2020-04-27 15:52:21 +00:00
|
|
|
// This is compatibility if just a string was passed.
|
|
|
|
if (typeof appArgs.processEnvs === 'string') {
|
|
|
|
process.env.processEnvs = appArgs.processEnvs;
|
|
|
|
} else {
|
|
|
|
Object.keys(appArgs.processEnvs).forEach((key) => {
|
|
|
|
/* eslint-env node */
|
|
|
|
process.env[key] = appArgs.processEnvs[key];
|
|
|
|
});
|
|
|
|
}
|
2017-08-16 14:20:43 +00:00
|
|
|
}
|
|
|
|
|
2016-01-29 14:04:41 +00:00
|
|
|
let mainWindow;
|
2016-01-23 02:09:47 +00:00
|
|
|
|
2016-03-26 07:06:50 +00:00
|
|
|
if (typeof appArgs.flashPluginDir === 'string') {
|
2017-04-29 14:52:12 +00:00
|
|
|
app.commandLine.appendSwitch('ppapi-flash-path', appArgs.flashPluginDir);
|
2016-03-26 07:06:50 +00:00
|
|
|
} else if (appArgs.flashPluginDir) {
|
Revamp and move to TypeScript (#898)
## Breaking changes
- Require **Node >= 8.10.0 and npm 5.6.0**
- Move to **Electron 8.1.1**.
- That's it. Lots of care went into breaking CLI & programmatic behavior
as little as possible. **Please report regressions**.
- Known issue: build may fail behind a proxy. Get in touch if you use one:
https://github.com/jiahaog/nativefier/issues/907#issuecomment-596144768
## Changes summary
Nativefier didn't get much love recently, to the point that it's
becoming hard to run on recent Node, due to old dependencies.
Also, some past practices now seem weird, as better expressible
by modern JS/TS, discouraging contributions including mine.
Addressing this, and one thing leading to another, came a
bigger-than-expected revamp, aiming at making Nativefier more
**lean, stable, future-proof, user-friendly and dev-friendly**,
while **not changing the CLI/programmatic interfaces**. Highlights:
- **Require Node>=8**, as imposed by many of our dependencies. Node 8
is twice LTS, and easily available even in conservative Linux distros.
No reason not to demand it.
- **Default to Electron 8**.
- **Bump** all dependencies to latest version, including electron-packager.
- **Move to TS**. TS is great. As of today, I see no reason not to use it,
and fight interface bugs at runtime rather than at compile time.
With that, get rid of everything Babel/Webpack.
- **Move away from Gulp**. Gulp's selling point is perf via streaming,
but for small builds like Nativefier, npm tasks are plenty good
and less dependency bloat. Gulp was the driver for this PR: broken
on Node 12, and I didn't feel like just upgrading and keeping it.
- Add tons of **verbose logs** everywhere it makes sense, to have a
fine & clear trace of the program flow. This will be helpful to
debug user-reported issues, and already helped me fix a few bugs.
- With better simple logging, get rid of the quirky and buggy
progress bar based on package `progress`. Nice logging (minimal
by default, the verbose logging mentioned above is only used
when passing `--verbose`) is better and one less dependency.
- **Dump `async` package**, a relic from old callback-hell early Node.
Also dump a few other micro-packages unnecessary now.
- A first pass of code **cleanup** thanks to modern JS/TS features:
fixes, simplifications, jsdoc type annotations to types, etc.
- **Remove GitHub integrations Hound & CodeClimate**, which are more
exotic than good'ol'linters, and whose signal-to-noise ratio is too low.
- Quality: **Add tests** and add **Windows + macOS CI builds**.
Also, add a **manual test script**, helping to quickly verify the
hard-to-programatically-test stuff before releases, and limit regressions.
- **Fix a very small number of existing bugs**. The goal of this PR was
*not* to fix bugs, but to get Nativefier in better shape to do so.
Bugfixes will come later. Still, these got addressed:
- Add common `Alt`+`Left`/`Right` for previous/next navigation.
- Improve #379: fix zoom with `Ctrl` + numpad `+`/`-`
- Fix pinch-to-zoom (see https://github.com/jiahaog/nativefier/issues/379#issuecomment-598612128 )
2020-03-15 20:50:01 +00:00
|
|
|
const flashPath = inferFlashPath();
|
2017-04-29 14:52:12 +00:00
|
|
|
app.commandLine.appendSwitch('ppapi-flash-path', flashPath);
|
2016-02-23 08:46:14 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 13:31:47 +00:00
|
|
|
if (appArgs.ignoreCertificate) {
|
2017-04-29 14:52:12 +00:00
|
|
|
app.commandLine.appendSwitch('ignore-certificate-errors');
|
2016-01-25 15:42:28 +00:00
|
|
|
}
|
|
|
|
|
2018-04-22 19:56:10 +00:00
|
|
|
if (appArgs.disableGpu) {
|
|
|
|
app.disableHardwareAcceleration();
|
|
|
|
}
|
|
|
|
|
2017-07-13 16:23:07 +00:00
|
|
|
if (appArgs.ignoreGpuBlacklist) {
|
|
|
|
app.commandLine.appendSwitch('ignore-gpu-blacklist');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (appArgs.enableEs3Apis) {
|
|
|
|
app.commandLine.appendSwitch('enable-es3-apis');
|
|
|
|
}
|
|
|
|
|
2017-07-05 13:07:31 +00:00
|
|
|
if (appArgs.diskCacheSize) {
|
|
|
|
app.commandLine.appendSwitch('disk-cache-size', appArgs.diskCacheSize);
|
|
|
|
}
|
|
|
|
|
2017-10-05 22:44:03 +00:00
|
|
|
if (appArgs.basicAuthUsername) {
|
2018-05-24 07:02:44 +00:00
|
|
|
app.commandLine.appendSwitch(
|
|
|
|
'basic-auth-username',
|
|
|
|
appArgs.basicAuthUsername,
|
|
|
|
);
|
2017-10-05 22:44:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (appArgs.basicAuthPassword) {
|
2018-05-24 07:02:44 +00:00
|
|
|
app.commandLine.appendSwitch(
|
|
|
|
'basic-auth-password',
|
|
|
|
appArgs.basicAuthPassword,
|
|
|
|
);
|
2017-10-05 22:44:03 +00:00
|
|
|
}
|
|
|
|
|
Revamp and move to TypeScript (#898)
## Breaking changes
- Require **Node >= 8.10.0 and npm 5.6.0**
- Move to **Electron 8.1.1**.
- That's it. Lots of care went into breaking CLI & programmatic behavior
as little as possible. **Please report regressions**.
- Known issue: build may fail behind a proxy. Get in touch if you use one:
https://github.com/jiahaog/nativefier/issues/907#issuecomment-596144768
## Changes summary
Nativefier didn't get much love recently, to the point that it's
becoming hard to run on recent Node, due to old dependencies.
Also, some past practices now seem weird, as better expressible
by modern JS/TS, discouraging contributions including mine.
Addressing this, and one thing leading to another, came a
bigger-than-expected revamp, aiming at making Nativefier more
**lean, stable, future-proof, user-friendly and dev-friendly**,
while **not changing the CLI/programmatic interfaces**. Highlights:
- **Require Node>=8**, as imposed by many of our dependencies. Node 8
is twice LTS, and easily available even in conservative Linux distros.
No reason not to demand it.
- **Default to Electron 8**.
- **Bump** all dependencies to latest version, including electron-packager.
- **Move to TS**. TS is great. As of today, I see no reason not to use it,
and fight interface bugs at runtime rather than at compile time.
With that, get rid of everything Babel/Webpack.
- **Move away from Gulp**. Gulp's selling point is perf via streaming,
but for small builds like Nativefier, npm tasks are plenty good
and less dependency bloat. Gulp was the driver for this PR: broken
on Node 12, and I didn't feel like just upgrading and keeping it.
- Add tons of **verbose logs** everywhere it makes sense, to have a
fine & clear trace of the program flow. This will be helpful to
debug user-reported issues, and already helped me fix a few bugs.
- With better simple logging, get rid of the quirky and buggy
progress bar based on package `progress`. Nice logging (minimal
by default, the verbose logging mentioned above is only used
when passing `--verbose`) is better and one less dependency.
- **Dump `async` package**, a relic from old callback-hell early Node.
Also dump a few other micro-packages unnecessary now.
- A first pass of code **cleanup** thanks to modern JS/TS features:
fixes, simplifications, jsdoc type annotations to types, etc.
- **Remove GitHub integrations Hound & CodeClimate**, which are more
exotic than good'ol'linters, and whose signal-to-noise ratio is too low.
- Quality: **Add tests** and add **Windows + macOS CI builds**.
Also, add a **manual test script**, helping to quickly verify the
hard-to-programatically-test stuff before releases, and limit regressions.
- **Fix a very small number of existing bugs**. The goal of this PR was
*not* to fix bugs, but to get Nativefier in better shape to do so.
Bugfixes will come later. Still, these got addressed:
- Add common `Alt`+`Left`/`Right` for previous/next navigation.
- Improve #379: fix zoom with `Ctrl` + numpad `+`/`-`
- Fix pinch-to-zoom (see https://github.com/jiahaog/nativefier/issues/379#issuecomment-598612128 )
2020-03-15 20:50:01 +00:00
|
|
|
const isRunningMacos = isOSX();
|
|
|
|
let currentBadgeCount = 0;
|
|
|
|
const setDockBadge = isRunningMacos
|
|
|
|
? (count: number, bounce = false) => {
|
|
|
|
app.dock.setBadge(count.toString());
|
|
|
|
if (bounce && count > currentBadgeCount) app.dock.bounce();
|
|
|
|
currentBadgeCount = count;
|
|
|
|
}
|
|
|
|
: () => undefined;
|
2016-01-23 07:12:53 +00:00
|
|
|
|
2016-01-29 14:04:41 +00:00
|
|
|
app.on('window-all-closed', () => {
|
2017-04-29 14:52:12 +00:00
|
|
|
if (!isOSX() || appArgs.fastQuit) {
|
|
|
|
app.quit();
|
|
|
|
}
|
2015-07-05 06:08:13 +00:00
|
|
|
});
|
|
|
|
|
2016-01-29 14:04:41 +00:00
|
|
|
app.on('activate', (event, hasVisibleWindows) => {
|
2017-04-29 14:52:12 +00:00
|
|
|
if (isOSX()) {
|
2017-11-14 13:05:01 +00:00
|
|
|
// this is called when the dock is clicked
|
2017-04-29 14:52:12 +00:00
|
|
|
if (!hasVisibleWindows) {
|
|
|
|
mainWindow.show();
|
2016-01-21 04:25:33 +00:00
|
|
|
}
|
2017-04-29 14:52:12 +00:00
|
|
|
}
|
2016-01-21 04:25:33 +00:00
|
|
|
});
|
|
|
|
|
2016-01-29 14:04:41 +00:00
|
|
|
app.on('before-quit', () => {
|
2017-04-29 14:52:12 +00:00
|
|
|
// not fired when the close button on the window is clicked
|
|
|
|
if (isOSX()) {
|
|
|
|
// need to force a quit as a workaround here to simulate the osx app hiding behaviour
|
|
|
|
// Somehow sokution at https://github.com/atom/electron/issues/444#issuecomment-76492576 does not work,
|
|
|
|
// e.prevent default appears to persist
|
|
|
|
|
|
|
|
// might cause issues in the future as before-quit and will-quit events are not called
|
|
|
|
app.exit(0);
|
|
|
|
}
|
2016-01-21 04:25:33 +00:00
|
|
|
});
|
|
|
|
|
2016-10-09 05:52:50 +00:00
|
|
|
if (appArgs.crashReporter) {
|
2017-04-29 14:52:12 +00:00
|
|
|
app.on('will-finish-launching', () => {
|
|
|
|
crashReporter.start({
|
2017-07-21 19:55:39 +00:00
|
|
|
companyName: appArgs.companyName || '',
|
2017-04-29 14:52:12 +00:00
|
|
|
productName: appArgs.name,
|
|
|
|
submitURL: appArgs.crashReporter,
|
2018-05-01 23:29:03 +00:00
|
|
|
uploadToServer: true,
|
2016-10-09 05:52:50 +00:00
|
|
|
});
|
2017-04-29 14:52:12 +00:00
|
|
|
});
|
2016-10-09 05:52:50 +00:00
|
|
|
}
|
|
|
|
|
2019-03-25 15:16:28 +00:00
|
|
|
// quit if singleInstance mode and there's already another instance running
|
|
|
|
const shouldQuit = appArgs.singleInstance && !app.requestSingleInstanceLock();
|
|
|
|
if (shouldQuit) {
|
|
|
|
app.quit();
|
|
|
|
} else {
|
|
|
|
app.on('second-instance', () => {
|
|
|
|
if (mainWindow) {
|
|
|
|
if (!mainWindow.isVisible()) {
|
|
|
|
// try
|
|
|
|
mainWindow.show();
|
|
|
|
}
|
|
|
|
if (mainWindow.isMinimized()) {
|
|
|
|
// minimized
|
|
|
|
mainWindow.restore();
|
|
|
|
}
|
|
|
|
mainWindow.focus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
app.on('ready', () => {
|
Revamp and move to TypeScript (#898)
## Breaking changes
- Require **Node >= 8.10.0 and npm 5.6.0**
- Move to **Electron 8.1.1**.
- That's it. Lots of care went into breaking CLI & programmatic behavior
as little as possible. **Please report regressions**.
- Known issue: build may fail behind a proxy. Get in touch if you use one:
https://github.com/jiahaog/nativefier/issues/907#issuecomment-596144768
## Changes summary
Nativefier didn't get much love recently, to the point that it's
becoming hard to run on recent Node, due to old dependencies.
Also, some past practices now seem weird, as better expressible
by modern JS/TS, discouraging contributions including mine.
Addressing this, and one thing leading to another, came a
bigger-than-expected revamp, aiming at making Nativefier more
**lean, stable, future-proof, user-friendly and dev-friendly**,
while **not changing the CLI/programmatic interfaces**. Highlights:
- **Require Node>=8**, as imposed by many of our dependencies. Node 8
is twice LTS, and easily available even in conservative Linux distros.
No reason not to demand it.
- **Default to Electron 8**.
- **Bump** all dependencies to latest version, including electron-packager.
- **Move to TS**. TS is great. As of today, I see no reason not to use it,
and fight interface bugs at runtime rather than at compile time.
With that, get rid of everything Babel/Webpack.
- **Move away from Gulp**. Gulp's selling point is perf via streaming,
but for small builds like Nativefier, npm tasks are plenty good
and less dependency bloat. Gulp was the driver for this PR: broken
on Node 12, and I didn't feel like just upgrading and keeping it.
- Add tons of **verbose logs** everywhere it makes sense, to have a
fine & clear trace of the program flow. This will be helpful to
debug user-reported issues, and already helped me fix a few bugs.
- With better simple logging, get rid of the quirky and buggy
progress bar based on package `progress`. Nice logging (minimal
by default, the verbose logging mentioned above is only used
when passing `--verbose`) is better and one less dependency.
- **Dump `async` package**, a relic from old callback-hell early Node.
Also dump a few other micro-packages unnecessary now.
- A first pass of code **cleanup** thanks to modern JS/TS features:
fixes, simplifications, jsdoc type annotations to types, etc.
- **Remove GitHub integrations Hound & CodeClimate**, which are more
exotic than good'ol'linters, and whose signal-to-noise ratio is too low.
- Quality: **Add tests** and add **Windows + macOS CI builds**.
Also, add a **manual test script**, helping to quickly verify the
hard-to-programatically-test stuff before releases, and limit regressions.
- **Fix a very small number of existing bugs**. The goal of this PR was
*not* to fix bugs, but to get Nativefier in better shape to do so.
Bugfixes will come later. Still, these got addressed:
- Add common `Alt`+`Left`/`Right` for previous/next navigation.
- Improve #379: fix zoom with `Ctrl` + numpad `+`/`-`
- Fix pinch-to-zoom (see https://github.com/jiahaog/nativefier/issues/379#issuecomment-598612128 )
2020-03-15 20:50:01 +00:00
|
|
|
mainWindow = createMainWindow(appArgs, app.quit.bind(this), setDockBadge);
|
2019-03-25 15:16:28 +00:00
|
|
|
createTrayIcon(appArgs, mainWindow);
|
|
|
|
|
|
|
|
// Register global shortcuts
|
|
|
|
if (appArgs.globalShortcuts) {
|
|
|
|
appArgs.globalShortcuts.forEach((shortcut) => {
|
|
|
|
globalShortcut.register(shortcut.key, () => {
|
|
|
|
shortcut.inputEvents.forEach((inputEvent) => {
|
|
|
|
mainWindow.webContents.sendInputEvent(inputEvent);
|
|
|
|
});
|
2018-11-05 02:03:52 +00:00
|
|
|
});
|
|
|
|
});
|
2019-03-25 15:16:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-07-05 06:08:13 +00:00
|
|
|
|
2018-05-01 23:24:35 +00:00
|
|
|
app.on('new-window-for-tab', () => {
|
|
|
|
mainWindow.emit('new-tab');
|
|
|
|
});
|
|
|
|
|
2016-01-29 14:04:41 +00:00
|
|
|
app.on('login', (event, webContents, request, authInfo, callback) => {
|
2017-11-14 13:05:01 +00:00
|
|
|
// for http authentication
|
2017-04-29 14:52:12 +00:00
|
|
|
event.preventDefault();
|
2017-10-05 22:44:03 +00:00
|
|
|
|
2018-05-24 07:02:44 +00:00
|
|
|
if (
|
|
|
|
appArgs.basicAuthUsername !== null &&
|
|
|
|
appArgs.basicAuthPassword !== null
|
|
|
|
) {
|
2017-10-05 22:44:03 +00:00
|
|
|
callback(appArgs.basicAuthUsername, appArgs.basicAuthPassword);
|
|
|
|
} else {
|
|
|
|
createLoginWindow(callback);
|
|
|
|
}
|
2016-01-21 18:39:52 +00:00
|
|
|
});
|