webpacker-electron 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +85 -0
- data/Rakefile +13 -0
- data/lib/install/config/electron-builder.yml +52 -0
- data/lib/install/config/webpack/electron/main/development.js +5 -0
- data/lib/install/config/webpack/electron/main/production.js +30 -0
- data/lib/install/config/webpack/electron/renderer/development.js +70 -0
- data/lib/install/config/webpack/electron/renderer/production.js +37 -0
- data/lib/install/lib/javascript/babel.js +23 -0
- data/lib/install/lib/javascript/notarize.js +40 -0
- data/lib/install/public/electron.html +9 -0
- data/lib/install/src/packs/electron/main.js +217 -0
- data/lib/install/src/packs/electron/renderer.js +1 -0
- data/lib/install/template.rb +67 -0
- data/lib/tasks/webpacker.rake +66 -0
- data/lib/webpacker/electron.rb +8 -0
- data/lib/webpacker/electron/railtie.rb +12 -0
- data/lib/webpacker/electron/version.rb +5 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6a19dff91639322ec84b6bda44ad1bd6eb3c63b46de1d772364fd11c958a9030
|
4
|
+
data.tar.gz: 06f7eec37a5c5681da7b83ffae1558da61cbaa6f18af70a3933913a2cf36016b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f6b23f497b1eb37f2415e4bae735aadb9538eee018bb2ea9ec45f517371d0c922fb5b56cbe9e818d1ba42161cc446467bece1293d6ada80296d607f783857000
|
7
|
+
data.tar.gz: 686884c0190c08bf9c780eb0a00f8e84b43de45a03102e11014fb0813c852246ceca1c0efcfa8aeb37a04ab06716e6315d12fa5ed861b5acc17d2dfae41d7962
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2021 hpneo
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# Webpacker::Electron
|
2
|
+
Webpacker::Electron makes it easy to reuse your webpack-based JavaScript application files within an Electron app.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
Add this line to your application's `Gemfile`:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'webpacker-electron'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
```bash
|
13
|
+
bundle
|
14
|
+
```
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
bundle add webpacker-electron
|
20
|
+
```
|
21
|
+
|
22
|
+
Finally, run the following to install Webpacker::Electron:
|
23
|
+
|
24
|
+
```bash
|
25
|
+
bundle exec rails webpacker:install:electron
|
26
|
+
```
|
27
|
+
|
28
|
+
This command will create the following files:
|
29
|
+
|
30
|
+
* `config/electron-builder.yml`: Configuration file for [`electron-builder`](https://www.electron.build/).
|
31
|
+
* `config/webpack/electron/main/development.js`: Configuration file for Electron's main process (in development mode).
|
32
|
+
* `config/webpack/electron/main/production.js`: Configuration file for Electron's main process (in production mode).
|
33
|
+
* `config/webpack/electron/renderer/development.js`: Configuration file for Electron's renderer process (in development mode).
|
34
|
+
* `config/webpack/electron/renderer/production.js`: Configuration file for Electron's renderer process (in production mode).
|
35
|
+
* `lib/javascript/babel.js`: Babel configuration specific for Electron's main process.
|
36
|
+
* `public/electron.html`: Template for the renderer process, for both webpack dev server and production build.
|
37
|
+
* `src/packs/electron/main.js`: JavaScript pack for Electron's main process.
|
38
|
+
* `src/packs/electron/renderer.js`: JavaScript pack for Electron's renderer process.
|
39
|
+
|
40
|
+
It also updates the following files:
|
41
|
+
|
42
|
+
* `.gitignore`: Ignores `public/dist` and `public/packs-electron`.
|
43
|
+
* `config/webpack/environment.js`: Ignore Electron's related packs.
|
44
|
+
|
45
|
+
It also installs the following packages:
|
46
|
+
|
47
|
+
* `@babel/register`
|
48
|
+
* `dotenv`
|
49
|
+
* `dotenv-webpack`
|
50
|
+
* `electron`
|
51
|
+
* `electron-builder`
|
52
|
+
* `electron-devtools-installer`
|
53
|
+
* `electron-notarize`
|
54
|
+
* `electron-debug`
|
55
|
+
* `electron-log`
|
56
|
+
* `electron-updater`
|
57
|
+
* `concurrently`
|
58
|
+
* `cross-env`
|
59
|
+
|
60
|
+
## Usage
|
61
|
+
Once installed, you can start your JavaScript app in Rails as an Electron app with the following command:
|
62
|
+
|
63
|
+
```bash
|
64
|
+
bundle exec rails webpacker:start:electron
|
65
|
+
```
|
66
|
+
|
67
|
+
This task will run a webpack dev server for the renderer pack. Also, it will run `rails webpacker:start:electron:main` to start the actual Electron app.
|
68
|
+
|
69
|
+
### Package the Electron app
|
70
|
+
|
71
|
+
To package the JavaScript application into an Electron app, run the following:
|
72
|
+
|
73
|
+
```bash
|
74
|
+
rails webpacker:package:electron
|
75
|
+
```
|
76
|
+
|
77
|
+
First, it will compile the main and renderer packs for Electron, and then it will put the resulting output in an Electron app using `electron-builder`.
|
78
|
+
|
79
|
+
The app will be generated in `public/dist`.
|
80
|
+
|
81
|
+
## Contributing
|
82
|
+
Contribution directions go here.
|
83
|
+
|
84
|
+
## License
|
85
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
appId: com.worktimelabs.meet
|
2
|
+
productName: Worktime Meetings
|
3
|
+
extends: null
|
4
|
+
directories:
|
5
|
+
app: "."
|
6
|
+
buildResources: public/assets
|
7
|
+
output: public/dist/
|
8
|
+
files:
|
9
|
+
- "package.json"
|
10
|
+
- "!node_modules"
|
11
|
+
- from: public/packs-electron/
|
12
|
+
to: "."
|
13
|
+
filter: "**/main.production.js"
|
14
|
+
- from: public/packs-electron/
|
15
|
+
to: "."
|
16
|
+
filter: "**/index.html"
|
17
|
+
- from: public/packs-electron/
|
18
|
+
to: packs-electron/
|
19
|
+
filter: "**/*"
|
20
|
+
afterSign: lib/javascript/notarize.js
|
21
|
+
asar: true
|
22
|
+
extraMetadata:
|
23
|
+
main: "./main.production.js"
|
24
|
+
mac:
|
25
|
+
target:
|
26
|
+
- dmg
|
27
|
+
type: distribution
|
28
|
+
hardenedRuntime: true
|
29
|
+
entitlements: assets/entitlements.mac.plist
|
30
|
+
entitlementsInherit: assets/entitlements.mac.plist
|
31
|
+
gatekeeperAssess: false
|
32
|
+
dmg:
|
33
|
+
contents:
|
34
|
+
- x: 130
|
35
|
+
y: 220
|
36
|
+
- x: 410
|
37
|
+
y: 220
|
38
|
+
type: link
|
39
|
+
path: /Applications
|
40
|
+
win:
|
41
|
+
target:
|
42
|
+
- nsis
|
43
|
+
linux:
|
44
|
+
target:
|
45
|
+
- AppImage
|
46
|
+
category: Development
|
47
|
+
# extraResources:
|
48
|
+
# - ./assets/**
|
49
|
+
publish:
|
50
|
+
provider: github
|
51
|
+
owner: ableco
|
52
|
+
repo: worktime-meetings
|
@@ -0,0 +1,30 @@
|
|
1
|
+
process.env.NODE_ENV = process.env.NODE_ENV || "production";
|
2
|
+
|
3
|
+
const path = require("path");
|
4
|
+
const { config } = require("@rails/webpacker");
|
5
|
+
const environment = require("../../environment");
|
6
|
+
|
7
|
+
environment.entry.delete("application");
|
8
|
+
|
9
|
+
const electronConfig = {
|
10
|
+
target: "electron-main",
|
11
|
+
entry: {
|
12
|
+
electron: path.resolve(
|
13
|
+
config.source_path,
|
14
|
+
config.source_entry_path,
|
15
|
+
"electron/main.js",
|
16
|
+
),
|
17
|
+
},
|
18
|
+
output: {
|
19
|
+
path: path.resolve(config.outputPath, "../", "packs-electron"),
|
20
|
+
filename: "main.production.js",
|
21
|
+
},
|
22
|
+
node: {
|
23
|
+
__dirname: false,
|
24
|
+
__filename: false,
|
25
|
+
},
|
26
|
+
};
|
27
|
+
|
28
|
+
environment.config.merge(electronConfig);
|
29
|
+
|
30
|
+
module.exports = environment.toWebpackConfig();
|
@@ -0,0 +1,70 @@
|
|
1
|
+
/* eslint-disable unicorn/no-process-exit */
|
2
|
+
process.env.NODE_ENV = process.env.NODE_ENV || "development";
|
3
|
+
|
4
|
+
const port = process.env.ELECTRON_PORT || 1212;
|
5
|
+
const publicPath = `http://localhost:${port}/`;
|
6
|
+
|
7
|
+
const path = require("path");
|
8
|
+
const { spawn } = require("child_process");
|
9
|
+
const webpack = require("webpack");
|
10
|
+
const DotEnvPlugin = require("dotenv-webpack");
|
11
|
+
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
12
|
+
const { config } = require("@rails/webpacker");
|
13
|
+
const environment = require("../../environment");
|
14
|
+
|
15
|
+
environment.entry.delete("application");
|
16
|
+
|
17
|
+
const electronConfig = {
|
18
|
+
target: "electron-renderer",
|
19
|
+
entry: {
|
20
|
+
electron: path.resolve(
|
21
|
+
"./",
|
22
|
+
config.source_path,
|
23
|
+
config.source_entry_path,
|
24
|
+
"electron/renderer.js",
|
25
|
+
),
|
26
|
+
},
|
27
|
+
output: {
|
28
|
+
publicPath,
|
29
|
+
path: path.resolve(config.outputPath, "../", "packs-electron"),
|
30
|
+
filename: "renderer.development.js",
|
31
|
+
},
|
32
|
+
node: {
|
33
|
+
__dirname: false,
|
34
|
+
__filename: false,
|
35
|
+
},
|
36
|
+
plugins: [
|
37
|
+
new DotEnvPlugin(),
|
38
|
+
new webpack.LoaderOptionsPlugin({
|
39
|
+
debug: true,
|
40
|
+
}),
|
41
|
+
new HtmlWebpackPlugin({
|
42
|
+
title: "Worktime Meetings",
|
43
|
+
template: path.resolve(config.outputPath, "../", "electron.html"),
|
44
|
+
}),
|
45
|
+
],
|
46
|
+
devServer: {
|
47
|
+
port,
|
48
|
+
publicPath,
|
49
|
+
contentBase: path.resolve(config.outputPath, "../", "packs-electron"),
|
50
|
+
historyApiFallback: {
|
51
|
+
verbose: true,
|
52
|
+
disableDotRule: false,
|
53
|
+
},
|
54
|
+
before() {
|
55
|
+
console.log("Starting Main Process...");
|
56
|
+
|
57
|
+
spawn("bin/rails", ["webpacker:start:electron:main"], {
|
58
|
+
shell: true,
|
59
|
+
env: process.env,
|
60
|
+
stdio: "inherit",
|
61
|
+
})
|
62
|
+
.on("close", (code) => process.exit(code))
|
63
|
+
.on("error", (spawnError) => console.error(spawnError));
|
64
|
+
},
|
65
|
+
},
|
66
|
+
};
|
67
|
+
|
68
|
+
environment.config.merge(electronConfig);
|
69
|
+
|
70
|
+
module.exports = environment.toWebpackConfig();
|
@@ -0,0 +1,37 @@
|
|
1
|
+
process.env.NODE_ENV = process.env.NODE_ENV || "production";
|
2
|
+
|
3
|
+
const path = require("path");
|
4
|
+
const DotEnvPlugin = require("dotenv-webpack");
|
5
|
+
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
6
|
+
const { config } = require("@rails/webpacker");
|
7
|
+
const environment = require("../../environment");
|
8
|
+
|
9
|
+
environment.entry.delete("application");
|
10
|
+
|
11
|
+
const electronConfig = {
|
12
|
+
target: "electron-renderer",
|
13
|
+
entry: {
|
14
|
+
electron: path.resolve(
|
15
|
+
"./",
|
16
|
+
config.source_path,
|
17
|
+
config.source_entry_path,
|
18
|
+
"electron/renderer.js",
|
19
|
+
),
|
20
|
+
},
|
21
|
+
output: {
|
22
|
+
path: path.resolve(config.outputPath, "../", "packs-electron"),
|
23
|
+
publicPath: "/packs-electron/",
|
24
|
+
filename: "renderer.production.js",
|
25
|
+
},
|
26
|
+
plugins: [
|
27
|
+
new DotEnvPlugin(),
|
28
|
+
new HtmlWebpackPlugin({
|
29
|
+
title: "Worktime Meetings",
|
30
|
+
template: path.resolve(config.outputPath, "../", "electron.html"),
|
31
|
+
}),
|
32
|
+
],
|
33
|
+
};
|
34
|
+
|
35
|
+
environment.config.merge(electronConfig);
|
36
|
+
|
37
|
+
module.exports = environment.toWebpackConfig();
|
@@ -0,0 +1,23 @@
|
|
1
|
+
const path = require("path");
|
2
|
+
|
3
|
+
require("@babel/register")({
|
4
|
+
extensions: [".es6", ".es", ".jsx", ".js", ".mjs", ".ts", ".tsx"],
|
5
|
+
cwd: path.join(__dirname, "../.."),
|
6
|
+
overrides: [
|
7
|
+
{
|
8
|
+
test: "./src/packs/electron",
|
9
|
+
presets: [
|
10
|
+
[
|
11
|
+
"@babel/preset-env",
|
12
|
+
{
|
13
|
+
forceAllTransforms: true,
|
14
|
+
useBuiltIns: "entry",
|
15
|
+
corejs: 3,
|
16
|
+
modules: "auto",
|
17
|
+
exclude: ["transform-typeof-symbol"],
|
18
|
+
},
|
19
|
+
],
|
20
|
+
],
|
21
|
+
},
|
22
|
+
],
|
23
|
+
});
|
@@ -0,0 +1,40 @@
|
|
1
|
+
const { notarize } = require("electron-notarize");
|
2
|
+
const YAML = require("yaml");
|
3
|
+
const fs = require("fs");
|
4
|
+
const { promisify } = require("util");
|
5
|
+
|
6
|
+
const readFile = promisify(fs.readFile);
|
7
|
+
|
8
|
+
exports.default = async function notarizeMacOS(context) {
|
9
|
+
const { electronPlatformName, appOutDir } = context;
|
10
|
+
if (electronPlatformName !== "darwin") {
|
11
|
+
return;
|
12
|
+
}
|
13
|
+
|
14
|
+
if (!process.env.CI) {
|
15
|
+
console.warn("Skipping notarizing step. Packaging is not running in CI");
|
16
|
+
return;
|
17
|
+
}
|
18
|
+
|
19
|
+
if (!("APPLE_ID" in process.env && "APPLE_ID_PASS" in process.env)) {
|
20
|
+
console.warn(
|
21
|
+
"Skipping notarizing step. APPLE_ID and APPLE_ID_PASS env variables must be set",
|
22
|
+
);
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
|
26
|
+
const electronBuilderConfig = await readFile(
|
27
|
+
"../../config/electron-builder.yml",
|
28
|
+
"utf8",
|
29
|
+
);
|
30
|
+
const buildInfo = YAML.parse(electronBuilderConfig);
|
31
|
+
|
32
|
+
const appName = context.packager.appInfo.productFilename;
|
33
|
+
|
34
|
+
await notarize({
|
35
|
+
appBundleId: buildInfo.appId,
|
36
|
+
appPath: `${appOutDir}/${appName}.app`,
|
37
|
+
appleId: process.env.APPLE_ID,
|
38
|
+
appleIdPassword: process.env.APPLE_ID_PASS,
|
39
|
+
});
|
40
|
+
};
|
@@ -0,0 +1,217 @@
|
|
1
|
+
/* eslint-disable no-console */
|
2
|
+
/**
|
3
|
+
* This module executes inside of electron's main process. You can start
|
4
|
+
* electron renderer process from here and communicate with the other processes
|
5
|
+
* through IPC.
|
6
|
+
*/
|
7
|
+
import "core-js/stable";
|
8
|
+
import "regenerator-runtime/runtime";
|
9
|
+
import path from "path";
|
10
|
+
import { app, session, protocol, BrowserWindow, shell } from "electron";
|
11
|
+
import { autoUpdater } from "electron-updater";
|
12
|
+
import log from "electron-log";
|
13
|
+
import fs from "fs";
|
14
|
+
import { promisify } from "util";
|
15
|
+
|
16
|
+
const stat = promisify(fs.stat);
|
17
|
+
|
18
|
+
const FILE_NOT_FOUND = -6;
|
19
|
+
|
20
|
+
const getPath = async (path_) => {
|
21
|
+
try {
|
22
|
+
const result = await stat(path_);
|
23
|
+
|
24
|
+
if (result.isFile()) {
|
25
|
+
return path_;
|
26
|
+
}
|
27
|
+
|
28
|
+
if (result.isDirectory()) {
|
29
|
+
return getPath(path.join(path_, "index.html"));
|
30
|
+
}
|
31
|
+
} catch (_) {}
|
32
|
+
};
|
33
|
+
|
34
|
+
function serve(baseOptions) {
|
35
|
+
const options = Object.assign(
|
36
|
+
{
|
37
|
+
isCorsEnabled: true,
|
38
|
+
scheme: "app",
|
39
|
+
},
|
40
|
+
baseOptions,
|
41
|
+
);
|
42
|
+
|
43
|
+
if (!options.directory) {
|
44
|
+
throw new Error("The `directory` option is required");
|
45
|
+
}
|
46
|
+
|
47
|
+
options.directory = path.resolve(app.getAppPath(), options.directory);
|
48
|
+
|
49
|
+
const handler = async (request, callback) => {
|
50
|
+
const indexPath = path.join(options.directory, "index.html");
|
51
|
+
const filePath = path.join(
|
52
|
+
options.directory,
|
53
|
+
decodeURIComponent(new URL(request.url).pathname),
|
54
|
+
);
|
55
|
+
const resolvedPath = await getPath(filePath);
|
56
|
+
const fileExtension = path.extname(filePath);
|
57
|
+
|
58
|
+
if (
|
59
|
+
resolvedPath ||
|
60
|
+
!fileExtension ||
|
61
|
+
fileExtension === ".html" ||
|
62
|
+
fileExtension === ".asar"
|
63
|
+
) {
|
64
|
+
callback({
|
65
|
+
path: resolvedPath || indexPath,
|
66
|
+
});
|
67
|
+
} else {
|
68
|
+
callback({ error: FILE_NOT_FOUND });
|
69
|
+
}
|
70
|
+
};
|
71
|
+
|
72
|
+
protocol.registerSchemesAsPrivileged([
|
73
|
+
{
|
74
|
+
scheme: options.scheme,
|
75
|
+
privileges: {
|
76
|
+
standard: true,
|
77
|
+
secure: true,
|
78
|
+
allowServiceWorkers: true,
|
79
|
+
supportFetchAPI: true,
|
80
|
+
corsEnabled: options.isCorsEnabled,
|
81
|
+
},
|
82
|
+
},
|
83
|
+
]);
|
84
|
+
|
85
|
+
app.on("ready", () => {
|
86
|
+
const protocolSession = options.partition
|
87
|
+
? session.fromPartition(options.partition)
|
88
|
+
: session.defaultSession;
|
89
|
+
|
90
|
+
protocolSession.protocol.registerFileProtocol(options.scheme, handler);
|
91
|
+
});
|
92
|
+
|
93
|
+
return async (window_) => {
|
94
|
+
await window_.loadURL(`${options.scheme}://-`);
|
95
|
+
};
|
96
|
+
}
|
97
|
+
|
98
|
+
const loadURL = serve({
|
99
|
+
directory: ".",
|
100
|
+
});
|
101
|
+
|
102
|
+
export default class AppUpdater {
|
103
|
+
constructor() {
|
104
|
+
log.transports.file.level = "info";
|
105
|
+
autoUpdater.logger = log;
|
106
|
+
autoUpdater.checkForUpdatesAndNotify();
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
let mainWindow = null;
|
111
|
+
|
112
|
+
if (process.env.NODE_ENV === "production") {
|
113
|
+
const sourceMapSupport = require("source-map-support");
|
114
|
+
sourceMapSupport.install();
|
115
|
+
}
|
116
|
+
|
117
|
+
if (
|
118
|
+
process.env.NODE_ENV === "development" ||
|
119
|
+
process.env.DEBUG_PROD === "true"
|
120
|
+
) {
|
121
|
+
require("electron-debug")();
|
122
|
+
}
|
123
|
+
|
124
|
+
const installExtensions = async () => {
|
125
|
+
const installer = require("electron-devtools-installer");
|
126
|
+
const forceDownload = !!process.env.UPGRADE_EXTENSIONS;
|
127
|
+
const extensions = ["REACT_DEVELOPER_TOOLS"];
|
128
|
+
|
129
|
+
return installer
|
130
|
+
.default(
|
131
|
+
extensions.map((name) => installer[name]),
|
132
|
+
forceDownload,
|
133
|
+
)
|
134
|
+
.catch(console.log);
|
135
|
+
};
|
136
|
+
|
137
|
+
const createWindow = async () => {
|
138
|
+
if (
|
139
|
+
process.env.NODE_ENV === "development" ||
|
140
|
+
process.env.DEBUG_PROD === "true"
|
141
|
+
) {
|
142
|
+
await installExtensions();
|
143
|
+
}
|
144
|
+
|
145
|
+
const RESOURCES_PATH = app.isPackaged
|
146
|
+
? path.join(process.resourcesPath, "assets")
|
147
|
+
: path.join(__dirname, "../assets");
|
148
|
+
|
149
|
+
const getAssetPath = (...paths) => {
|
150
|
+
return path.join(RESOURCES_PATH, ...paths);
|
151
|
+
};
|
152
|
+
|
153
|
+
mainWindow = new BrowserWindow({
|
154
|
+
show: false,
|
155
|
+
width: 1024,
|
156
|
+
height: 728,
|
157
|
+
icon: getAssetPath("icon.png"),
|
158
|
+
webPreferences: {
|
159
|
+
nodeIntegration: true,
|
160
|
+
devTools: true,
|
161
|
+
},
|
162
|
+
});
|
163
|
+
|
164
|
+
if (process.env.NODE_ENV === "development") {
|
165
|
+
mainWindow.loadURL("http://localhost:1212");
|
166
|
+
} else {
|
167
|
+
loadURL(mainWindow);
|
168
|
+
}
|
169
|
+
// @TODO: Use 'ready-to-show' event
|
170
|
+
// https://github.com/electron/electron/blob/master/docs/api/browser-window.md#using-ready-to-show-event
|
171
|
+
mainWindow.webContents.on("did-finish-load", () => {
|
172
|
+
if (!mainWindow) {
|
173
|
+
throw new Error('"mainWindow" is not defined');
|
174
|
+
}
|
175
|
+
if (process.env.START_MINIMIZED) {
|
176
|
+
mainWindow.minimize();
|
177
|
+
} else {
|
178
|
+
mainWindow.show();
|
179
|
+
mainWindow.focus();
|
180
|
+
}
|
181
|
+
});
|
182
|
+
|
183
|
+
mainWindow.webContents.session.clearStorageData();
|
184
|
+
|
185
|
+
mainWindow.on("closed", () => {
|
186
|
+
mainWindow = null;
|
187
|
+
});
|
188
|
+
|
189
|
+
// Open urls in the user's browser
|
190
|
+
mainWindow.webContents.on("new-window", (event, url) => {
|
191
|
+
event.preventDefault();
|
192
|
+
shell.openExternal(url);
|
193
|
+
});
|
194
|
+
|
195
|
+
// Remove this if your app does not use auto updates
|
196
|
+
new AppUpdater();
|
197
|
+
};
|
198
|
+
|
199
|
+
/**
|
200
|
+
* Add event listeners...
|
201
|
+
*/
|
202
|
+
|
203
|
+
app.on("window-all-closed", () => {
|
204
|
+
// Respect the OSX convention of having the application in memory even
|
205
|
+
// after all windows have been closed
|
206
|
+
if (process.platform !== "darwin") {
|
207
|
+
app.quit();
|
208
|
+
}
|
209
|
+
});
|
210
|
+
|
211
|
+
app.whenReady().then(createWindow).catch(console.log);
|
212
|
+
|
213
|
+
app.on("activate", () => {
|
214
|
+
// On macOS it's common to re-create a window in the app when the
|
215
|
+
// dock icon is clicked and there are no other windows open.
|
216
|
+
if (mainWindow === null) createWindow();
|
217
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
import "../application.js";
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "webpacker/configuration"
|
2
|
+
|
3
|
+
say "Checking for package's name and version"
|
4
|
+
package = JSON.parse(File.read(Rails.root.join("package.json")))
|
5
|
+
|
6
|
+
if package["name"].present? && package["version"].present?
|
7
|
+
say "Adding Electron to #{package['name']}@#{package['version']}", :blue
|
8
|
+
else
|
9
|
+
say "Couldn't find a name or version for this application. Add a 'name' or 'version' in your package.json", :red
|
10
|
+
return
|
11
|
+
end
|
12
|
+
|
13
|
+
say "Copying Webpacker configuration files for Electron"
|
14
|
+
|
15
|
+
directory "#{__dir__}/config/webpack/electron", "config/webpack/electron"
|
16
|
+
copy_file "#{__dir__}/config/electron-builder.yml", "config/electron-builder.yml"
|
17
|
+
copy_file "#{__dir__}/lib/javascript/babel.js", "lib/javascript/babel.js"
|
18
|
+
copy_file "#{__dir__}/lib/javascript/notarize.js", "lib/javascript/notarize.js"
|
19
|
+
|
20
|
+
say "Updating webpack environment configuration to ignore Electron packs"
|
21
|
+
|
22
|
+
unless File.read(Rails.root.join("config/webpack/environment.js")).include?(".filter((key) => key.match(/^electron/))")
|
23
|
+
insert_into_file Rails.root.join("config/webpack/environment.js"), after: "const { environment } = require(\"@rails/webpacker\");\n" do
|
24
|
+
<<~JS
|
25
|
+
|
26
|
+
Object.keys(environment.entry)
|
27
|
+
.filter((key) => key.match(/^electron/))
|
28
|
+
.forEach((entry) => {
|
29
|
+
environment.entry.delete(entry);
|
30
|
+
});
|
31
|
+
|
32
|
+
JS
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
if File.exists?(Rails.root.join(".gitignore"))
|
37
|
+
unless File.read(Rails.root.join(".gitignore")).include?("public/packs-electron")
|
38
|
+
append_to_file Rails.root.join(".gitignore") do
|
39
|
+
<<~TEXT
|
40
|
+
|
41
|
+
# Electron
|
42
|
+
public/packs-electron
|
43
|
+
public/dist
|
44
|
+
|
45
|
+
TEXT
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
say "Creating dist directories for Electron builds"
|
51
|
+
|
52
|
+
empty_directory "public/packs-electron"
|
53
|
+
empty_directory "public/dist"
|
54
|
+
empty_directory "public/assets/icons"
|
55
|
+
|
56
|
+
say "Copying Electron packs and entry files to #{Webpacker.config.source_entry_path}"
|
57
|
+
|
58
|
+
directory "#{__dir__}/src/packs/electron", "#{Webpacker.config.source_entry_path}/electron"
|
59
|
+
copy_file "#{__dir__}/public/electron.html", "public/electron.html"
|
60
|
+
|
61
|
+
say "Installing all Electron dependencies"
|
62
|
+
|
63
|
+
run "yarn add --dev electron electron-builder electron-notarize electron-devtools-installer @babel/register dotenv dotenv-webpack html-webpack-plugin@4.5.1 concurrently cross-env yaml"
|
64
|
+
run "yarn add electron-updater electron-log electron-debug"
|
65
|
+
run "yarn run electron-builder install-app-deps"
|
66
|
+
|
67
|
+
say "Webpacker now supports Electron 🎉", :green
|
@@ -0,0 +1,66 @@
|
|
1
|
+
bin_path = ENV["BUNDLE_BIN"] || Rails.root.join("bin")
|
2
|
+
|
3
|
+
namespace :webpacker do
|
4
|
+
desc "Install everything needed for Electron"
|
5
|
+
task "install:electron": ["webpacker:check_yarn"] do |task|
|
6
|
+
prefix = task.name.split(/#|webpacker:install/).first
|
7
|
+
install_template_path = template_path("../install/template.rb")
|
8
|
+
|
9
|
+
if Rails::VERSION::MAJOR >= 5
|
10
|
+
Kernel.exec "#{RbConfig.ruby} #{bin_path}/rails #{prefix}app:template LOCATION=#{install_template_path}"
|
11
|
+
else
|
12
|
+
Kernel.exec "#{RbConfig.ruby} #{bin_path}/rake #{prefix}rails:template LOCATION=#{install_template_path}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Start Electron app"
|
17
|
+
task "start:electron": ["webpacker:verify_install", :environment] do
|
18
|
+
webpacker_config_path = Webpacker.config.config_path.dirname.join("webpack", "electron")
|
19
|
+
|
20
|
+
Dir.chdir(Rails.root) do
|
21
|
+
Kernel.exec "yarn run cross-env NODE_ENV=development webpack-dev-server --config #{webpacker_config_path.join('renderer', 'development.js')}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Start Electron main process"
|
26
|
+
task "start:electron:main": ["webpacker:verify_install", :environment] do
|
27
|
+
source_entry_path = Webpacker.config.source_entry_path.join("electron")
|
28
|
+
|
29
|
+
Dir.chdir(Rails.root) do
|
30
|
+
Kernel.exec "yarn run cross-env NODE_ENV=development electron -r ./lib/javascript/babel #{source_entry_path.join('main.js')}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Compile JavaScript packs using webpack for Electron"
|
35
|
+
task "compile:electron": ["webpacker:verify_install", :environment] do
|
36
|
+
webpacker_config_path = Webpacker.config.config_path.dirname.join("webpack", "electron")
|
37
|
+
|
38
|
+
compile_electron_main = "yarn run cross-env RAILS_ENV=production NODE_ENV=production webpack --config #{webpacker_config_path.join('main', 'production.js')}"
|
39
|
+
compile_electron_renderer = "yarn run cross-env RAILS_ENV=production NODE_ENV=production webpack --config #{webpacker_config_path.join('renderer', 'production.js')}"
|
40
|
+
|
41
|
+
Dir.chdir(Rails.root) do
|
42
|
+
Kernel.exec "yarn run concurrently \"#{compile_electron_main}\" \"#{compile_electron_renderer}\""
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "Package Electron app"
|
47
|
+
task "package:electron": ["webpacker:verify_install", :environment] do
|
48
|
+
electron_builder_config_path = Rails.root.join("config", "electron-builder.yml")
|
49
|
+
|
50
|
+
if Rails::VERSION::MAJOR >= 5
|
51
|
+
compile_task = "#{RbConfig.ruby} #{bin_path}/rails webpacker:compile:electron"
|
52
|
+
else
|
53
|
+
compile_task = "#{RbConfig.ruby} #{bin_path}/rake webpacker:compile:electron"
|
54
|
+
end
|
55
|
+
|
56
|
+
Dir.chdir(Rails.root) do
|
57
|
+
Kernel.exec "rm -rf public/dist && #{compile_task} && yarn run electron-builder build --config #{electron_builder_config_path} --publish never"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def template_path(template)
|
65
|
+
File.expand_path(template, __dir__).freeze
|
66
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webpacker-electron
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Able
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-02-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 6.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 6.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: webpacker
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.76'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.76'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop-able
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.2.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.2.2
|
69
|
+
description: Use webpacker configuration to build Electron apps using the same codebase.
|
70
|
+
email:
|
71
|
+
- engineering@able.co
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- MIT-LICENSE
|
77
|
+
- README.md
|
78
|
+
- Rakefile
|
79
|
+
- lib/install/config/electron-builder.yml
|
80
|
+
- lib/install/config/webpack/electron/main/development.js
|
81
|
+
- lib/install/config/webpack/electron/main/production.js
|
82
|
+
- lib/install/config/webpack/electron/renderer/development.js
|
83
|
+
- lib/install/config/webpack/electron/renderer/production.js
|
84
|
+
- lib/install/lib/javascript/babel.js
|
85
|
+
- lib/install/lib/javascript/notarize.js
|
86
|
+
- lib/install/public/electron.html
|
87
|
+
- lib/install/src/packs/electron/main.js
|
88
|
+
- lib/install/src/packs/electron/renderer.js
|
89
|
+
- lib/install/template.rb
|
90
|
+
- lib/tasks/webpacker.rake
|
91
|
+
- lib/webpacker/electron.rb
|
92
|
+
- lib/webpacker/electron/railtie.rb
|
93
|
+
- lib/webpacker/electron/version.rb
|
94
|
+
homepage: https://github.com/ableco/webpacker-electron
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata:
|
98
|
+
allowed_push_host: https://rubygems.org
|
99
|
+
homepage_uri: https://github.com/ableco/webpacker-electron
|
100
|
+
source_code_uri: https://github.com/ableco/webpacker-electron
|
101
|
+
changelog_uri: https://github.com/ableco/webpacker-electron/blob/master/CHANGELOG.md
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubygems_version: 3.1.4
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: Electron integration for Webpacker.
|
121
|
+
test_files: []
|