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

Start in tray #18

Closed
fernandogobah opened this issue Mar 19, 2020 · 9 comments
Closed

Start in tray #18

fernandogobah opened this issue Mar 19, 2020 · 9 comments

Comments

@fernandogobah
Copy link

Is possible start the app in tray bar?

@subratappt
Copy link

The following codes will give you tray

const path = require('path');
const trayIcon = path.join(__dirname, 'assets/icon.ico');
//const trayIcon = nativeImage.createFromPath("./assets/icon.png");

app.on("ready", () => {
  tray = new Tray(trayIcon)
  const contextMenu = Menu.buildFromTemplate([
    {
      label: 'Play/Pause', click: function () {
        hook_ytm("#left-controls > div > paper-icon-button.play-pause-button.style-scope.ytmusic-player-bar")
      }
    },
    {
      label: 'Next', click: function () {
        hook_ytm("#left-controls > div > paper-icon-button.next-button.style-scope.ytmusic-player-bar")
      }
    },
    {
      label: 'Prev', click: function () {
        hook_ytm("#left-controls > div > paper-icon-button.previous-button.style-scope.ytmusic-player-bar")
      }
    },
    {
      label: 'Show', click: function () {
        win.show()
      }
    },

    {
      label: 'Quit', click: function () {
        app.quit()
      }
    },
  ])
  tray.setToolTip('Youtube Music')
  tray.on('double-click', () => {
    win.show()
  })
  if (process.platform == 'win32') {
    tray.on('click', tray.popUpContextMenu)
  }
  tray.setContextMenu(contextMenu);
  createWindow();
}
)

// bla bla bla

async function createWindow() {
  win = new BrowserWindow({
    backgroundColor: "#000",
    webPreferences: { nodeIntegration: false, contextIsolation: true },
	// bla bla bla
  })

  win.on('close', (event) => {
    if (app.quitting) {
      win = null
    } else {
      if (process.platform == 'darwin') {
        app.dock.hide()
      }
      event.preventDefault()
      win.hide()
    }
  })

  await win.loadURL('https://music.youtube.com')

  return win;
}


function hook_ytm(selector) {
  win.webContents.executeJavaScript('document.querySelector("' + selector + '").click();', true)
}

@th-ch
Copy link
Owner

th-ch commented Apr 12, 2020

Hey @fernandogobah , thanks for submitting the issue! The latest version (v1.3.1) has an "options" menu, you can enable tray and set the window visible or hidden - with "Tray + hidden window", you should have the behavior "start in tray".

Feel free to re-open this issue if it does not work properly!

PS: Thank you @subratappt for the code snippet, it has been implemented in the app!

@th-ch th-ch closed this as completed Apr 12, 2020
@subratappt
Copy link

subratappt commented Apr 14, 2020

Thank you for the implementation.

Version: 1.3.1

  1. For Windows, when the tray is on, please change close button behaviour of window from quit to hide.
  2. In the tray, play/pause is not working properly.

@th-ch th-ch reopened this Apr 14, 2020
@th-ch
Copy link
Owner

th-ch commented Apr 26, 2020

Hey @subratappt, thanks for reporting both issues!

v1.3.2 should fix issue 1, the app should now not exit if the tray is on (unless you select "Quit" in the tray menu) + clicking on the tray icon should now show/hide the app.

For the second issue, play/pause seems to work fine for me (tested on Windows/Mac) unless the plugin "autoconfirm when paused" is enabled (playing is resumed automatically by the plugin just after pausing), do yo have it enabled? This plugin is still quite experimental (it also messes up with play/pause through media keys) - if you don't have this plugin enabled, then it might be another bug! - which plugins do you use in the app?

@subratappt
Copy link

Hey @subratappt, thanks for reporting both issues!

v1.3.2 should fix issue 1, the app should now not exit if the tray is on (unless you select "Quit" in the tray menu) + clicking on the tray icon should now show/hide the app.

For the second issue, play/pause seems to work fine for me (tested on Windows/Mac) unless the plugin "autoconfirm when paused" is enabled (playing is resumed automatically by the plugin just after pausing), do yo have it enabled? This plugin is still quite experimental (it also messes up with play/pause through media keys) - if you don't have this plugin enabled, then it might be another bug! - which plugins do you use in the app?

Thank you for the update. Yes for the second issue, "autoconfirm when paused" was enabled. I hope you will get the issue solved soon.

@benji009
Copy link

Is it possible to add auto start when you turn on the computer?

@th-ch
Copy link
Owner

th-ch commented Jul 12, 2020

Hey @benji009, thank you for the feedback!

#32 adds an option to autostart the application at login (YouTube Music then starts playing automatically) which is available in the 1.4.0 pre-release but only works for Mac/Win (limitation of electron), would this do the job for you?

@benji009
Copy link

yes that is perfect :)

@th-ch th-ch mentioned this issue Oct 19, 2020
@th-ch
Copy link
Owner

th-ch commented Jan 15, 2021

It seems the last open problem in this issue is the auto-confirm-when-paused vs media keys - it seems it is fixed in the last versions but in case it's not, it will be tracked in #129 - closing this one, feel free to re-open/open a new issue if needed!

@th-ch th-ch closed this as completed Jan 15, 2021
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

4 participants