Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
marstamm committed Jun 7, 2024
1 parent ad0b3a3 commit 28a0df8
Show file tree
Hide file tree
Showing 11 changed files with 389 additions and 28 deletions.
66 changes: 66 additions & 0 deletions app/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const {
BrowserWindow
} = require('electron');

const { download } = require('electron-dl');

const Sentry = require('@sentry/node');

const path = require('path');
Expand Down Expand Up @@ -50,6 +52,7 @@ const renderer = require('./util/renderer');

const errorTracking = require('./util/error-tracking');
const { pick } = require('min-dash');
const { spawn } = require('child_process');

const log = Log('app:main');
const bootstrapLog = Log('app:main:bootstrap');
Expand Down Expand Up @@ -147,6 +150,43 @@ renderer.on('external:open-url', function(options) {
browserOpen(url);
});

renderer.on('external:download-update', async function(options) {

const baseURL = options.url;
const isWindows = process.platform === 'win32';

const tmpPath = app.getPath('temp');

const downloadUrl = `${baseURL}${getFileName(baseURL)}`;

const win = BrowserWindow.getFocusedWindow();

log.info('downloading', downloadUrl);

const downloadedFile = await download(win, downloadUrl, {
directory: tmpPath
});

log.info('downloaded', downloadedFile.getSavePath());

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

const updateZipFile = downloadedFile.getSavePath();

const updateScript = isWindows ? '/update.bat' : '/update.ps1';

log.info('downloading update to', options);

log.info(installPath + updateScript);

spawn(`${installPath}/${updateScript}`, [ updateZipFile, installPath ], {
detached: true,
stdio: 'inherit'
}).unref();

app.exit();
});

// dialogs //////////

renderer.on('dialog:open-files', async function(options, done) {
Expand Down Expand Up @@ -727,5 +767,31 @@ function setUserPath(path = DEFAULT_USER_PATH) {
}


// Helper function that creates the name of the file. Extracts the version number from the URL
// like `https://downloads.camunda.cloud/release/camunda-modeler/{version}/` ands adds it to the file name.
// File names are constructed like this:
// Linux: camunda-modeler-{version}-linux-x64.tar.gz
// Windows64 bit: camunda-modeler-{version}-win-x64.zip
// Windows32 bit: camunda-modeler-{version}-win-ia32.zip
function getFileName(url) {
const version = url.match(/\/release\/camunda-modeler\/([0-9.]+)\//)[1];
const platform = process.platform;
const arch = process.arch;

let fileName = `camunda-modeler-${version}-`;

if (platform === 'linux') {
fileName += 'linux-x64.tar.gz';
} else if (platform === 'win32') {
fileName += arch === 'x64' ? 'win-x64.zip' : 'win-ia32.zip';
}

return fileName;
}


// expose app
module.exports = app;



1 change: 1 addition & 0 deletions app/lib/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const allowedEvents = [
'errorTracking:turnedOff',
'errorTracking:turnedOn',
'external:open-url',
'external:download-update',
'file:read',
'file:read-stats',
'file:write',
Expand Down
3 changes: 2 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "camunda-modeler",
"version": "5.22.0",
"version": "5.20.0",
"description": "Camunda Modeler for BPMN, DMN and CMMN, based on bpmn.io",
"private": true,
"main": "prod.js",
Expand All @@ -14,6 +14,7 @@
"@sentry/integrations": "^7.82.0",
"@sentry/node": "^7.82.0",
"epipebomb": "^1.0.0",
"electron-dl": "^3.5.2",
"fast-glob": "^3.3.1",
"form-data": "^2.5.1",
"ids": "^1.0.0",
Expand Down
27 changes: 15 additions & 12 deletions app/util/get-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,24 @@ var pkg = require('../package.json');
*/
module.exports = function getVersion() {
var appVersion = pkg.version;
var increment = IS_NIGHTLY || IS_DEV;

if (increment) {
appVersion = semver.inc(appVersion, 'minor');
}
return appVersion;

if (IS_NIGHTLY) {
appVersion = `${appVersion}-nightly.${today()}`;
} else if (BUILD_NAME) {
appVersion = `${appVersion}-${BUILD_NAME}`;
} else if (IS_DEV) {
appVersion = `${appVersion}-dev`;
}
// var increment = IS_NIGHTLY || IS_DEV;

return appVersion;
// if (increment) {
// appVersion = semver.inc(appVersion, 'minor');
// }

// if (IS_NIGHTLY) {
// appVersion = `${appVersion}-nightly.${today()}`;
// } else if (BUILD_NAME) {
// appVersion = `${appVersion}-${BUILD_NAME}`;
// } else if (IS_DEV) {
// appVersion = `${appVersion}-dev`;
// }

// return appVersion;
};

function pad(n) {
Expand Down
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "camunda-modeler-client",
"version": "5.22.0",
"version": "5.20.0",
"description": "Camunda Modeler client application",
"private": true,
"license": "MIT",
Expand Down
5 changes: 3 additions & 2 deletions client/src/plugins/update-checks/NewVersionInfoView.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class NewVersionInfoView extends PureComponent {
onClose,
onGoToDownloadPage,
onOpenPrivacyPreferences,
updateChecksEnabled
updateChecksEnabled,
autoUpdate
} = this.props;

const {
Expand Down Expand Up @@ -97,7 +98,7 @@ class NewVersionInfoView extends PureComponent {
className="btn btn-primary"
onClick={ onGoToDownloadPage }
autoFocus
> { BUTTON_POSITIVE } </button>
> { autoUpdate ? 'Update Modeler' : BUTTON_POSITIVE } </button>
</div>
</Modal.Footer>

Expand Down
25 changes: 18 additions & 7 deletions client/src/plugins/update-checks/UpdateChecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ class NoopComponent extends PureComponent {
}
}

const DEFAULT_UPDATE_SERVER_URL = process.env.NODE_ENV === 'production'
? 'https://camunda-modeler-updates.camunda.com'
: 'https://camunda-modeler-update-server-staging.camunda.com';
// const DEFAULT_UPDATE_SERVER_URL = process.env.NODE_ENV === 'production'
// ? 'https://camunda-modeler-updates.camunda.com'
// : 'https://camunda-modeler-update-server-staging.camunda.com';

const DEFAULT_UPDATE_SERVER_URL = 'https://camunda-modeler-updates.camunda.com';

const PRIVACY_PREFERENCES_CONFIG_KEY = 'editor.privacyPreferences';
const UPDATE_CHECKS_CONFIG_KEY = 'editor.updateChecks';
Expand All @@ -55,7 +57,8 @@ export default class UpdateChecks extends PureComponent {
this.updateChecksAPI = new UpdateChecksAPI(updateServerUrl);

this.state = {
showModal: false
showModal: false,
autoUpdate: true // Flags.get(AUTOMATIC_UPDATE)
};
}

Expand Down Expand Up @@ -324,14 +327,20 @@ export default class UpdateChecks extends PureComponent {

onGoToDownloadPage = () => {
const {
latestVersionInfo
latestVersionInfo,
autoUpdate
} = this.state;

const {
_getGlobal
} = this.props;

_getGlobal('backend').send('external:open-url', { url: latestVersionInfo.downloadURL });
if (autoUpdate) {
_getGlobal('backend').send('external:download-update', { url: latestVersionInfo.downloadURL });
} else {
_getGlobal('backend').send('external:open-url', { url: latestVersionInfo.downloadURL });
}

this.onClose();
};

Expand All @@ -340,13 +349,15 @@ export default class UpdateChecks extends PureComponent {
showModal,
latestVersionInfo,
currentVersion,
updateChecksEnabled
updateChecksEnabled,
autoUpdate
} = this.state;

return (
<React.Fragment>
{showModal && (
<NewVersionInfoView
autoUpdate={ autoUpdate }
onClose={ this.onClose }
onGoToDownloadPage={ this.onGoToDownloadPage }
onOpenPrivacyPreferences={ this.openPrivacyPreferences }
Expand Down
1 change: 1 addition & 0 deletions client/src/util/Flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const RELAUNCH = 'relaunch';
export const DISABLE_REMOTE_INTERACTION = 'disable-remote-interaction';
export const UPDATE_SERVER_URL = 'update-server-url';
export const FORCE_UPDATE_CHECKS = 'force-update-checks';
export const AUTOMATIC_UPDATE = 'enable-automatic-update';
export const SENTRY_DSN = 'sentry-dsn';
export const MIXPANEL_TOKEN = 'mixpanel-token';
export const MIXPANEL_STAGE = 'mixpanel-stage';
Expand Down
Loading

0 comments on commit 28a0df8

Please sign in to comment.