Skip to content

Conversation

@haslinghuis
Copy link
Member

We need to migrate deprecated API's.

This PR is removing chrome.storage API and uses the ConfigStorage.js we had in place already instead.

Deprecated API Suggested API Link
chrome.storage Cache API https://web.dev/storage-for-the-web/
chrome.fileSystem Native FileSystem API https://web.dev/file-system-access/
chrome.serial Web Serial API https://web.dev/serial/
chrome.sockets.tcp WebSockets https://web.dev/websocketstream/
chrome.usb Web USB API https://web.dev/usb/

@haslinghuis haslinghuis added this to the 10.8.0 milestone Oct 17, 2021
@haslinghuis haslinghuis self-assigned this Oct 17, 2021
@haslinghuis haslinghuis force-pushed the remove_chrome_storage branch 2 times, most recently from 4048b62 to 128b024 Compare October 18, 2021 01:04
@haslinghuis haslinghuis changed the title migrate chrome storage API to window.localStorage migrate remaining depecrated chrome storage API calls to ConfigStorage JSON implementation. Oct 18, 2021
Copy link
Member

@chmelevskij chmelevskij left a comment

Choose a reason for hiding this comment

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

I'd remove callbacks if using local storage. Would make it a bit easier to reason about since now storage is all sync.

@chmelevskij
Copy link
Member

So to fix the callback issue we need to refactor the get as well

get: function(key, callback) {
if (Array.isArray(key)) {
let obj = {};
key.forEach(function (element) {
try {
obj = {...obj, ...JSON.parse(window.localStorage.getItem(element))};
} catch (e) {
// is okay
}
});
callback(obj);
} else {
const keyValue = window.localStorage.getItem(key);
if (keyValue) {
let obj = {};
try {
obj = JSON.parse(keyValue);
} catch (e) {
// It's fine if we fail that parse
}
callback(obj);
} else {
callback({});
}
}
},

    get: function(key) {
        if (Array.isArray(key)) {
            let obj = {};
            key.forEach(function (element) {
                try {
                    obj = {...obj, ...JSON.parse(window.localStorage.getItem(element))};
                } catch (e) {
                    // is okay
                }
            });
            return obj;
        } else {
            const keyValue = window.localStorage.getItem(key);
            if (keyValue) {
                let obj = {};
                try {
                    obj = JSON.parse(keyValue);
                } catch (e) {
                    // It's fine if we fail that parse
                }
                return obj;
            } else {
                return {};
            }
        }
    },

Then in the actual code which was using the callback, return value of get needs to be assigned to a variable and later on used in the callback body logic.

@haslinghuis haslinghuis force-pushed the remove_chrome_storage branch 3 times, most recently from 40a76f5 to 6dcf2ac Compare November 21, 2021 17:55
@haslinghuis haslinghuis modified the milestones: 10.8.0, 10.7.1 Nov 21, 2021
@haslinghuis haslinghuis force-pushed the remove_chrome_storage branch from 6dcf2ac to 535bdf1 Compare November 21, 2021 20:34
@haslinghuis
Copy link
Member Author

Squashed and rebased

@limonspb
Copy link
Member

Proposal (discussed with @haslinghuis )
leave it for 10.9 or 10.8.1

limonspb
limonspb previously approved these changes Nov 22, 2021
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 9, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@haslinghuis
Copy link
Member Author

Rebased

chmelevskij
chmelevskij previously approved these changes Jan 10, 2022
@haslinghuis haslinghuis added this to the 10.9.0 milestone Jan 10, 2022
@blckmn
Copy link
Member

blckmn commented Jan 10, 2022

AUTOMERGE: (FAIL)

  • github identifies PR as mergeable -> FAIL
  • assigned to a milestone -> PASS
  • cooling off period lapsed -> PASS
  • commit count less or equal to three -> PASS
  • Don't merge label NOT found -> PASS
  • at least one RN: label found -> PASS
  • Tested label found -> FAIL
  • assigned to an approver -> PASS
  • approver count at least three -> FAIL

@haslinghuis haslinghuis force-pushed the remove_chrome_storage branch from 725d4b4 to 578473d Compare February 25, 2022 01:01
@haslinghuis haslinghuis changed the title migrate remaining depecrated chrome storage API calls to ConfigStorage JSON implementation. [chore] migrate remaining deprecated chrome storage API calls to ConfigStorage JSON implementation. Feb 25, 2022
@github-actions

This comment has been minimized.

@haslinghuis
Copy link
Member Author

Rebased

Add remove function

Remove callback from set and remove

Rebased

Rebased
@haslinghuis haslinghuis force-pushed the remove_chrome_storage branch from 753cda8 to f41e135 Compare April 21, 2022 23:09
@haslinghuis
Copy link
Member Author

Squashed and rebased

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@github-actions
Copy link
Contributor

Do you want to test this code? Here you have an automated build:
Betaflight-Configurator-Android
Betaflight-Configurator-Linux
Betaflight-Configurator-macOS
Betaflight-Configurator-Windows
WARNING: It may be unstable and result in corrupted configurations or data loss. Use only for testing!

@haslinghuis haslinghuis mentioned this pull request May 26, 2022
8 tasks
@haslinghuis haslinghuis merged commit ee3ddc1 into betaflight:master May 27, 2022
@haslinghuis haslinghuis deleted the remove_chrome_storage branch May 27, 2022 00:44
@haslinghuis haslinghuis modified the milestones: 10.9.0, 10.8.0 May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants