Skip to content

Commit 6923a7b

Browse files
committed
fixup the extension swapper to suck less
1 parent 73b29ff commit 6923a7b

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/containers/tw-custom-extension-modal.jsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,15 @@ class CustomExtensionModal extends React.Component {
116116
}
117117
async handleLoadExtension () {
118118
let failed = false;
119-
if (this.props.swapId) {
119+
// i dont think this is a good idea to say anymore, either swap works or its bugged
120+
if (/*this.props.swapId*/ false) {
120121
/* eslint-disable-next-line no-alert, max-len */
121122
if (!confirm('Failure to swap extensions will cause the extension to be flatout removed, are you sure the inputed extension has matching id\'s and has no errors?')) {
122123
return;
123124
}
124125
}
125126
this.handleClose();
127+
const oldUrl = this.props.vm.extensionManager.extensionUrlFromId(this.props.swapId);
126128
try {
127129
const url = await this.getExtensionURL();
128130
if (this.state.unsandboxed) {
@@ -131,17 +133,21 @@ class CustomExtensionModal extends React.Component {
131133
if (this.props.swapId) {
132134
const runtime = this.props.vm.runtime;
133135
this.props.vm.extensionManager.prepareSwap(this.props.swapId);
134-
const loadedIds = await this.props.vm.extensionManager.loadExtensionURL(url);
136+
const startingIds = Object.keys(this.props.vm.extensionManager.getExtensionURLs());
137+
await this.props.vm.extensionManager.loadExtensionURL(url);
138+
const loadedIds = Object.keys(this.props.vm.extensionManager.getExtensionURLs())
139+
.filter(id => !startingIds.includes(id));
135140
if (!loadedIds.includes(this.props.swapId)) {
136141
for (const ext of loadedIds) this.props.vm.extensionManager.removeExtension(ext);
142+
this.props.vm.extensionManager.loadExtensionURL(oldUrl);
137143
// eslint-disable-next-line no-alert
138-
alert('The extension you used for the edit had a different ID than the one you were editing.');
144+
alert('The extension you used for the edit had a different ID than the one you were editing. Reverting replacement.');
139145
}
140146
loadedIds.forEach(extId => {
141147
const idx = runtime._blockInfo.findIndex(ext => ext.id === extId);
142148
const doubleIdx = runtime._blockInfo.findIndex((ext, i) => ext.id === extId && i !== idx);
143149
if (doubleIdx === -1) return;
144-
const extInfo = runtime._blockInfo[idx];
150+
const extInfo = runtime._blockInfo[doubleIdx];
145151
runtime._blockInfo.splice(doubleIdx, 1);
146152
runtime._blockInfo.splice(idx, 1, extInfo);
147153
});
@@ -162,6 +168,7 @@ class CustomExtensionModal extends React.Component {
162168
// eslint-disable-next-line no-alert
163169
alert('The extension you used for the edit has failed to load.');
164170
this.props.vm.runtime._removeExtensionPrimitive(this.props.swapId);
171+
this.props.vm.extensionManager.loadExtensionURL(oldUrl);
165172
}
166173
if (failed) return;
167174
if (!this.state.addingToLibrary) return;

src/reducers/modals.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const reducer = function (state, action) {
4343
const makeState = {
4444
[action.modal]: true
4545
};
46-
if (action.extensionModalSwapId) makeState.extensionModalSwapId = action.extensionModalSwapId;
46+
makeState.extensionModalSwapId = action.extensionModalSwapId;
4747
return Object.assign({}, state, makeState);
4848
}
4949
case CLOSE_MODAL:

0 commit comments

Comments
 (0)