mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2025-01-22 22:58:33 +00:00
Support creating self-contained "portable" apps writing their app data to the app folder (fix #376) (PR #1168)
In response to #376 Co-authored-by: Ronan Jouchet <ronan@jouchet.fr>
This commit is contained in:
parent
dd6e15fb5c
commit
7dc189ef3f
@ -1,6 +1,7 @@
|
||||
import 'source-map-support/register';
|
||||
|
||||
import fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
import {
|
||||
app,
|
||||
@ -30,6 +31,16 @@ if (require('electron-squirrel-startup')) {
|
||||
|
||||
const appArgs = JSON.parse(fs.readFileSync(APP_ARGS_FILE_PATH, 'utf8'));
|
||||
|
||||
// Do this relatively early so that we can start storing appData with the app
|
||||
if (appArgs.portable) {
|
||||
log.debug(
|
||||
'App was built as portable; setting appData and userData to the app folder: ',
|
||||
path.resolve(path.join(__dirname, '..', 'appData')),
|
||||
);
|
||||
app.setPath('appData', path.join(__dirname, '..', 'appData'));
|
||||
app.setPath('userData', path.join(__dirname, '..', 'appData'));
|
||||
}
|
||||
|
||||
// Take in a URL on the command line as an override
|
||||
if (process.argv.length > 1) {
|
||||
const maybeUrl = process.argv[1];
|
||||
|
21
docs/api.md
21
docs/api.md
@ -27,6 +27,7 @@
|
||||
- [Manually Converting `.icns`](#manually-converting-icns)
|
||||
- [[counter]](#counter)
|
||||
- [[bounce]](#bounce)
|
||||
- [[portable]](#portable)
|
||||
- [[width]](#width)
|
||||
- [[height]](#height)
|
||||
- [[min-width]](#min-width)
|
||||
@ -296,6 +297,26 @@ Use a counter that persists even with window focus for the application badge for
|
||||
|
||||
(macOS only) When the counter increases, the dock icon will bounce for one second. This only works if the `--counter` option is active.
|
||||
|
||||
#### [portable]
|
||||
|
||||
```
|
||||
--portable
|
||||
```
|
||||
|
||||
Make your app store its user data (cookies, cache, etc) inside the app folder, making it "portable" in the sense popularized by [PortableApps.com](https://portableapps.com/): you can carry it around e.g. on a USB key, and it will work the same with your data.
|
||||
|
||||
**IMPORTANT SECURITY NOTICE**
|
||||
|
||||
When creating a portable app, all data accumulated after running the app (including login information, cache, cookies), will be saved in the app folder. If this app is then shared with others, THEY WILL HAVE THAT ACCUMULATED DATA, POTENTIALLY INCLUDING ACCESS TO ANY ACCOUNTS YOU LOGGED INTO.
|
||||
|
||||
→ Best practice to *distribute apps* using this flag:
|
||||
|
||||
1. Create your application with this flag
|
||||
2. Test it
|
||||
3. Delete your application and containing folder
|
||||
4. Recreate it in the same way you did in step 1
|
||||
5. Distribute the app without opening it
|
||||
|
||||
#### [width]
|
||||
|
||||
```
|
||||
|
@ -67,6 +67,7 @@ function pickElectronAppArgs(options: AppOptions): any {
|
||||
nativefierVersion: options.nativefier.nativefierVersion,
|
||||
osxNotarize: options.packager.osxNotarize,
|
||||
osxSign: options.packager.osxSign,
|
||||
portable: options.packager.portable,
|
||||
processEnvs: options.nativefier.processEnvs,
|
||||
protocols: options.packager.protocols,
|
||||
proxyRules: options.nativefier.proxyRules,
|
||||
|
@ -131,6 +131,10 @@ if (require.main === module) {
|
||||
'-i, --icon <value>',
|
||||
'the icon file to use as the icon for the app (should be a .png, on macOS can also be an .icns)',
|
||||
)
|
||||
.option(
|
||||
'--portable',
|
||||
'Make the app store its user data in the app folder. WARNING: see https://github.com/nativefier/nativefier/blob/master/docs/api.md#portable for security risks',
|
||||
)
|
||||
.option(
|
||||
'--width <value>',
|
||||
'set window default width; defaults to 1280px',
|
||||
|
@ -1,8 +1,9 @@
|
||||
import * as electronPackager from 'electron-packager';
|
||||
|
||||
export interface ElectronPackagerOptions extends electronPackager.Options {
|
||||
targetUrl: string;
|
||||
portable: boolean;
|
||||
platform: string;
|
||||
targetUrl: string;
|
||||
upgrade: boolean;
|
||||
upgradeFrom?: string;
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ export async function getOptions(rawOptions: any): Promise<AppOptions> {
|
||||
out: rawOptions.out || process.cwd(),
|
||||
overwrite: rawOptions.overwrite,
|
||||
platform: rawOptions.platform || inferPlatform(),
|
||||
portable: rawOptions.portable || false,
|
||||
targetUrl:
|
||||
rawOptions.targetUrl === undefined
|
||||
? '' // We'll plug this in later via upgrade
|
||||
@ -192,8 +193,19 @@ export async function getOptions(rawOptions: any): Promise<AppOptions> {
|
||||
options.nativefier.height = options.nativefier.maxHeight;
|
||||
}
|
||||
|
||||
if (options.packager.portable) {
|
||||
log.info(
|
||||
'Building app as portable.',
|
||||
'SECURITY WARNING: all data accumulated in the app folder after running it',
|
||||
'(including login information, cache, cookies) will be saved',
|
||||
'in the app folder. If this app is then shared with others,',
|
||||
'THEY WILL HAVE THAT ACCUMULATED DATA, POTENTIALLY INCLUDING ACCESS',
|
||||
'TO ANY ACCOUNTS YOU LOGGED INTO.',
|
||||
);
|
||||
}
|
||||
|
||||
if (rawOptions.globalShortcuts) {
|
||||
log.debug('Use global shortcuts file at', rawOptions.globalShortcuts);
|
||||
log.debug('Using global shortcuts file at', rawOptions.globalShortcuts);
|
||||
const globalShortcuts = JSON.parse(
|
||||
fs.readFileSync(rawOptions.globalShortcuts).toString(),
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user