Skip to content

[devtools_plugin_sdk] Detect web refresh on devtools plugin side #7779

@davidmartos96

Description

@davidmartos96

Hello!
I'm developing a devtools plugin which offers functionality to clear/remove a local sqlite file on web and io platforms.

The problem I'm having is that when the app does a window.location.reload() when a request to reset the database is performed, the devtools plugin doesn't have the chance to know about this event, so we cannot update UI to remove this database from a list for example.
I tried using ServiceManager.connectedState but it doesn't seem to fit here, as the VM service session is the same one.

My implementation is as follows. It works correctly on IO platforms but not on web.

app side

void handleResetDbRequest() {
    // Delete database file / web indexeddb    
    await resetDb();
    
    // Let the plugin know that it needs to refresh the list of databases in the devtools UI
    postEvent('notify-db-update');
   
    // it does nothing on io and `window.location.reload()` on web
    await afterDbReset();
}

devtools plugin

Future<void> requestDbReset() async {
    // request a db reset to the app
    await serviceManager.callServiceExtensionOnMainIsolate(...);
    
    // Perform a hot restart of the app
    await serviceManager.performHotRestart();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2important to work on, but not at the top of the work list.devtools extensionsIssues related to DevTools extensions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions