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

Make zip builds more portable (python & ffmpeg) #1484

Merged
merged 5 commits into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
102 changes: 102 additions & 0 deletions forge.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
const AdmZip = require('adm-zip');

module.exports = {
packagerConfig: {
executableName: 'chainner',
extraResource: './backend/src/',
icon: './src/public/icons/cross_platform/icon',
},
publishers: [
{
name: '@electron-forge/publisher-github',
config: {
repository: {
owner: 'chaiNNer-org',
name: 'chaiNNer',
},
},
draft: true,
prerelease: true,
},
],
makers: [
{
name: '@electron-forge/maker-squirrel',
config: {
name: 'chainner',
iconUrl:
'https://github.com/chaiNNer-org/chaiNNer/blob/main/src/public/icons/win/icon.ico',
setupIcon: './src/public/icons/win/icon.ico',
loadingGif: './src/public/icons/win/installing_loop.gif',
},
},
{
name: '@electron-forge/maker-zip',
platforms: ['darwin', 'linux', 'win32'],
},
{
name: '@electron-forge/maker-dmg',
config: {
format: 'ULFO',
name: 'chaiNNer',
icon: './src/public/icons/mac/icon.icns',
},
},
{
name: '@electron-forge/maker-deb',
config: {
name: 'chainner',
options: {
icon: './src/public/icons/cross_platform/icon.png',
},
},
},
{
name: '@electron-forge/maker-rpm',
config: {
name: 'chainner',
options: {
icon: './src/public/icons/cross_platform/icon.png',
},
},
},
],
plugins: [
{
name: '@electron-forge/plugin-webpack',
config: {
mainConfig: './webpack.main.config.js',
renderer: {
config: './webpack.renderer.config.js',
nodeIntegration: true,
contextIsolation: false,
entryPoints: [
{
html: './src/renderer/index.html',
js: './src/renderer/renderer.js',
name: 'main_window',
},
{
html: './src/renderer/splash.html',
js: './src/renderer/splash_renderer.js',
name: 'splash_screen',
},
],
},
devContentSecurityPolicy: '',
},
},
],
hooks: {
postMake: async (forgeConfig, makeResults) => {
const justArtifacts = makeResults.map((m) => m.artifacts).reduce((a, b) => a.concat(b));
const zipArtifact = justArtifacts.find((a) => a.endsWith('.zip'));
if (zipArtifact) {
// Add an empty `portable` file to the zip
const zip = new AdmZip(zipArtifact);
zip.addFile('portable', Buffer.alloc(0));
zip.writeZip(zipArtifact);
}
},
},
};
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 1 addition & 93 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,99 +33,6 @@
"npm": ">=7.0.0"
},
"license": "GPLv3",
"config": {
"forge": {
"packagerConfig": {
"executableName": "chainner",
"extraResource": "./backend/src/",
"icon": "./src/public/icons/cross_platform/icon"
},
"publishers": [
{
"name": "@electron-forge/publisher-github",
"config": {
"repository": {
"owner": "joeyballentine",
"name": "chaiNNer"
}
},
"draft": true,
"prerelease": true
}
],
"makers": [
{
"name": "@electron-forge/maker-squirrel",
"config": {
"name": "chainner",
"iconUrl": "https://github.com/chaiNNer-org/chaiNNer/blob/main/src/public/icons/win/icon.ico",
"setupIcon": "./src/public/icons/win/icon.ico",
"loadingGif": "./src/public/icons/win/installing_loop.gif"
}
},
{
"name": "@electron-forge/maker-zip",
"platforms": [
"darwin",
"linux",
"win32"
]
},
{
"name": "@electron-forge/maker-dmg",
"config": {
"format": "ULFO",
"name": "chaiNNer",
"icon": "./src/public/icons/mac/icon.icns"
}
},
{
"name": "@electron-forge/maker-deb",
"config": {
"name": "chainner",
"options": {
"icon": "./src/public/icons/cross_platform/icon.png"
}
}
},
{
"name": "@electron-forge/maker-rpm",
"config": {
"name": "chainner",
"options": {
"icon": "./src/public/icons/cross_platform/icon.png"
}
}
}
],
"plugins": [
{
"name": "@electron-forge/plugin-webpack",
"config": {
"mainConfig": "./webpack.main.config.js",
"renderer": {
"config": "./webpack.renderer.config.js",
"nodeIntegration": true,
"contextIsolation": false,
"entryPoints": [
{
"html": "./src/renderer/index.html",
"js": "./src/renderer/renderer.js",
"name": "main_window"
},
{
"html": "./src/renderer/splash.html",
"js": "./src/renderer/splash_renderer.js",
"name": "splash_screen"
}
]
},
"devContentSecurityPolicy": ""
}
}
]
}
},
"devDependencies": {
"@babel/core": "^7.18.2",
"@babel/preset-react": "^7.17.12",
Expand Down Expand Up @@ -200,6 +107,7 @@
"@emotion/styled": "^11.8.1",
"@fontsource/open-sans": "^4.5.10",
"@react-nano/use-event-source": "^0.12.0",
"adm-zip": "^0.5.10",
"bezier-js": "^6.1.0",
"cross-fetch": "^3.1.5",
"decompress": "^4.2.1",
Expand Down
18 changes: 12 additions & 6 deletions src/main/backend/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { runPipInstall, runPipList } from '../../common/pip';
import { CriticalError } from '../../common/ui/error';
import { ProgressToken } from '../../common/ui/progress';
import { checkFileExists } from '../../common/util';
import { versionGt } from '../../common/version';
import { getArguments } from '../arguments';
import { getIntegratedFfmpeg, hasSystemFfmpeg } from '../ffmpeg/ffmpeg';
Expand Down Expand Up @@ -39,13 +40,14 @@ const getValidPort = async () => {
const getPythonInfo = async (
token: ProgressToken,
useSystemPython: boolean,
systemPythonLocation: string | undefined | null
systemPythonLocation: string | undefined | null,
rootDir: string
) => {
log.info('Attempting to check Python env...');

let pythonInfo: PythonInfo;

let integratedPythonFolderPath = path.join(app.getPath('userData'), '/python');
let integratedPythonFolderPath = path.join(rootDir, '/python');

if (systemPythonLocation) {
// eslint-disable-next-line no-param-reassign
Expand Down Expand Up @@ -131,12 +133,12 @@ const getPythonInfo = async (
return pythonInfo;
};

const getFfmpegInfo = async (token: ProgressToken) => {
const getFfmpegInfo = async (token: ProgressToken, rootDir: string) => {
log.info('Attempting to check Ffmpeg env...');

let ffmpegInfo: FfmpegInfo;

const integratedFfmpegFolderPath = path.join(app.getPath('userData'), '/ffmpeg');
const integratedFfmpegFolderPath = path.join(rootDir, '/ffmpeg');

try {
ffmpegInfo = await getIntegratedFfmpeg(integratedFfmpegFolderPath, (percentage, stage) => {
Expand Down Expand Up @@ -267,17 +269,21 @@ const setupOwnedBackend = async (
});
const port = await getValidPort();

const currentExecutableDir = path.dirname(app.getAppPath());
const isPortable = await checkFileExists(path.join(currentExecutableDir, 'portable'));
const rootDir = isPortable ? currentExecutableDir : app.getPath('userData');
joeyballentine marked this conversation as resolved.
Show resolved Hide resolved

token.submitProgress({
status: t('splash.checkingPython', 'Checking system environment for valid Python...'),
totalProgress: 0.2,
});
const pythonInfo = await getPythonInfo(token, useSystemPython, systemPythonLocation);
const pythonInfo = await getPythonInfo(token, useSystemPython, systemPythonLocation, rootDir);

token.submitProgress({
status: t('splash.checkingFfmpeg', 'Checking system environment for Ffmpeg...'),
totalProgress: 0.5,
});
const ffmpegInfo = await getFfmpegInfo(token);
const ffmpegInfo = await getFfmpegInfo(token, rootDir);

token.submitProgress({
status: t('splash.checkingDeps', 'Checking dependencies...'),
Expand Down