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

Cannot integrate node in the menubar BrowserWindow #363

Open
eesahsaeed opened this issue Dec 7, 2021 · 2 comments
Open

Cannot integrate node in the menubar BrowserWindow #363

eesahsaeed opened this issue Dec 7, 2021 · 2 comments

Comments

@eesahsaeed
Copy link

Error

error1

Actual Behaviour

Uncaught ReferenceError: require is not defined

Specifications

  • Menubar version: menubar v9.1.0
  • Platform: windows 10
  • Electron version: electron v16.0.2

Source Code

Main process

`
const MenuBar = require( "menubar" ).menubar;

let browserWindow = null;

const menubar = MenuBar( {
index: file://${__dirname}/index.html,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
} );

menubar.on( "ready", () => {
console.log( "Application is ready" );
} );

menubar.on( "after-create-window", () => {
menubar.window.webContents.openDevTools();
} );
`

Renderer process

console.log( "in renderer" );

const { clipboard } = require( "electron" );

const clippingsList = document.getElementById( "clippings-list" );
const copyFromClipboardButton = document.getElementById( "copy-from-clipboard" );

clippingsList.addEventListener( "click", event => {
const hasClass = className => {
event.target.classList.contains( className );

const clippingListItem = getButtonParent( event );

if ( hasClass( "remove-clipping" ) ) removeClipping( clippingListItem );
if ( hasClass( "copy-clipping" ) ) writeToClipboard( getClippingText( clippingListItem ) );
if ( hasClass( "publish-clipping" ) ) console.log( "Publish clipping", getClippingText() );

}
} );

const addClippingToList = () => {
const clippingText = clipboard.readText();
const clippingElement = createClippingElement( clippingText );
clippingsList.prepend( clippingElement );
};

const getButtonParent = ( target ) => {
return target.parentNode.parentNode;
};

const getClippingText = ( clippingListItem ) => {
return clippingListItem.querySelector( ".clipping-text" ).innerText;
};

const removeClipping = target => {
target.remove();
};

const writeToClipboard = ( clippingText ) => {
clipboard.writeText( clippingText );
};

const createClippingElement = ( clippingText ) => {
const clippingElement = document.createElement( "article" );

clippingElement.classList.add( "clippings-list-item" );

clippingElement.innerHTML = <div class='clipping-text' disabled='true'></div> <div class="clipping-controls"> <button class="copy-clipping">&rarr; Clipboard</button> <button class="publish-clipping">Publish</button> <button class="remove-clipping">Remove</button> </div>;

clippingElement.querySelector( ".clipping-text" ).innerText = clippingText;

return clippingElement;
}

copyFromClipboardButton.addEventListener( "click", addClippingToList );

##Anyone who can help please?

@linonetwo
Copy link
Contributor

Use https://github.com/linonetwo/electron-ipc-cat

Remote is deprecated.

@aceimnorstuvwxz
Copy link

see this issue's solution: #334

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants