Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] migrate remaining deprecated chrome storage API calls to ConfigStorage JSON implementation. #2636

Merged
merged 1 commit into from May 27, 2022

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
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
@haslinghuis haslinghuis removed this from Configurator in Finalizing Firmware 4.3 Release 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 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
Copy link
Member Author

Squashed and rebased

@sonarcloud
Copy link

sonarcloud bot commented Apr 21, 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

@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 added this to Needs work in Finalizing Firmware 4.3 Release via automation May 27, 2022
@haslinghuis haslinghuis modified the milestones: 10.9.0, 10.8.0 May 27, 2022
@haslinghuis haslinghuis moved this from Needs work to Finished (Merged) in Finalizing Firmware 4.3 Release May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

6 participants