Prevent .deb packages from being opened with archive manager.

This commit is contained in:
Franco Montenegro 2022-03-02 22:09:21 -03:00
parent 2e565fd95b
commit 6e97fbf5f8
11 changed files with 1127 additions and 944 deletions

View file

@ -22,6 +22,7 @@ import { diskSpaceLinux, diskSpaceWindows, diskSpaceMac } from '../ui/util/disks
const { download } = require('electron-dl'); const { download } = require('electron-dl');
const remote = require('@electron/remote/main'); const remote = require('@electron/remote/main');
const os = require('os'); const os = require('os');
const sudo = require('sudo-prompt');
remote.initialize(); remote.initialize();
const filePath = path.join(process.resourcesPath, 'static', 'upgradeDisabled'); const filePath = path.join(process.resourcesPath, 'static', 'upgradeDisabled');
@ -348,16 +349,33 @@ ipcMain.on('download-upgrade', async (event, params) => {
}); });
ipcMain.on('upgrade', (event, installerPath) => { ipcMain.on('upgrade', (event, installerPath) => {
// what to do if no shutdown in a long time?
console.log('Update downloaded to', installerPath);
console.log('The app will close and you will be prompted to install the latest version of LBRY.');
console.log('After the install is complete, please reopen the app.');
// Prevent .deb package from opening with archive manager (Ubuntu >= 20)
if (process.platform === 'linux' && !process.env.APPIMAGE) {
sudo.exec(`dpkg -i ${installerPath}`, { name: app.name }, (err, stdout, stderr) => {
if (err || stderr) {
rendererWindow.webContents.send('upgrade-installing-error');
return;
}
// Re-launch the application when the installation finishes.
app.relaunch();
app.quit();
});
return;
}
app.on('quit', () => { app.on('quit', () => {
console.log('Launching upgrade installer at', installerPath); console.log('Launching upgrade installer at', installerPath);
// This gets triggered called after *all* other quit-related events, so // This gets triggered called after *all* other quit-related events, so
// we'll only get here if we're fully prepared and quitting for real. // we'll only get here if we're fully prepared and quitting for real.
shell.openPath(installerPath); shell.openPath(installerPath);
}); });
// what to do if no shutdown in a long time?
console.log('Update downloaded to', installerPath);
console.log('The app will close and you will be prompted to install the latest version of LBRY.');
console.log('After the install is complete, please reopen the app.');
app.quit(); app.quit();
}); });

View file

@ -67,6 +67,7 @@
"remove-markdown": "^0.3.0", "remove-markdown": "^0.3.0",
"rss": "^1.2.2", "rss": "^1.2.2",
"source-map-explorer": "^2.5.2", "source-map-explorer": "^2.5.2",
"sudo-prompt": "^9.2.1",
"tempy": "^0.6.0", "tempy": "^0.6.0",
"videojs-logo": "^2.1.4" "videojs-logo": "^2.1.4"
}, },

View file

@ -2312,5 +2312,7 @@
"Free --[legend, unused disk space]--": "Free", "Free --[legend, unused disk space]--": "Free",
"Top content in %language%": "Top content in %language%", "Top content in %language%": "Top content in %language%",
"Apply": "Apply", "Apply": "Apply",
"Installing, please wait...": "Installing, please wait...",
"There was an error during installation. Please, try again.": "There was an error during installation. Please, try again.",
"--end--": "--end--" "--end--": "--end--"
} }

View file

@ -45,6 +45,8 @@ export const DOWNLOAD_UPGRADE = 'DOWNLOAD_UPGRADE';
export const UPGRADE_DOWNLOAD_STARTED = 'UPGRADE_DOWNLOAD_STARTED'; export const UPGRADE_DOWNLOAD_STARTED = 'UPGRADE_DOWNLOAD_STARTED';
export const UPGRADE_DOWNLOAD_COMPLETED = 'UPGRADE_DOWNLOAD_COMPLETED'; export const UPGRADE_DOWNLOAD_COMPLETED = 'UPGRADE_DOWNLOAD_COMPLETED';
export const UPGRADE_DOWNLOAD_PROGRESSED = 'UPGRADE_DOWNLOAD_PROGRESSED'; export const UPGRADE_DOWNLOAD_PROGRESSED = 'UPGRADE_DOWNLOAD_PROGRESSED';
export const UPGRADE_INIT_INSTALL = 'UPGRADE_INIT_INSTALL';
export const UPGRADE_INSTALL_ERROR = 'UPGRADE_INSTALL_ERROR';
export const CHECK_UPGRADE_AVAILABLE = 'CHECK_UPGRADE_AVAILABLE'; export const CHECK_UPGRADE_AVAILABLE = 'CHECK_UPGRADE_AVAILABLE';
export const CHECK_UPGRADE_START = 'CHECK_UPGRADE_START'; export const CHECK_UPGRADE_START = 'CHECK_UPGRADE_START';
export const CHECK_UPGRADE_SUCCESS = 'CHECK_UPGRADE_SUCCESS'; export const CHECK_UPGRADE_SUCCESS = 'CHECK_UPGRADE_SUCCESS';

View file

@ -21,6 +21,7 @@ import {
doToggle3PAnalytics, doToggle3PAnalytics,
doUpdateDownloadProgress, doUpdateDownloadProgress,
doNotifyUpdateAvailable, doNotifyUpdateAvailable,
doShowUpgradeInstallationError,
} from 'redux/actions/app'; } from 'redux/actions/app';
import { isURIValid } from 'util/lbryURI'; import { isURIValid } from 'util/lbryURI';
import { setSearchApi } from 'redux/actions/search'; import { setSearchApi } from 'redux/actions/search';
@ -132,6 +133,10 @@ autoUpdater.on('update-available', (e) => {
app.store.dispatch(doNotifyUpdateAvailable(e)); app.store.dispatch(doNotifyUpdateAvailable(e));
}); });
ipcRenderer.on('upgrade-installing-error', () => {
app.store.dispatch(doShowUpgradeInstallationError());
});
ipcRenderer.on('download-progress-update', (e, p) => { ipcRenderer.on('download-progress-update', (e, p) => {
app.store.dispatch(doUpdateDownloadProgress(Math.round(p.percent * 100))); app.store.dispatch(doUpdateDownloadProgress(Math.round(p.percent * 100)));
}); });

View file

@ -1,15 +1,23 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { doStartUpgrade, doCancelUpgrade, doHideModal } from 'redux/actions/app'; import { doStartUpgrade, doCancelUpgrade, doHideModal } from 'redux/actions/app';
import { selectDownloadProgress, selectDownloadComplete, selectUpgradeDownloadPath } from 'redux/selectors/app'; import {
selectDownloadProgress,
selectDownloadComplete,
selectUpgradeDownloadPath,
selectUpgradeInitialized,
selectUpgradeFailedInstallation,
} from 'redux/selectors/app';
import ModalDownloading from './view'; import ModalDownloading from './view';
const select = state => ({ const select = (state) => ({
downloadProgress: selectDownloadProgress(state), downloadProgress: selectDownloadProgress(state),
downloadComplete: selectDownloadComplete(state), downloadComplete: selectDownloadComplete(state),
downloadItem: selectUpgradeDownloadPath(state), downloadItem: selectUpgradeDownloadPath(state),
upgradeInitialized: selectUpgradeInitialized(state),
failedInstallation: selectUpgradeFailedInstallation(state),
}); });
const perform = dispatch => ({ const perform = (dispatch) => ({
startUpgrade: () => dispatch(doStartUpgrade()), startUpgrade: () => dispatch(doStartUpgrade()),
cancelUpgrade: () => { cancelUpgrade: () => {
dispatch(doHideModal()); dispatch(doHideModal());
@ -17,7 +25,4 @@ const perform = dispatch => ({
}, },
}); });
export default connect( export default connect(select, perform)(ModalDownloading);
select,
perform
)(ModalDownloading);

View file

@ -10,11 +10,21 @@ type Props = {
downloadItem: string, downloadItem: string,
startUpgrade: () => void, startUpgrade: () => void,
cancelUpgrade: () => void, cancelUpgrade: () => void,
upgradeInitialized: boolean,
failedInstallation: boolean,
}; };
class ModalDownloading extends React.PureComponent<Props> { class ModalDownloading extends React.PureComponent<Props> {
render() { render() {
const { downloadProgress, downloadComplete, downloadItem, startUpgrade, cancelUpgrade } = this.props; const {
downloadProgress,
downloadComplete,
downloadItem,
startUpgrade,
cancelUpgrade,
upgradeInitialized,
failedInstallation,
} = this.props;
return ( return (
<Modal title={__('Downloading update')} isOpen contentLabel={__('Downloading update')} type="custom"> <Modal title={__('Downloading update')} isOpen contentLabel={__('Downloading update')} type="custom">
@ -40,9 +50,18 @@ class ModalDownloading extends React.PureComponent<Props> {
</React.Fragment> </React.Fragment>
) : null} ) : null}
{failedInstallation && <p>{__('There was an error during installation. Please, try again.')}</p>}
<div className="card__actions"> <div className="card__actions">
{downloadComplete ? <Button button="primary" label={__('Begin Upgrade')} onClick={startUpgrade} /> : null} {downloadComplete ? (
<Button button="link" label={__('Cancel')} onClick={cancelUpgrade} /> <Button
disabled={upgradeInitialized}
button="primary"
label={__(upgradeInitialized ? 'Installing, please wait...' : 'Begin Upgrade')}
onClick={startUpgrade}
/>
) : null}
<Button disabled={upgradeInitialized} button="link" label={__('Cancel')} onClick={cancelUpgrade} />
</div> </div>
</Modal> </Modal>
); );

View file

@ -85,6 +85,15 @@ export function doStartUpgrade() {
const upgradeDownloadPath = selectUpgradeDownloadPath(state); const upgradeDownloadPath = selectUpgradeDownloadPath(state);
ipcRenderer.send('upgrade', upgradeDownloadPath); ipcRenderer.send('upgrade', upgradeDownloadPath);
dispatch({
type: ACTIONS.UPGRADE_INIT_INSTALL,
});
};
}
export function doShowUpgradeInstallationError() {
return {
type: ACTIONS.UPGRADE_INSTALL_ERROR,
}; };
} }

View file

@ -67,6 +67,8 @@ const defaultState: AppState = {
modalsAllowed: true, modalsAllowed: true,
hasClickedComment: false, hasClickedComment: false,
downloadProgress: undefined, downloadProgress: undefined,
upgradeInitialized: false,
upgradeFailedInstallation: false,
upgradeDownloading: undefined, upgradeDownloading: undefined,
upgradeDownloadComplete: undefined, upgradeDownloadComplete: undefined,
checkUpgradeTimer: undefined, checkUpgradeTimer: undefined,
@ -162,6 +164,18 @@ reducers[ACTIONS.UPGRADE_DOWNLOAD_STARTED] = (state) =>
upgradeDownloading: true, upgradeDownloading: true,
}); });
reducers[ACTIONS.UPGRADE_INIT_INSTALL] = (state) =>
Object.assign({}, state, {
upgradeInitialized: true,
upgradeFailedInstallation: false,
});
reducers[ACTIONS.UPGRADE_INSTALL_ERROR] = (state) =>
Object.assign({}, state, {
upgradeInitialized: false,
upgradeFailedInstallation: true,
});
reducers[ACTIONS.CHANGE_MODALS_ALLOWED] = (state, action) => reducers[ACTIONS.CHANGE_MODALS_ALLOWED] = (state, action) =>
Object.assign({}, state, { Object.assign({}, state, {
modalsAllowed: action.data.modalsAllowed, modalsAllowed: action.data.modalsAllowed,

View file

@ -25,6 +25,10 @@ export const selectRemoteVersion = createSelector(selectState, (state) => state.
export const selectIsUpgradeAvailable = createSelector(selectState, (state) => state.isUpgradeAvailable); export const selectIsUpgradeAvailable = createSelector(selectState, (state) => state.isUpgradeAvailable);
export const selectUpgradeInitialized = createSelector(selectState, (state) => state.upgradeInitialized);
export const selectUpgradeFailedInstallation = createSelector(selectState, (state) => state.upgradeFailedInstallation);
export const selectUpgradeFilename = createSelector(selectPlatform, selectRemoteVersion, (platform, version) => { export const selectUpgradeFilename = createSelector(selectPlatform, selectRemoteVersion, (platform, version) => {
switch (platform) { switch (platform) {
case 'darwin': case 'darwin':

1964
yarn.lock

File diff suppressed because it is too large Load diff