Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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 packages/base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from './tools';
export * from './types';
export * from './widget';
export * from './annotations';
export * from './settings';
29 changes: 29 additions & 0 deletions packages/base/src/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ISettingRegistry } from '@jupyterlab/settingregistry';

const SETTINGS_ID = '@jupytergis/jupytergis-core:jupytergis-settings';

/**
* Default settings state.
*/
const settingsState = {
proxyUrl: 'https://corsproxy.io'
};

/**
* Initialize settings from the JupyterLab setting registry.
*/
export const initSettings = async (
settingRegistry: ISettingRegistry
): Promise<void> => {
const setting = await settingRegistry.load(SETTINGS_ID);

const userSettings = setting.user ?? {};

settingsState.proxyUrl =
(userSettings as any).proxyUrl ?? settingsState.proxyUrl;
};

/**
* Get the full current settings.
*/
export const getSettings = () => settingsState;
4 changes: 3 additions & 1 deletion packages/base/src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { showErrorMessage } from '@jupyterlab/apputils';
import * as d3Color from 'd3-color';
import shp from 'shpjs';
import { getGdal } from './gdal';
import { getSettings } from './settings';

import {
IDict,
Expand Down Expand Up @@ -412,10 +413,11 @@ const fetchWithProxies = async <T>(
url: string,
parseResponse: (response: Response) => Promise<T>
): Promise<T | null> => {
const externalProxyUrl = getSettings().proxyUrl;
const proxyUrls = [
url, // Direct fetch
`/jupytergis_core/proxy?url=${encodeURIComponent(url)}`, // Internal proxy
`https://corsproxy.io/?url=${encodeURIComponent(url)}` // External proxy
`${externalProxyUrl}/?url=${encodeURIComponent(url)}` // External proxy
];

for (const proxyUrl of proxyUrls) {
Expand Down
4 changes: 3 additions & 1 deletion python/jupytergis_core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"author": "JupyterGIS contributors",
"files": [
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
"style/**/*.{css,js,eot,gif,html,jpg,json,png,svg,woff2,ttf}"
"style/**/*.{css,js,eot,gif,html,jpg,json,png,svg,woff2,ttf}",
"schema/**/*.{json,js,ts}"
],
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -91,6 +92,7 @@
"access": "public"
},
"jupyterlab": {
"schemaDir": "schema",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 17 of this file, you want to list the schema folder as part of the package file

"discovery": {
"server": {
"managers": [
Expand Down
13 changes: 13 additions & 0 deletions python/jupytergis_core/schema/jupytergis-settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"title": "JupyterGIS Settings",
"description": "Settings for the JupyterGIS extension.",
"type": "object",
"properties": {
"proxyUrl": {
"type": "string",
"title": "Proxy URL",
"description": "The proxy URL to use for external requests.",
"default": "https://corsproxy.io"
}
}
}
23 changes: 19 additions & 4 deletions python/jupytergis_core/src/jgisplugin/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ import { PageConfig } from '@jupyterlab/coreutils';
import { IFileBrowserFactory } from '@jupyterlab/filebrowser';
import { ILauncher } from '@jupyterlab/launcher';
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
import { ISettingRegistry } from '@jupyterlab/settingregistry';

import { CommandIDs, logoIcon, logoMiniIcon } from '@jupytergis/base';
import {
CommandIDs,
logoIcon,
logoMiniIcon,
initSettings
} from '@jupytergis/base';
import { JupyterGISDocumentWidgetFactory } from '../factory';
import { JupyterGISModelFactory } from './modelfactory';
import { MimeDocumentFactory } from '@jupyterlab/docregistry';
Expand All @@ -36,8 +42,9 @@ const FACTORY = 'JupyterGIS .jgis Viewer';
const CONTENT_TYPE = 'jgis';
const PALETTE_CATEGORY = 'JupyterGIS';
const MODEL_NAME = 'jupytergis-jgismodel';
const SETTINGS_ID = '@jupytergis/jupytergis-core:jupytergis-settings';

const activate = (
const activate = async (
app: JupyterFrontEnd,
tracker: WidgetTracker<IJupyterGISWidget>,
themeManager: IThemeManager,
Expand All @@ -48,13 +55,20 @@ const activate = (
rendermime: IRenderMimeRegistry,
consoleTracker: IConsoleTracker,
annotationModel: IAnnotationModel,
settingRegistry: ISettingRegistry,
launcher: ILauncher | null,
palette: ICommandPalette | null,
drive: ICollaborativeDrive | null
): void => {
): Promise<void> => {
if (PageConfig.getOption('jgis_expose_maps')) {
window.jupytergisMaps = {};
}
const setting = await settingRegistry.load(SETTINGS_ID);
setting.changed.connect(() => {
const newSettings = setting.composite as any;
console.log('JupyterGIS Settings updated:', newSettings);
});
await initSettings(settingRegistry);

const widgetFactory = new JupyterGISDocumentWidgetFactory({
name: FACTORY,
Expand Down Expand Up @@ -270,7 +284,8 @@ const jGISPlugin: JupyterFrontEndPlugin<void> = {
IEditorServices,
IRenderMimeRegistry,
IConsoleTracker,
IAnnotationToken
IAnnotationToken,
ISettingRegistry
],
optional: [ILauncher, ICommandPalette, ICollaborativeDrive],
autoStart: true,
Expand Down
Loading