@lvce-editor/extension-host-worker 5.29.0 → 5.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extensionHostWorkerMain.js +108 -94
- package/package.json +1 -1
|
@@ -2844,6 +2844,110 @@ const {
|
|
|
2844
2844
|
}
|
|
2845
2845
|
});
|
|
2846
2846
|
|
|
2847
|
+
const RE_PROTOCOL = /^([a-z-]+):\/\//;
|
|
2848
|
+
const getProtocol = uri => {
|
|
2849
|
+
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
2850
|
+
if (protocolMatch) {
|
|
2851
|
+
return protocolMatch[1];
|
|
2852
|
+
}
|
|
2853
|
+
return '';
|
|
2854
|
+
};
|
|
2855
|
+
|
|
2856
|
+
const createWebViewIpc = async webView => {
|
|
2857
|
+
const {
|
|
2858
|
+
uid,
|
|
2859
|
+
origin
|
|
2860
|
+
} = webView;
|
|
2861
|
+
const {
|
|
2862
|
+
port1,
|
|
2863
|
+
port2
|
|
2864
|
+
} = getPortTuple();
|
|
2865
|
+
const rpcPromise = MessagePortRpcParent.create({
|
|
2866
|
+
messagePort: port2,
|
|
2867
|
+
isMessagePortOpen: false,
|
|
2868
|
+
commandMap: {}
|
|
2869
|
+
});
|
|
2870
|
+
const portType = 'test';
|
|
2871
|
+
await invokeAndTransfer$1('WebView.setPort', uid, port1, origin, portType);
|
|
2872
|
+
// TODO maybe don't send a message port only to get object url?
|
|
2873
|
+
// TODO dispose rpc to avoid memory leak
|
|
2874
|
+
const rpc = await rpcPromise;
|
|
2875
|
+
return rpc;
|
|
2876
|
+
};
|
|
2877
|
+
|
|
2878
|
+
const webViews = Object.create(null);
|
|
2879
|
+
const webViewProviders = Object.create(null);
|
|
2880
|
+
const getProvider = providerId => {
|
|
2881
|
+
return webViewProviders[providerId];
|
|
2882
|
+
};
|
|
2883
|
+
const setProvider = (providerId, provider) => {
|
|
2884
|
+
webViewProviders[providerId] = provider;
|
|
2885
|
+
};
|
|
2886
|
+
const getWebView = id => {
|
|
2887
|
+
return webViews[id];
|
|
2888
|
+
};
|
|
2889
|
+
const setWebView = (id, webView) => {
|
|
2890
|
+
webViews[id] = webView;
|
|
2891
|
+
};
|
|
2892
|
+
const getWebViews$1 = () => {
|
|
2893
|
+
return webViews;
|
|
2894
|
+
};
|
|
2895
|
+
|
|
2896
|
+
// TODO if webViewId is provided,
|
|
2897
|
+
// 1. read file as blob
|
|
2898
|
+
// 2. send blob to webview
|
|
2899
|
+
// 3. create objecturl in webview
|
|
2900
|
+
// 4. send back objecturl to extension host worker
|
|
2901
|
+
// 5. provide objectUrl to extension
|
|
2902
|
+
|
|
2903
|
+
const getRemoteUrlForWebView = async (uri, options = {}) => {
|
|
2904
|
+
// TODO webviews should be stored in iframe worker
|
|
2905
|
+
const webView = getWebView(options.webViewId);
|
|
2906
|
+
if (!webView) {
|
|
2907
|
+
throw new Error(`webview ${options.webViewId} not found`);
|
|
2908
|
+
}
|
|
2909
|
+
const [rpc, blob] = await Promise.all([createWebViewIpc(webView), invoke$1('FileSystem.getBlob', uri)]);
|
|
2910
|
+
const objectUrl = await rpc.invoke('createObjectUrl', blob);
|
|
2911
|
+
return objectUrl;
|
|
2912
|
+
};
|
|
2913
|
+
|
|
2914
|
+
const isFileProtocol = protocol => {
|
|
2915
|
+
return !protocol || protocol === 'file';
|
|
2916
|
+
};
|
|
2917
|
+
const getRemoteUrlSync = uri => {
|
|
2918
|
+
const protocol = getProtocol(uri);
|
|
2919
|
+
const withoutPrefix = uri.startsWith('file://') ? uri.slice('file://'.length) : uri;
|
|
2920
|
+
if (platform === Remote && isFileProtocol(protocol)) {
|
|
2921
|
+
if (uri.startsWith('/')) {
|
|
2922
|
+
return `/remote${withoutPrefix}`;
|
|
2923
|
+
}
|
|
2924
|
+
return `/remote/${withoutPrefix}`;
|
|
2925
|
+
}
|
|
2926
|
+
if (platform === Electron && isFileProtocol(protocol)) {
|
|
2927
|
+
if (uri.startsWith('/')) {
|
|
2928
|
+
return `/remote${withoutPrefix}`;
|
|
2929
|
+
}
|
|
2930
|
+
return `/remote/${withoutPrefix}`;
|
|
2931
|
+
}
|
|
2932
|
+
return '';
|
|
2933
|
+
};
|
|
2934
|
+
const getRemoteUrl$1 = async (uri, options = {}) => {
|
|
2935
|
+
// TODO uri should always have protocol
|
|
2936
|
+
// then ask file system provider for remote url, for example disk file system provider or html file system provider
|
|
2937
|
+
const syncUrl = getRemoteUrlSync(uri);
|
|
2938
|
+
if (syncUrl) {
|
|
2939
|
+
return syncUrl;
|
|
2940
|
+
}
|
|
2941
|
+
if (options.webViewId) {
|
|
2942
|
+
return getRemoteUrlForWebView(uri, options);
|
|
2943
|
+
}
|
|
2944
|
+
if (uri.startsWith('html://')) {
|
|
2945
|
+
const url = await invoke$1('Blob.getSrc', uri);
|
|
2946
|
+
return url;
|
|
2947
|
+
}
|
|
2948
|
+
throw new Error(`unsupported platform for remote url`);
|
|
2949
|
+
};
|
|
2950
|
+
|
|
2847
2951
|
const state$9 = {
|
|
2848
2952
|
webExtensions: []
|
|
2849
2953
|
};
|
|
@@ -3022,7 +3126,10 @@ const getIconDefinitions = async providerId => {
|
|
|
3022
3126
|
const id = extension.id.split('.');
|
|
3023
3127
|
const shortId = id[1];
|
|
3024
3128
|
if (shortId === providerId && extension['source-control-icons'] && Array.isArray(extension['source-control-icons'])) {
|
|
3025
|
-
|
|
3129
|
+
const baseIcons = extension['source-control-icons'];
|
|
3130
|
+
const absoluteUris = baseIcons.map(icon => `${extension.uri}/${icon}`);
|
|
3131
|
+
const remoteUris = absoluteUris.map(icon => getRemoteUrlSync(icon));
|
|
3132
|
+
return remoteUris;
|
|
3026
3133
|
}
|
|
3027
3134
|
}
|
|
3028
3135
|
// TODO return warning that no icons were found?
|
|
@@ -3089,99 +3196,6 @@ const {
|
|
|
3089
3196
|
}
|
|
3090
3197
|
});
|
|
3091
3198
|
|
|
3092
|
-
const RE_PROTOCOL = /^([a-z-]+):\/\//;
|
|
3093
|
-
const getProtocol = uri => {
|
|
3094
|
-
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
3095
|
-
if (protocolMatch) {
|
|
3096
|
-
return protocolMatch[1];
|
|
3097
|
-
}
|
|
3098
|
-
return '';
|
|
3099
|
-
};
|
|
3100
|
-
|
|
3101
|
-
const createWebViewIpc = async webView => {
|
|
3102
|
-
const {
|
|
3103
|
-
uid,
|
|
3104
|
-
origin
|
|
3105
|
-
} = webView;
|
|
3106
|
-
const {
|
|
3107
|
-
port1,
|
|
3108
|
-
port2
|
|
3109
|
-
} = getPortTuple();
|
|
3110
|
-
const rpcPromise = MessagePortRpcParent.create({
|
|
3111
|
-
messagePort: port2,
|
|
3112
|
-
isMessagePortOpen: false,
|
|
3113
|
-
commandMap: {}
|
|
3114
|
-
});
|
|
3115
|
-
const portType = 'test';
|
|
3116
|
-
await invokeAndTransfer$1('WebView.setPort', uid, port1, origin, portType);
|
|
3117
|
-
// TODO maybe don't send a message port only to get object url?
|
|
3118
|
-
// TODO dispose rpc to avoid memory leak
|
|
3119
|
-
const rpc = await rpcPromise;
|
|
3120
|
-
return rpc;
|
|
3121
|
-
};
|
|
3122
|
-
|
|
3123
|
-
const webViews = Object.create(null);
|
|
3124
|
-
const webViewProviders = Object.create(null);
|
|
3125
|
-
const getProvider = providerId => {
|
|
3126
|
-
return webViewProviders[providerId];
|
|
3127
|
-
};
|
|
3128
|
-
const setProvider = (providerId, provider) => {
|
|
3129
|
-
webViewProviders[providerId] = provider;
|
|
3130
|
-
};
|
|
3131
|
-
const getWebView = id => {
|
|
3132
|
-
return webViews[id];
|
|
3133
|
-
};
|
|
3134
|
-
const setWebView = (id, webView) => {
|
|
3135
|
-
webViews[id] = webView;
|
|
3136
|
-
};
|
|
3137
|
-
const getWebViews$1 = () => {
|
|
3138
|
-
return webViews;
|
|
3139
|
-
};
|
|
3140
|
-
|
|
3141
|
-
// TODO if webViewId is provided,
|
|
3142
|
-
// 1. read file as blob
|
|
3143
|
-
// 2. send blob to webview
|
|
3144
|
-
// 3. create objecturl in webview
|
|
3145
|
-
// 4. send back objecturl to extension host worker
|
|
3146
|
-
// 5. provide objectUrl to extension
|
|
3147
|
-
|
|
3148
|
-
const getRemoteUrlForWebView = async (uri, options = {}) => {
|
|
3149
|
-
// TODO webviews should be stored in iframe worker
|
|
3150
|
-
const webView = getWebView(options.webViewId);
|
|
3151
|
-
if (!webView) {
|
|
3152
|
-
throw new Error(`webview ${options.webViewId} not found`);
|
|
3153
|
-
}
|
|
3154
|
-
const [rpc, blob] = await Promise.all([createWebViewIpc(webView), invoke$1('FileSystem.getBlob', uri)]);
|
|
3155
|
-
const objectUrl = await rpc.invoke('createObjectUrl', blob);
|
|
3156
|
-
return objectUrl;
|
|
3157
|
-
};
|
|
3158
|
-
|
|
3159
|
-
const getRemoteUrl$1 = async (uri, options = {}) => {
|
|
3160
|
-
// TODO uri should always have protocol
|
|
3161
|
-
// then ask file system provider for remote url, for example disk file system provider or html file system provider
|
|
3162
|
-
const protocol = getProtocol(uri);
|
|
3163
|
-
if (platform === Remote && !protocol) {
|
|
3164
|
-
if (uri.startsWith('/')) {
|
|
3165
|
-
return `/remote${uri}`;
|
|
3166
|
-
}
|
|
3167
|
-
return `/remote/${uri}`;
|
|
3168
|
-
}
|
|
3169
|
-
if (platform === Electron && !protocol) {
|
|
3170
|
-
if (uri.startsWith('/')) {
|
|
3171
|
-
return `/remote${uri}`;
|
|
3172
|
-
}
|
|
3173
|
-
return `/remote/${uri}`;
|
|
3174
|
-
}
|
|
3175
|
-
if (options.webViewId) {
|
|
3176
|
-
return getRemoteUrlForWebView(uri, options);
|
|
3177
|
-
}
|
|
3178
|
-
if (uri.startsWith('html://')) {
|
|
3179
|
-
const url = await invoke$1('Blob.getSrc', uri);
|
|
3180
|
-
return url;
|
|
3181
|
-
}
|
|
3182
|
-
throw new Error(`unsupported platform for remote url`);
|
|
3183
|
-
};
|
|
3184
|
-
|
|
3185
3199
|
// TODO pass uuid to allow having multiple webviews open at the same time
|
|
3186
3200
|
|
|
3187
3201
|
/**
|