{"id":13733358,"url":"https://github.com/felixhao28/node-systray","last_synced_at":"2025-05-08T09:32:05.633Z","repository":{"id":45998983,"uuid":"309557922","full_name":"felixhao28/node-systray","owner":"felixhao28","description":"A cross-platform systray library for nodejs.","archived":false,"fork":true,"pushed_at":"2023-05-16T18:06:10.000Z","size":34218,"stargazers_count":35,"open_issues_count":4,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-24T16:02:15.698Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/systray2","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"zaaack/node-systray","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/felixhao28.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-03T03:10:25.000Z","updated_at":"2024-12-31T10:25:21.000Z","dependencies_parsed_at":"2023-01-24T07:45:25.206Z","dependency_job_id":null,"html_url":"https://github.com/felixhao28/node-systray","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felixhao28%2Fnode-systray","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felixhao28%2Fnode-systray/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felixhao28%2Fnode-systray/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felixhao28%2Fnode-systray/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/felixhao28","download_url":"https://codeload.github.com/felixhao28/node-systray/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252512818,"owners_count":21760082,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T03:00:41.836Z","updated_at":"2025-05-08T09:32:00.908Z","avatar_url":"https://github.com/felixhao28.png","language":"TypeScript","funding_links":[],"categories":["System Tray"],"sub_categories":["Flexbox"],"readme":"# node-systray\n\n\u003e SysTray2 library for nodejs using [systray-portable](https://github.com/felixhao28/systray-portable) (a portable version of [the go systray library](https://github.com/getlantern/systray)).\n\n\n## Install\n```sh\nnpm i systray2\n# or\nyarn add systray2\n```\n\n## Usage\n\n### Simple Example\n\nThis example shows how to display a menu with two menu items, and how to handle mouse click events and exit the tray process.\n\n```ts\nimport SysTray from 'systray2';\nimport os from 'os'\n\nconst item = {\n  title: 'Show Exit Button',\n  tooltip: 'This menu item will toggle the display of the exit button.',\n  // The \"checked\" property will create a check mark on the side of this menu item.\n  // To dynamically update the display of the check mark, use the \"sendAction\" method, as shown below.\n  // Note that \"checked\" is implemented by plain text in linux\n  checked: false,\n  enabled: true,\n}\n\nconst itemExit = {\n  title: 'Exit',\n  tooltip: 'bb',\n  checked: false,\n  enabled: true,\n}\n\n// Simple menu example\nconst systray = new SysTray({\n  menu: {\n    // you should use .png icon on macOS/Linux, and .ico format on Windows\n    icon: os.platform() === 'win32' ? './logo_s.ico' : './logo_s.png',\n    // a template icon is a transparency mask that will appear to be dark in light mode and light in dark mode\n    isTemplateIcon: os.platform() === 'darwin',\n    title: '标题',\n    tooltip: 'Tips',\n    items: [\n      item,\n      itemExit\n    ]\n  },\n  debug: false,\n  copyDir: false // copy go tray binary to an outside directory, useful for packing tool like pkg.\n})\n\n// The actual handling of the click events.\n// This is obviously important if you want your MenuItems to react to mouse clicks.\nsystray.onClick(action =\u003e {\n  if (action.item.title === \"Exit\") {\n    systray.kill(false)\n  } else {\n    console.log(\"menu item clicked!\")\n  }\n})\n\n// Systray.ready is a promise which resolves when the tray is ready.\nsystray.ready().then(() =\u003e {\n  console.log('systray started!')\n}).catch(err =\u003e {\n  console.log('systray failed to start: ' + err.message)\n})\n```\n\n### Reactive Menu Example\n\nThis example shows how to use checkbox-style menu items and menus with sub menu items.\n\n```ts\nimport SysTray from 'systray2';\nimport os from 'os'\n\n/**\n * Represents a user-defined clickable MenuItem.\n * `click` here is a custom property. You can name it whatever you want, but it should\n * be in consistent with the name used in the systray.onClick callback.\n *\n * You do not necessarily need this type. But in most cases, you will need some ways to\n * react to the mouse clicks.\n *\n * The actual code for handling click events can be found at the end of the code sample.\n * ```\n * systray.onClick(action =\u003e {\n *   if (action.item.click != null) {\n *     action.item.click()\n *   }\n * })\n * ```\n */\ninterface MenuItemClickable extends MenuItem {\n  click?: () =\u003e void;\n  items?: MenuItemClickable[];\n}\n\nconst item1: MenuItemClickable = {\n  title: 'Show Exit Button',\n  tooltip: 'This menu item will toggle the display of the exit button.',\n  // The \"checked\" property will create a check mark on the side of this menu item.\n  // To dynamically update the display of the check mark, use the \"sendAction\" method, as shown below.\n  // Note that \"checked\" is implemented by plain text in linux\n  checked: false,\n  enabled: true,\n  // click is not a standard property but a custom value\n  click: () =\u003e {\n    // change the state\n    item1.checked = !item1.checked\n    // and then send it to the background tray service.\n    systray.sendAction({\n      type: 'update-item',\n      item: item1,\n    })\n    // toggle Exit\n    itemExit.hidden = !itemExit.hidden\n    systray.sendAction({\n      type: 'update-item',\n      item: itemExit,\n    })\n  }\n}\nconst item2: MenuItemClickable = {\n  title: 'Submenu Parent',\n  tooltip: 'this is the parent menu',\n  checked: false,\n  enabled: true,\n  hidden: false,\n  // add a submenu item\n  items: [{\n    title: 'Submenu',\n    tooltip: 'this is a submenu item',\n    checked: false,\n    enabled: true,\n    click: () =\u003e {\n      // open the url\n      console.log('open the url')\n    }\n  }]\n}\nconst itemExit: MenuItemClickable = {\n  title: 'Exit',\n  tooltip: 'bb',\n  checked: false,\n  enabled: true,\n  click: () =\u003e {\n    systray.kill(false)\n  }\n}\nconst systray = new SysTray({\n  menu: {\n    // you should use .png icon on macOS/Linux, and .ico format on Windows\n    icon: os.platform() === 'win32' ? './logo_s.ico' : './logo_s.png',\n    // a template icon is a transparency mask that will appear to be dark in light mode and light in dark mode\n    isTemplateIcon: os.platform() === 'darwin',\n    title: '标题',\n    tooltip: 'Tips',\n    items: [\n      item1,\n      SysTray.separator, // SysTray.separator is equivalent to a MenuItem with \"title\" equals \"\u003cSEPARATOR\u003e\"\n      item2,\n      itemExit\n    ]\n  },\n  debug: false,\n  copyDir: false // copy go tray binary to an outside directory, useful for packing tool like pkg.\n})\n\n// The actual handling of the click events.\n// This is obviously important if you want your MenuItems to react to mouse clicks.\nsystray.onClick(action =\u003e {\n  if (action.item.click != null) {\n    action.item.click()\n  }\n})\n\n// Systray.ready is a promise which resolves when the tray is ready.\nsystray.ready().then(() =\u003e {\n  console.log('systray started!')\n}).catch(err =\u003e {\n  console.log('systray failed to start: ' + err.message)\n})\n\n```\n\nTo integrate with packing tools like `webpack`, use something like `copy-webpack-plugin` to copy the desired `tray_*_release[.exe]` to the `traybin/` folder of the working directory.\n\n## Known Issues\n\nToggling `hiding` on a menu item with a sub-menu causes the sub-menu to disappear.\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelixhao28%2Fnode-systray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffelixhao28%2Fnode-systray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelixhao28%2Fnode-systray/lists"}