No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Tray icon not showing in production(Electron)

    Help
    5
    10
    2901
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      donvie last edited by donvie

      Tray icon not showing in production but in development the icon it is showing. i am using mac to build the electron app.

      Thank you

      import { app, BrowserWindow, nativeTheme, Menu, Tray } from 'electron'
      const path = require('path')
      
      try {
        if (process.platform === 'win32' && nativeTheme.shouldUseDarkColors === true) {
          require('fs').unlinkSync(require('path').join(app.getPath('userData'), 'DevTools Extensions'))
        }
      } catch (_) { }
      
      /**
       * Set `__statics` path to static files in production;
       * The reason we are setting it here is that the path needs to be evaluated at runtime
       */
      if (process.env.PROD) {
        global.__statics = __dirname
      }
      
      let mainWindow
      
      function createWindow () {
        /**
         * Initial window options
         */
        mainWindow = new BrowserWindow({
          width: 350,
          height: 600,
          useContentSize: true,
          frame: false,
          minWidth: 240,
          minHeight: 500,
          titleBarStyle: 'hidden',
          webPreferences: {
            // Change from /quasar.conf.js > electron > nodeIntegration;
            // More info: https://quasar.dev/quasar-cli/developing-electron-apps/node-integration
            nodeIntegration: process.env.QUASAR_NODE_INTEGRATION,
            nodeIntegrationInWorker: process.env.QUASAR_NODE_INTEGRATION,
      
            // More info: /quasar-cli/developing-electron-apps/electron-preload-script
            // preload: path.resolve(__dirname, 'electron-preload.js')
          }
        })
      
        mainWindow.setBackgroundColor('#f5f5f5') 
      
        mainWindow.loadURL(process.env.APP_URL)
      
        mainWindow.on('closed', () => {
          mainWindow = null
        })
      }
      
      
      let tray = null
      app.whenReady().then(() => {
        tray = new Tray(path.resolve(__statics,'icons', 'favicon-16x16.png'))
        const contextMenu = Menu.buildFromTemplate([
          {
            label: 'Light Mode / Dark Mode',
            click: function (item) {
              mainWindow.webContents.send('darkMode')
            }
          }
        ])
      
        tray.setToolTip('This is my application.')
        tray.setContextMenu(contextMenu)
      })
      
      app.on('ready', createWindow)
      
      app.on('window-all-closed', () => {
        if (process.platform !== 'darwin') {
          app.quit()
        }
      })
      
      app.on('activate', () => {
        if (mainWindow === null) {
          createWindow()
        }
      })
      
      
      1 Reply Last reply Reply Quote 0
      • D
        donvie last edited by

        NEED HELP!! Can someone experienced this problem

        1 Reply Last reply Reply Quote 0
        • L
          Luis Adriani last edited by

          I have the same problem. Can anyone help?

          1 Reply Last reply Reply Quote 0
          • Hawkeye64
            Hawkeye64 last edited by

            @donvie @Luis-Adriani Please follow the Electron guide here: https://www.electronjs.org/docs/api/tray

            1 Reply Last reply Reply Quote 0
            • T
              tangmemgyu last edited by

              Same Problem !! Need HELP!

              1 Reply Last reply Reply Quote 0
              • M
                mingzai84 last edited by

                put favicon-16x16.png into /public, then modify code :

                tray = new Tray(
                    require('path').resolve(__statics, 'favicon-16x16.png')
                )
                

                then build again and it’s done.

                1 Reply Last reply Reply Quote 0
                • M
                  mingzai84 last edited by

                  I’ve tested it many times. It seems that under the /public directory, except for icons and favicon.ico, The rest can be generated into the build package. It could be a bug. Or I guess quasar deliberately ignored them because they were web icons, not electron icons.

                  T 1 Reply Last reply Reply Quote 0
                  • T
                    tangmemgyu @mingzai84 last edited by tangmemgyu

                    @mingzai84 no use ,
                    I found a Unpackaged folder after building.
                    My Application’s first page view was just fine. but when I turn another route, it became white screen…
                    Tray was still lost…

                    Here is my file tree of public/

                    public
                    ├── favicon.ico
                    ├── fonts
                    │   ├── Nunito-Bold.ttf
                    │   └── Nunito-Regular.ttf
                    └── icons
                        ├── favicon-16x16.png
                        ├── favicon-180x180.png
                        ├── favicon-192x192.png
                        ├── favicon-32x32.png
                        ├── favicon-512x512.png
                        ├── favicon.ico
                        ├── icon-128x128.png
                        ├── icon-16x16.png
                        ├── icon-32x32.png
                        ├── icon-48x48.png
                        ├── icon-64x64.png
                        ├── icon.icns
                        ├── icon.ico
                        └── icon.png
                    

                    Here is my code in my electron.main.js

                    void app.whenReady().then(_ => {
                      tray = new Tray(
                        require('path').resolve(__statics, 'icons/favicon-16x16.png')
                      );
                      const trayMenu = Menu.buildFromTemplate([
                        {
                          label: '显示主窗口',
                          click: reShowWindow
                        },
                        {
                          label: '启用开发者模式',
                          click() {
                            reShowWindow();
                            openDevTools();
                          }
                        },
                        {
                          label: '退出 Search Zen',
                          click() {
                            app.quit();
                          }
                        }
                      ]);
                    
                      tray.setToolTip('Search Zen - 极速搜索助手');
                      tray.setContextMenu(trayMenu);
                    });
                    
                    1 Reply Last reply Reply Quote 0
                    • M
                      mingzai84 last edited by

                      i said put favicon-16x16.png into /public, you still put it into /public/icons;
                      i said to write this code

                      require('path').resolve(__statics, 'favicon-16x16.png')
                      

                      you still

                      require('path').resolve(__statics, 'icons/favicon-16x16.png')
                      

                      white screen is your app’s problem, not the icon problem

                      1 Reply Last reply Reply Quote 0
                      • T
                        tangmemgyu last edited by

                        Yes You’re right! Thanks for helping me!!
                        My tray now is available in production.
                        but white screen problem is still there. seen UnPackaged folders with a lot of files…

                        Here is my repo: https://github.com/ShenQingchuan/SearchZenTool.git
                        I can’t figure out for why my other pages are lost in production …

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post