The TouchBarButton function cannot be used as a constructor

Encountered an error while using Electron:

This is my code for a Better Discord add-on written in JavaScript. I am relatively new to JS, so any assistance would be greatly appreciated. Thank you.

//META{"name":"BetterTouchbar"}*//
const { app, BrowserWindow, TouchBar, TouchBarButton} = require('electron');
class BetterTouchbar {

    // Constructor
    constructor() {
        this.initialized = false;
    }

    // Meta Information
    getName() { return "BetterTouchbar"; }
    getShortName() { return "BT"; }
    getDescription() { return "eekZ"; }
    getVersion() { return "0.1.0"; }
    getAuthor() { return "Aj3douglas"; }

    start(){

        const button = new TouchBarButton({
            label: "a",
            backgroundColor: "#FF0000",
            accessibilityLabel: "a",
            click: ()=>{
                console.log("Clicked a button")
            }
        });
        const touchBar = new TouchBar({
            items: [button],
        })
        window.setTouchBar(touchBar)
    }
}

Answer â„–1

Importing TouchBarButton incorrectly can lead to it being undefined when your code runs, resulting in an error.

To correctly extract it from TouchBar, use the following syntax:

const { app, BrowserWindow, TouchBar } = require('electron');
const { TouchBarButton } = TouchBar;

Note:

If you are attempting to modify a core aspect of Discord, which is not supported by the plugin system, you will need to override Discord's code. Unfortunately, as Discord is not open source, forking and modifying the codebase is not possible.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Aligning my website in HTML

Is it possible for me to create a similar effect on my site like the one seen here ()? The site has a background with content layered on top of it. When you scroll the page horizontally, the content remains centered until you reach the very left edge, at w ...

A guide to extracting the Jquery Version from the Chrome browser console while browsing webpages and transferring it to the Eclipse Java console using Selenium

Is there a way to retrieve the Jquery Version from Chrome browser console for webpages and transfer it to eclipse Java console using selenium? Try this command: $. ui. version https://i.sstatic.net/3bxA1.png ...

Use jQuery to select and emphasize the following menu option

Hey there! I'm currently working on adding a new feature to my website. I want the menu items to highlight in succession when clicked. For example, if I click on people, I want it to highlight and then move on to highlight the next item in the menu, w ...

How can you alter each character when you hover over them?

I have a query <p class="item">Ultimatepp’s</p> When hovering over it, I want to change each character individually. I currently have a few characters stored in a variable called 'characters': 'a#ldfhas?', 'kdjbiho ...

Deliver real-time updates directly to clients using Django Channels and Websockets

Currently, I am working on a page that needs to display live-updating data to the client. The rest of the website is constructed using Django framework, so my approach involves utilizing Channels for this purpose. The data that needs to be showcased is st ...

Sending an Angular expression based on an identifier

When the onchange() event is triggered in the Select/Option element, it is supposed to write the value of the JSON file as an angular expression to the test ID div. However, it currently writes it as a string: {{names[1].thnev}} (Manually inserting this i ...

The use of JQuery repeating fields can cause disruptions to the Bootstrap layout when removing rows

I have been struggling with a form that contains multiple fields that need to be repetitive. My current code is functional, but I'm encountering an issue where clicking on any remove button other than the first one causes the fields in the row to rear ...

405 status code returned for CORS request

Hello everyone, I need assistance with my CORS issue. I am trying to make an API request from another domain and encountering an error with the following code: var headers = { host: host, path: url + instance + '?action=reset', ...

Struggling to link variables and functions to an angularJS controller

When using the $scope object to bind functions and variables, and making changes accordingly in HTML, the code works fine. But when using a different object, it doesn't work as expected. Here is an example of a working code snippet: ...

Is the .html page cached and accessible offline if not included in the service-worker.js file?

During the development of my PWA, I encountered an unexpected behavior with caching. I included a test .html page for testing purposes that was not supposed to be cached in the sw.js folder. Additionally, I added some external links for testing. However, w ...

The iPad scroll did not meet the condition for reaching the bottom

Looking to modify the footer when the bottom of the page is reached via scrolling, I implemented the following code: if($(window).scrollTop() + $(window).height() == $(document).height()) This condition successfully detects whether the scroll has reached ...

Why is there only one element in the slot when using v-for?

Within my Vue application code, there is a swiper component. Inside this component, I am using a v-for and a slot. I am facing an issue in the parent component (Foo) where I need to access the component (baz) I inserted into the slot using a ref. However, ...

Creating a secured page with Node.js and Express: Password Protection

I am a beginner with node.js/express! Currently, I am working on developing a chat site along with a chat admin site. When I navigate to _____:3000/admin, it prompts me for a password through a form. I am looking for a way to verify if the entered passwor ...

Utilizing PhP and AJAX for seamless form uploads without the need to refresh the page

I have a form in PHP that reloads after submission. I implemented Ajax to prevent the reloading, but now the data is not being submitted to the database. Am I overlooking something here? When I remove the AJAX, it functions properly but reloads the page. I ...

Delete the radio button list within the content placeholder

I'm having trouble with accessing elements by name on a master page content placeholder. Can someone assist me with this issue? Thank you in advance. <asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> <script type="tex ...

Arranging a collection of objects into a two-dimensional array

I've got an array of objects that I want to format in a way suitable for react-csv, specifically as a 2D array resembling a nested loop structure shown below: https://i.sstatic.net/41cuj.png The desired end result should look like this: [ ["Name", ...

The code is functioning properly on both Codepen and JSFiddle

I encountered an issue where my code for the header to display only when scrolling up worked perfectly in jsfiddle or codepen, but failed when I tried it in my own program. It was puzzling because I copied and pasted the same code into both platforms and i ...

"The incredible power of the spread operator in conjunction with EsLint

Is there a way to duplicate an object and modify one of its properties? Here's an example: const initialState = { showTagPanel: false, }; export default function reducerFoo(state = initialState, action) { switch(action.type) { case types.SH ...

Ways to effectively utilize jQuery objects as arguments in the delegate function

When working with delegate and multiple selectors, you can use the following syntax: $(contextElement).delegate('selector1, selector2' , 'eventName', function(){ //blabla }); In projects where managing DOM elements is important, stori ...

What is the best way to delete a subdocument from a main document when either condition x is true or condition y is true?

A subdocument referred to as Bets is embedded into an array of a property on another model called Users. When a user removes a friend, all associated bets with that specific user should also be deleted from the User document (the user who was friends with ...