Skip to content

Commit

Permalink
Merge pull request #7601 from telamonian/implement-save-settingconnector
Browse files Browse the repository at this point in the history
followup #7147: adds SettingConnector.save, reenables saving of user settings
  • Loading branch information
afshin committed Dec 11, 2019
2 parents b349e5d + e4ac8aa commit ea87dd7
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 58 deletions.
62 changes: 4 additions & 58 deletions packages/apputils-extension/src/index.ts
Expand Up @@ -9,7 +9,6 @@ import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';

import {
Dialog,
ICommandPalette,
Expand All @@ -18,28 +17,20 @@ import {
WindowResolver,
Printing
} from '@jupyterlab/apputils';

import {
Debouncer,
ISettingRegistry,
IStateDB,
PageConfig,
SettingRegistry,
StateDB,
Throttler,
URLExt
} from '@jupyterlab/coreutils';

import { defaultIconRegistry } from '@jupyterlab/ui-components';

import { PromiseDelegate } from '@lumino/coreutils';

import { DisposableDelegate } from '@lumino/disposable';

import { Palette } from './palette';

import { SettingConnector } from './settingconnector';

import { settingsPlugin } from './settingsplugin';
import { themesPlugin, themesPaletteMenuPlugin } from './themeplugins';

/**
Expand Down Expand Up @@ -86,51 +77,6 @@ const paletteRestorer: JupyterFrontEndPlugin<void> = {
autoStart: true
};

/**
* The default setting registry provider.
*/
const settings: JupyterFrontEndPlugin<ISettingRegistry> = {
id: '@jupyterlab/apputils-extension:settings',
activate: async (app: JupyterFrontEnd): Promise<ISettingRegistry> => {
const { isDisabled } = PageConfig.Extension;
const connector = new SettingConnector(app.serviceManager.settings);

const registry = new SettingRegistry({
connector,
plugins: (await connector.list('active')).values
});

// If there are plugins that have schemas that are not in the setting
// registry after the application has restored, try to load them manually
// because otherwise, its settings will never become available in the
// setting registry.
void app.restored.then(async () => {
const plugins = await connector.list('all');
plugins.ids.forEach(async (id, index) => {
if (isDisabled(id) || id in registry.plugins) {
return;
}

try {
await registry.load(id);
} catch (error) {
console.warn(`Settings failed to load for (${id})`, error);
if (plugins.values[index].schema['jupyter.lab.transform']) {
console.warn(
`This may happen if {autoStart: false} in (${id}) ` +
`or if it is one of the deferredExtensions in page config.`
);
}
}
});
});

return registry;
},
autoStart: true,
provides: ISettingRegistry
};

/**
* The default window name resolver provider.
*/
Expand Down Expand Up @@ -497,13 +443,13 @@ const state: JupyterFrontEndPlugin<IStateDB> = {
const plugins: JupyterFrontEndPlugin<any>[] = [
palette,
paletteRestorer,
print,
resolver,
settings,
settingsPlugin,
state,
splash,
themesPlugin,
themesPaletteMenuPlugin,
print
themesPaletteMenuPlugin
];
export default plugins;

Expand Down
4 changes: 4 additions & 0 deletions packages/apputils-extension/src/settingconnector.ts
Expand Up @@ -40,5 +40,9 @@ export class SettingConnector extends DataConnector<
};
}

async save(id: string, raw: string): Promise<void> {
await this._connector.save(id, raw);
}

private _connector: IDataConnector<ISettingRegistry.IPlugin, string>;
}
61 changes: 61 additions & 0 deletions packages/apputils-extension/src/settingsplugin.ts
@@ -0,0 +1,61 @@
/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import {
ISettingRegistry,
PageConfig,
SettingRegistry
} from '@jupyterlab/coreutils';

import { SettingConnector } from './settingconnector';

/**
* The default setting registry provider.
*/
export const settingsPlugin: JupyterFrontEndPlugin<ISettingRegistry> = {
id: '@jupyterlab/apputils-extension:settings',
activate: async (app: JupyterFrontEnd): Promise<ISettingRegistry> => {
const { isDisabled } = PageConfig.Extension;
const connector = new SettingConnector(app.serviceManager.settings);

const registry = new SettingRegistry({
connector,
plugins: (await connector.list('active')).values
});

// If there are plugins that have schemas that are not in the setting
// registry after the application has restored, try to load them manually
// because otherwise, its settings will never become available in the
// setting registry.
void app.restored.then(async () => {
const plugins = await connector.list('all');
plugins.ids.forEach(async (id, index) => {
if (isDisabled(id) || id in registry.plugins) {
return;
}

try {
await registry.load(id);
} catch (error) {
console.warn(`Settings failed to load for (${id})`, error);
if (plugins.values[index].schema['jupyter.lab.transform']) {
console.warn(
`This may happen if {autoStart: false} in (${id}) ` +
`or if it is one of the deferredExtensions in page config.`
);
}
}
});
});

return registry;
},
autoStart: true,
provides: ISettingRegistry
};

0 comments on commit ea87dd7

Please sign in to comment.