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

notification for bundled env updates, auto update bundled env #764

Merged
merged 8 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions src/assets/server-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 50 additions & 2 deletions src/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as yaml from 'js-yaml';
import * as semver from 'semver';
import * as fs from 'fs';
import {
bundledEnvironmentIsInstalled,
clearSession,
EnvironmentInstallStatus,
getBundledPythonEnvPath,
Expand Down Expand Up @@ -392,6 +393,12 @@ export class JupyterApplication implements IApplication, IDisposable {
installUpdatesAutomatically: settings.getValue(
SettingType.installUpdatesAutomatically
),
notifyOnBundledEnvUpdates: settings.getValue(
SettingType.notifyOnBundledEnvUpdates
),
updateBundledEnvAutomatically: settings.getValue(
SettingType.updateBundledEnvAutomatically
),
defaultWorkingDirectory: userSettings.getValue(
SettingType.defaultWorkingDirectory
),
Expand Down Expand Up @@ -429,7 +436,9 @@ export class JupyterApplication implements IApplication, IDisposable {
isDarkTheme: this._isDarkTheme,
defaultPythonPath: userSettings.getValue(SettingType.pythonPath),
app: this,
activateTab
activateTab,
bundledEnvInstallationExists: bundledEnvironmentIsInstalled(),
bundledEnvInstallationLatest: this._registry.bundledEnvironmentIsLatest()
});

this._managePythonEnvDialog = dialog;
Expand Down Expand Up @@ -529,7 +538,16 @@ export class JupyterApplication implements IApplication, IDisposable {
};

dialog.showMessageBox(dialogOpts).then(returnValue => {
if (returnValue.response === 0) autoUpdater.quitAndInstall();
if (returnValue.response === 0) {
if (
userSettings.getValue(SettingType.updateBundledEnvAutomatically) &&
bundledEnvironmentIsInstalled()
) {
appData.updateBundledEnvOnRestart = true;
appData.save();
}
autoUpdater.quitAndInstall();
}
});
});

Expand Down Expand Up @@ -773,6 +791,27 @@ export class JupyterApplication implements IApplication, IDisposable {
}
);

this._evm.registerEventHandler(
EventTypeMain.UpdateBundledPythonEnv,
async event => {
const choice = dialog.showMessageBoxSync({
type: 'warning',
message: 'Update bundled environment',
detail:
'App will restart and the existing environment installation will be deleted before update. Would you like to continue?',
mbektas marked this conversation as resolved.
Show resolved Hide resolved
buttons: ['Update', 'Cancel'],
defaultId: 1,
cancelId: 1
});

if (choice === 0) {
appData.updateBundledEnvOnRestart = true;
app.relaunch();
app.quit();
}
}
);

this._evm.registerEventHandler(
EventTypeMain.ShowManagePythonEnvironmentsDialog,
async (event, activateTab) => {
Expand Down Expand Up @@ -1091,6 +1130,15 @@ export class JupyterApplication implements IApplication, IDisposable {
}
);

this._evm.registerEventHandler(
EventTypeMain.SetSettings,
(_event, settings: { [key: string]: any }) => {
for (const key in settings) {
userSettings.setValue(key as SettingType, settings[key]);
}
}
);

this._evm.registerSyncEventHandler(
EventTypeMain.GetServerInfo,
(event): IServerInfo => {
Expand Down
10 changes: 10 additions & 0 deletions src/main/config/appdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ export class ApplicationData {
});
}
}

if ('updateBundledEnvOnRestart' in jsonData) {
this.updateBundledEnvOnRestart = jsonData.updateBundledEnvOnRestart;
}
}

save() {
Expand Down Expand Up @@ -245,6 +249,10 @@ export class ApplicationData {
});
}

if (this.updateBundledEnvOnRestart) {
appDataJSON.updateBundledEnvOnRestart = true;
}

fs.writeFileSync(appDataPath, JSON.stringify(appDataJSON, null, 2));
}

Expand Down Expand Up @@ -396,6 +404,8 @@ export class ApplicationData {
discoveredPythonEnvs: IPythonEnvironment[] = [];
userSetPythonEnvs: IPythonEnvironment[] = [];

updateBundledEnvOnRestart: boolean = false;

private _recentSessionsChanged = new Signal<this, void>(this);
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/config/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export type KeyValueMap = { [key: string]: string };
export enum SettingType {
checkForUpdatesAutomatically = 'checkForUpdatesAutomatically',
installUpdatesAutomatically = 'installUpdatesAutomatically',
notifyOnBundledEnvUpdates = 'notifyOnBundledEnvUpdates',
updateBundledEnvAutomatically = 'updateBundledEnvAutomatically',

theme = 'theme',
syncJupyterLabTheme = 'syncJupyterLabTheme',
Expand Down Expand Up @@ -124,6 +126,8 @@ export class UserSettings {
this._settings = {
checkForUpdatesAutomatically: new Setting<boolean>(true),
installUpdatesAutomatically: new Setting<boolean>(true),
notifyOnBundledEnvUpdates: new Setting<boolean>(true),
updateBundledEnvAutomatically: new Setting<boolean>(false),
showNewsFeed: new Setting<boolean>(true),

/* making themes workspace overridable is not feasible.
Expand Down
22 changes: 14 additions & 8 deletions src/main/dialog/dialogtitlebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ class JupyterLabDialogTitleBar extends HTMLElement {
const titleEl = document.createElement('div');
titleEl.setAttribute('class', 'dialog-title');

const closeButton = document.createElement('div');
closeButton.setAttribute('class', 'close-button');
closeButton.innerHTML = `<svg viewBox='0 0 10 10'><polygon points='10.2,0.7 9.5,0 5.1,4.4 0.7,0 0,0.7 4.4,5.1 0,9.5 0.7,10.2 5.1,5.8 9.5,10.2 10.2,9.5 5.8,5.1'/></svg>`;
closeButton.title = 'Close';
closeButton.onclick = () => {
window.close();
};
const closable = this.getAttribute('data-closable') !== 'false';
let closeButton = null;
if (closable) {
closeButton = document.createElement('div');
closeButton.setAttribute('class', 'close-button');
closeButton.innerHTML = `<svg viewBox='0 0 10 10'><polygon points='10.2,0.7 9.5,0 5.1,4.4 0.7,0 0,0.7 4.4,5.1 0,9.5 0.7,10.2 5.1,5.8 9.5,10.2 10.2,9.5 5.8,5.1'/></svg>`;
closeButton.title = 'Close';
closeButton.onclick = () => {
window.close();
};
}

const title = this.getAttribute('data-title');
titleEl.textContent = title;
Expand Down Expand Up @@ -85,7 +89,9 @@ class JupyterLabDialogTitleBar extends HTMLElement {
shadow.appendChild(style);
shadow.appendChild(wrapper);
wrapper.appendChild(titleEl);
wrapper.appendChild(closeButton);
if (closeButton) {
wrapper.appendChild(closeButton);
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/main/dialog/themedwindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import { DarkThemeBGColor, LightThemeBGColor } from '../utils';
export class ThemedWindow {
constructor(options: ThemedWindow.IOptions) {
this._isDarkTheme = options.isDarkTheme;
this._closable = options.closable !== false;
this._window = new BrowserWindow({
parent: options.parent,
modal: options.modal,
title: options.title,
width: options.width,
height: options.height,
show: false,
closable: this._closable,
resizable: options.resizable !== false,
titleBarStyle: 'hidden',
frame: process.platform === 'darwin',
Expand All @@ -40,6 +42,11 @@ export class ThemedWindow {
return this._window;
}

close() {
this._window.closable = true;
this._window.close();
}

loadDialogContent(bodyHtml: string) {
let toolkitJsSrc = fs
.readFileSync(
Expand Down Expand Up @@ -114,7 +121,7 @@ export class ThemedWindow {
<div class="page-container">
<jlab-dialog-titlebar id="title-bar" data-title="${
this._window.title
}" class="${
}" data-closable="${this._closable.toString()}" class="${
mbektas marked this conversation as resolved.
Show resolved Hide resolved
this._isDarkTheme ? 'app-ui-dark' : ''
}"></jlab-dialog-titlebar>
<div id="jlab-dialog-body" class="jlab-dialog-body">
Expand All @@ -130,6 +137,7 @@ export class ThemedWindow {
}

private _isDarkTheme: boolean;
private _closable: boolean;
private _window: BrowserWindow;
}

Expand All @@ -141,6 +149,7 @@ export namespace ThemedWindow {
title: string;
width: number;
height: number;
closable?: boolean;
resizable?: boolean;
preload?: string;
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/eventtypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export enum EventTypeMain {
SetDefaultWorkingDirectory = 'set-default-working-directory',
SelectPythonPath = 'select-python-path',
InstallBundledPythonEnv = 'install-bundled-python-env',
UpdateBundledPythonEnv = 'update-bundled-python-env',
ValidatePythonPath = 'validate-python-path',
ValidateRemoteServerUrl = 'validate-remote-server-url',
SetDefaultPythonPath = 'set-default-python-path',
Expand Down Expand Up @@ -79,7 +80,8 @@ export enum EventTypeMain {
ValidateSystemPythonPath = 'validate-system-python-path',
SetSystemPythonPath = 'set-system-python-path',
CopySessionInfoToClipboard = 'copy-session-info-to-clipboard',
RestartSession = 'restart-session'
RestartSession = 'restart-session',
SetSettings = 'set-settings'
}

// events sent to Renderer process
Expand All @@ -94,12 +96,14 @@ export enum EventTypeRenderer {
SetTitle = 'set-title',
SetActive = 'set-active',
ShowServerStatus = 'show-server-status',
ShowServerNotificationBadge = 'show-server-notification-badge',
SetRecentSessionList = 'set-recent-session-list',
SetNewsList = 'set-news-list',
SetNotificationMessage = 'set-notification-message',
EnableLocalServerActions = 'enable-local-server-actions',
SetDefaultWorkingDirectoryResult = 'set-default-working-directory-result',
ResetPythonEnvSelectPopup = 'reset-python-env-select-popup',
SetPythonEnvironmentList = 'set-python-environment-list',
SetEnvironmentListUpdateStatus = 'set-environment-list-update-status'
SetEnvironmentListUpdateStatus = 'set-environment-list-update-status',
ShowUpdateBundledEnvAction = 'show-bundled-env-action'
}
Loading
Loading