Import File implementation

Summary: Implementation was missing for the browser. This provides a default implementation.

Reviewed By: aigoncharov

Differential Revision: D48311198

fbshipit-source-id: fd067600f571234e0fbccfb90853b62f175ff8fb
This commit is contained in:
Lorenzo Blasa
2023-08-14 11:33:06 -07:00
committed by Facebook GitHub Bot
parent 2f5f4911e5
commit ff6f98fc0d
12 changed files with 130 additions and 54 deletions

View File

@@ -139,6 +139,9 @@ export function createNetworkManager(
})
.then((res) => {
if (res) {
if (res.encoding !== 'utf-8' || typeof res.data !== 'string') {
return;
}
const importedRoutes = JSON.parse(res.data);
importedRoutes?.forEach((importedRoute: Route) => {
if (importedRoute != null) {

View File

@@ -123,27 +123,31 @@ export function plugin(client: PluginClient<Events, Methods>) {
}
async function loadFromFile() {
const file = await getFlipperLib().importFile();
if (file?.path != undefined) {
const data = await getFlipperLib().remoteServerContext.fs.readFile(
file.path,
{encoding: 'utf-8'},
);
const preferences = JSON.parse(data) as SharedPreferencesEntry;
const name = selectedPreferences.get();
if (name != null) {
updateSharedPreferences({
name: name,
preferences: preferences.preferences,
});
for (const key in preferences.preferences) {
await client.send('setSharedPreference', {
sharedPreferencesName: name,
preferenceName: key,
preferenceValue: preferences.preferences[key],
if (file && file.encoding === 'utf-8' && typeof file.data === 'string') {
try {
const preferences = JSON.parse(file.data) as SharedPreferencesEntry;
const name = selectedPreferences.get();
if (name != null) {
updateSharedPreferences({
name: name,
preferences: preferences.preferences,
});
for (const key in preferences.preferences) {
await client.send('setSharedPreference', {
sharedPreferencesName: name,
preferenceName: key,
preferenceValue: preferences.preferences[key],
});
}
}
} catch (e) {
console.warn('Unable to import shared preferences', e);
}
} else {
console.warn(
'The loaded file either has wrong encoding or is not a valid json file',
);
}
}