AlexTorresDev / custom-electron-titlebar

Custom electon title bar inpire on VS Code title bar
MIT License
868 stars 149 forks source link

Remove use of fs module #194

Closed Madff386 closed 2 years ago

Madff386 commented 2 years ago

From version 20.0.0 of electron, preload process is now sandboxed by default electron #32869

This causes titlebar to throw errors when attempting to fetch node fs module used to read the custom user provided icon json file.

Updated titlebar.ts to remove the import of fs module and directly pass a dictionary of the json file instead of reading it from disk.

Using a bundler like webpack for the preload.js script could work like this (not tested):

import { Titlebar, Color } from 'custom-electron-titlebar';
import icon from './assets/images/icon.svg';
import icons from './assets/icons.json';

let titlebar;

window.addEventListener('DOMContentLoaded', () => {
  titlebar = new Titlebar({
    backgroundColor: Color.fromHex("#388e3c"),
    itemBackgroundColor: Color.fromHex("#121212"),
    svgColor: Color.WHITE,
    icon: icon,
    icons: icons,
    //menu: null // = do not automatically use Menu.applicationMenu
  })
Muhammad-Taif-Khan commented 2 years ago

Did you test it?

mdaff169 commented 2 years ago

I haven’t yet tested that example for the preload script. I can if you want me to.