Skip to content

Commit 6563173

Browse files
committed
Support for custom versions of the IITC core has been added to the methods for creating and restoring backups
1 parent 3e1671e commit 6563173

File tree

2 files changed

+66
-5
lines changed

2 files changed

+66
-5
lines changed

src/backup.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3
22

3-
import { parseMeta } from './helpers.js';
3+
import { isSet, parseMeta } from './helpers.js';
44
import deepmerge from '@bundled-es-modules/deepmerge';
55

66
/**
@@ -78,9 +78,9 @@ export const exportPluginsSettings = (all_storage) => {
7878
};
7979

8080
/**
81-
* Exports external plugins from the provided storage object.
81+
* Exports external IITC core and plugins from the provided storage object.
8282
*
83-
* This function takes a storage object and extracts external plugins based on predefined keys.
83+
* This function takes a storage object and extracts external IITC core and plugins based on predefined keys.
8484
* It creates a new object containing the external plugins organized by their channels and filenames,
8585
* and returns it.
8686
*
@@ -91,15 +91,34 @@ export const exportExternalPlugins = (all_storage) => {
9191
const external_plugins = {};
9292

9393
// An array of predefined keys for external plugins
94-
const storage_keys = ['release_plugins_user', 'beta_plugins_user', 'custom_plugins_user'];
94+
const storage_keys = [
95+
'release_iitc_core_user',
96+
'beta_iitc_core_user',
97+
'custom_iitc_core_user',
98+
'release_plugins_user',
99+
'beta_plugins_user',
100+
'custom_plugins_user',
101+
];
95102

96103
// Loop through all_storage and check if the keys are present in storage_keys
97104
// If present, process and add the external plugins to the external_plugins object
98105
for (const key in all_storage) {
99106
if (storage_keys.includes(key)) {
100107
// Extract the channel name from the key by splitting at '_'
101108
const channel = key.split('_')[0];
102-
external_plugins[channel] = {};
109+
const variant = key.split('_')[1];
110+
111+
// Create a channel if it doesn't exist
112+
if (!(channel in external_plugins)) {
113+
external_plugins[channel] = {};
114+
}
115+
116+
// Add a custom IITC core to the external_plugins object
117+
if (variant === 'iitc' && isSet(all_storage[key]) && isSet(all_storage[key]['code'])) {
118+
const plugin_filename = 'total-conversion-build.user.js';
119+
external_plugins[channel][plugin_filename] = all_storage[key]['code'];
120+
continue;
121+
}
103122

104123
// Loop through each plugin UID in the current key's storage data
105124
for (const plugin_uid in all_storage[key]) {

test/manager.9.backup.spec.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@ describe('getBackupData and setBackupData', function () {
99
let manager = null;
1010
const first_plugin_uid = 'Available AP statistics+https://github.com/IITC-CE/ingress-intel-total-conversion';
1111
const external_code = '// ==UserScript==\n// @name IITC plugin\n// ==/UserScript==\nreturn false;';
12+
const external_iitc_code =
13+
'// ==UserScript==\n' +
14+
'// @name IITC: Ingress intel map total conversion\n' +
15+
'// @namespace https://github.com/IITC-CE/ingress-intel-total-conversion\n' +
16+
'// ==/UserScript==\n' +
17+
'return false;';
1218
const initialBackupData = {
1319
external_plugins: {
1420
beta: {},
1521
custom: {},
1622
release: {
23+
'total-conversion-build.user.js': external_iitc_code,
1724
'bookmarks1.user.js': external_code,
1825
},
1926
},
@@ -39,6 +46,7 @@ describe('getBackupData and setBackupData', function () {
3946
'bookmarks2.user.js': external_code,
4047
},
4148
beta: {
49+
'total-conversion-build.user.js': external_iitc_code,
4250
'bookmarks3.user.js': external_code,
4351
},
4452
},
@@ -90,6 +98,31 @@ describe('getBackupData and setBackupData', function () {
9098
const run = await manager.managePlugin(first_plugin_uid, 'on');
9199
expect(run).to.be.undefined;
92100
});
101+
it('Add custom IITC core', async function () {
102+
const scripts = [
103+
{
104+
meta: {
105+
id: 'total-conversion-build',
106+
namespace: 'https://github.com/IITC-CE/ingress-intel-total-conversion',
107+
name: 'IITC: Ingress intel map total conversion',
108+
filename: 'total-conversion-build.user.js',
109+
},
110+
code: external_iitc_code,
111+
},
112+
];
113+
const installed = {
114+
'IITC: Ingress intel map total conversion+https://github.com/IITC-CE/ingress-intel-total-conversion': {
115+
uid: 'IITC: Ingress intel map total conversion+https://github.com/IITC-CE/ingress-intel-total-conversion',
116+
id: 'total-conversion-build',
117+
namespace: 'https://github.com/IITC-CE/ingress-intel-total-conversion',
118+
name: 'IITC: Ingress intel map total conversion',
119+
code: external_iitc_code,
120+
filename: 'total-conversion-build.user.js',
121+
},
122+
};
123+
const run = await manager.addUserScripts(scripts);
124+
expect(run).to.deep.equal(installed);
125+
});
93126
it('Add external plugin', async function () {
94127
const scripts = [
95128
{
@@ -155,6 +188,15 @@ describe('getBackupData and setBackupData', function () {
155188
VMin9999: 'backup2',
156189
});
157190

191+
const externalCore = await storage.get(['beta_iitc_core_user']);
192+
expect(externalCore['beta_iitc_core_user']).to.deep.equal({
193+
uid: 'IITC: Ingress intel map total conversion+https://github.com/IITC-CE/ingress-intel-total-conversion',
194+
name: 'IITC: Ingress intel map total conversion',
195+
namespace: 'https://github.com/IITC-CE/ingress-intel-total-conversion',
196+
code: external_iitc_code,
197+
filename: 'total-conversion-build.user.js',
198+
});
199+
158200
const externalPlugins = await storage.get(['release_plugins_user', 'beta_plugins_user']);
159201
expect(externalPlugins['release_plugins_user']).to.have.all.keys(
160202
'Bookmarks for maps and portals+https://github.com/IITC-CE/ingress-intel-total-conversion',

0 commit comments

Comments
 (0)