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 1 commit
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
22 changes: 15 additions & 7 deletions src/main/backend/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ 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 @@ -261,17 +260,16 @@ 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 currentExecutableDir = path.dirname(app.getAppPath());
const isPortable = await checkFileExists(path.join(currentExecutableDir, 'portable'));
const rootDir = isPortable ? currentExecutableDir : app.getPath('userData');
const rootDir = await getRootDir();

token.submitProgress({
status: t('splash.checkingPython', 'Checking system environment for valid Python...'),
Expand Down Expand Up @@ -315,13 +313,23 @@ 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 currentExecutableDir = path.dirname(app.getPath('exe'));
log.info(`currentExecutableDir setupBackend: ${currentExecutableDir}`);
joeyballentine marked this conversation as resolved.
Show resolved Hide resolved

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;
};