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 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
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
30 changes: 20 additions & 10 deletions src/main/backend/setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { app } from 'electron';
import log from 'electron-log';
import { t } from 'i18next';
import path from 'path';
Expand Down Expand Up @@ -39,13 +38,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 +131,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 @@ -259,25 +259,28 @@ const setupOwnedBackend = async (
token: ProgressToken,
useSystemPython: boolean,
systemPythonLocation: string | undefined | null,
hasNvidia: () => Promise<boolean>
hasNvidia: () => Promise<boolean>,
getRootDir: () => Promise<string>
): Promise<OwnedBackendProcess> => {
token.submitProgress({
status: t('splash.checkingPort', 'Checking for available port...'),
totalProgress: 0.1,
});
const port = await getValidPort();

const rootDir = await getRootDir();

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 Expand Up @@ -309,13 +312,20 @@ export const setupBackend = async (
token: ProgressToken,
useSystemPython: boolean,
systemPythonLocation: string | undefined | null,
hasNvidia: () => Promise<boolean>
hasNvidia: () => Promise<boolean>,
getRootDir: () => Promise<string>
): Promise<BackendProcess> => {
token.submitProgress({ totalProgress: 0 });

const backend = getArguments().noBackend
? await setupBorrowedBackend(token, 8000)
: await setupOwnedBackend(token, useSystemPython, systemPythonLocation, hasNvidia);
: await setupOwnedBackend(
token,
useSystemPython,
systemPythonLocation,
hasNvidia,
getRootDir
);

token.submitProgress({ totalProgress: 1 });
return backend;
Expand Down
10 changes: 9 additions & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { BackendProcess } from './backend/process';
import { setupBackend } from './backend/setup';
import { MenuData, setMainMenu } from './menu';
import { createNvidiaSmiVRamChecker, getNvidiaGpuNames, getNvidiaSmi } from './nvidiaSmi';
import { getRootDir } from './platform';
import { addSplashScreen } from './splash';
import { getGpuInfo } from './systemInfo';
import { hasUpdate } from './update';
Expand Down Expand Up @@ -273,12 +274,19 @@ const checkNvidiaSmi = async () => {
};

const nvidiaSmiPromise = checkNvidiaSmi();
const getRootDirPromise = getRootDir();

const createBackend = async (token: ProgressToken) => {
const useSystemPython = localStorage.getItem('use-system-python') === 'true';
const systemPythonLocation = localStorage.getItem('system-python-location');

return setupBackend(token, useSystemPython, systemPythonLocation, () => nvidiaSmiPromise);
return setupBackend(
token,
useSystemPython,
systemPythonLocation,
() => nvidiaSmiPromise,
() => getRootDirPromise
);
};

const createWindow = lazy(async () => {
Expand Down
16 changes: 16 additions & 0 deletions src/main/platform.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { app } from 'electron';
import os from 'os';
import path from 'path';
import { checkFileExists } from '../common/util';

export type SupportedPlatform = 'linux' | 'darwin' | 'win32';

Expand All @@ -15,3 +18,16 @@ export const getPlatform = (): SupportedPlatform => {
);
}
};

export const currentExecutableDir = path.dirname(app.getPath('exe'));

export const getIsPortable = async (): Promise<boolean> => {
const isPortable = await checkFileExists(path.join(currentExecutableDir, 'portable'));
return isPortable;
};

export const getRootDir = async (): Promise<string> => {
const isPortable = await getIsPortable();
const rootDir = isPortable ? currentExecutableDir : app.getPath('userData');
return rootDir;
};