Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packaging for macOS #28

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Package
on: push
jobs:
package:
name: Package
runs-on: macos-10.15
steps:
- uses: actions/checkout@v2
with:
persist-credentials: false
- uses: actions/setup-node@v2
with:
node-version: '14'
- run: npm ci
- run: npm run make
- uses: actions/upload-artifact@v2
with:
name: packages
path: out/make/**
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ resources/darwin/bin/
dist
.idea/
*~
/out/
/.webpack/
22 changes: 21 additions & 1 deletion background.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { app, ipcMain, dialog } = require('electron');
const { app, ipcMain, dialog, protocol } = require('electron');
const deepmerge = require('deepmerge');
const path = require('path');
const url = require('url');
const settings = require('./src/config/settings.js');
const tray = require('./src/menu/tray.js');
const window = require('./src/window/window.js');
Expand All @@ -13,6 +15,24 @@ let cfg;

app.whenReady().then(() => {

// Set up protocol handler for app://
// This is needed because in packaged builds we'll not be allowed to access
// file:// URLs for our resources.
protocol.registerFileProtocol('app', (request, callback) => {
let relPath = (new URL(request.url)).pathname;
// Default to the path for development mode, running out of the source tree.
let absPath = path.join(app.getAppPath(), ".webpack", relPath);
if (app.isPackaged) {
// electron-forge replaces MAIN_WINDOW_WEBPACK_ENTRY with the path to
// the index.html, but we want to find top of the .asar if available.
/*global MAIN_WINDOW_WEBPACK_ENTRY */ // Quiet ESLint warning
let rootURL = MAIN_WINDOW_WEBPACK_ENTRY.replace(/\.webpack\/.*$/, '');
let root = url.fileURLToPath(rootURL);
absPath = path.join(root, ".webpack", relPath);
}
callback({ path: absPath });
});

tray.init();

// TODO: Check if first install and start welcome screen
Expand Down
73 changes: 73 additions & 0 deletions forge.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* This script is configuration for electron-forge; since we use vue-cli-service
* for development, the easiest thing to do here is to just run that code to
* generate the expected webpack configuration and pass it to electron-forge.
*/
'use strict';

const VueCliService = require('@vue/cli-service/lib/Service');

const service = new VueCliService(__dirname);
const mode = (process.env.NODE_ENV === 'DEV') ? 'development' : 'production';
service.init(mode);
const config = service.resolveWebpackConfig();
// Delete the output options; we need to use the defaults so electron-forge can
// find the results.
delete config.output;

// Forge wraps the config in a proxy; some of the plugin configs have `null` as
// a value, which the proxy doesn't like. Fix them here.
for (let plugin of config.plugins) {
switch (plugin.constructor.name) {
case "HashedModuleIdsPlugin":
if (plugin.options && plugin.options.context === null) {
// The code does `options.context ? options.context : fallback`
// so it works to set it to `false` here.
plugin.options.context = false;
}
break;
}
}

module.exports = {
packagerConfig: {
asar: true,
extraResource: ["resources"],
},
plugins: [
["@electron-forge/plugin-webpack",
{
mainConfig: {
entry: "./background.js",
module: {
rules: [
{ test: /\.js$/, use: ['cache-loader', 'babel-loader'] },
]
}
},
renderer: {
config: config,
entryPoints: [{ js: "./src/main.js", name: "main_window" }]
}
}
]
],
makers: [
{
name: "@electron-forge/maker-squirrel",
config: { name: "rancher_desktop" }
},
{
name: "@electron-forge/maker-zip",
platforms: ["darwin"]
}
],
hooks: {
readPackageJson: (forgeConfig, packageJson) => {
// Override the main entrypoint, because we manually run through
// webpack when packaging.
packageJson.main = '.webpack/main';
return packageJson;
}
}
}
Loading