ntminhdn / Flutter-Bloc-CleanArchitecture

457 stars 200 forks source link

Error from Clipboard to Data Model tool #36

Closed jinergenkai closed 10 months ago

jinergenkai commented 10 months ago

Error from Clipboard to Data Model tool. I use the tool nalsmobilebrain you shared: Clipboard to Data Model, when Enter after entering the model name, the following error always appears "exactly" those words no matter what is in my clipboard. image

Err: the JSON is invalid: JSONError: Unexpected token '�', "�J뢰��z-~)ݱ"... is not valid JSON while parsing '�J뢰��z-~)ݱ��������٢���מ�ק�*'���y��y�鹹'

I use Flutter 3.13.1 and windows.

Maybe the error comes from incompatibility with the windows clipboard, I understand you only support Macos.

Can you fix it, or share the source code of the tool. Or do I have to rewrite the tool from scratch?

I look forward to receiving feedback from you on the above issue. Thanks!

jinergenkai commented 10 months ago

Hey, I'm trying to fix this by editing the extension code, specifically for Windows users.

  1. Navigate to %USERPROFILE%\.vscode\extensions\undefined_publisher.nalsmobilebrain-0.10.0\dist and open extension.js.

  2. Use format document (Shift+Alt+F) to improve readability.

  3. Inside extension.js, search for "base64").slice(3).toString("utf-8") and replace from:

    return (
    (t = t.substr(0, t.length - 2)),
    Buffer.from(t, "base64").slice(3).toString("utf-8")
    );
    • into: return (t, t);
  4. Create a new folder named fallbacks inside the dist folder, and within it, create a file named paste.vbs. Insert the following code into paste.vbs:

    
    Sub CopyToClipboard(data)
    Dim objHTML
    Set objHTML = CreateObject("htmlfile")
    objHTML.ParentWindow.ClipboardData.SetData "text", data
    Set objHTML = Nothing
    End Sub
    Function PasteFromClipboard()
    Dim objHTML, clipboardData
    Set objHTML = CreateObject("htmlfile")
    clipboardData = objHTML.ParentWindow.ClipboardData.GetData("text")
    PasteFromClipboard = clipboardData
    Set objHTML = Nothing
    End Function

WScript.StdOut.Write PasteFromClipboard()

5. In extension.js,  look for `Couldn't write file due to error: ${e}`  and add the following line of code just before this section:

if (!e.startsWith(i.workspace.workspaceFolders[0].uri.fsPath)) e = i.workspace.workspaceFolders[0].uri.fsPath + e;

This addition should come before:

c.writeFile(e, t, "utf8", (e) => { e ? n( new Error( Couldn't write file due to error: ${e} ) ) : u(); });