Code Monkey home page Code Monkey logo

electron-promote-windows-tray-items's Introduction

electron-promote-windows-tray-items

When you first create an Electron tray item on Windows, it will show up in the toolbar customization area:

customization area

rather than in the toolbar itself:

toolbar

By default, the user must explicitly choose to show icons in the toolbar. But not only does this create extra, potentially non-intuitive work for the user, it forces the design of icons that will look good in both the toolbar and the customization area since you can't choose different icons for each location.

This package helps you skip this process. For any item in its default state, i.e. the user has not explicitly hid the item from the toolbar, this package will "promote" that item from the customization area to the toolbar.

Requirements

This package may be safely required on non-Windows platforms, though the package will return an error if it is attempted to be used on non-Windows platforms.

This project is currently compatible with Electron 0.36.2 due to its dependence on electron-edge.

Installation

For Electron:

npm install electron-promote-windows-tray-items

or

npm install electron-promote-windows-tray-items --save

Usage

var promoteWindowsTrayItems = require('electron-promote-windows-tray-items');

// Create a tray item.
var icon = new Tray(/* ... */);

if (process.platform === 'win32') {
  // Icon will now be in the toolbar customization area without the user explicitly toggling it to show in the toolbar.

  promoteWindowsTrayItems(function(err) {
    // Icon will now be in the toolbar itself unless the user explicitly hid it from the toolbar.
  });
}

Contributing

We welcome pull requests! Please lint your code.

Credits

Created by Jeff Wear, with the core C# logic used by this module originally developed by Paul Betts.

Copyright and License

Copyright 2016 Mixmax, Inc., licensed under the MIT License.

Some portions derived from Squirrel.Windows, copyright 2012-2016 GitHub, Inc., licensed under the MIT License.

Release History

  • 1.0.1 README fixes
  • 1.0.0 Initial release.

electron-promote-windows-tray-items's People

Contributors

bradvogel avatar megantinleywilson avatar skeggse avatar spencer-brown avatar wearhere avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

tex0l tmpethick

electron-promote-windows-tray-items's Issues

Causes Windows 7 app to terminate silently

This seems to work well on Windows 8 and 10, but if I run it on a Windows 7 machine, my app seems to quit silently - no error message. I can avoid this with the following code:

const os = require('os')

function isWin8orAbove(release) {
  if (process.platform !== 'win32') return false

  // parse the release string to get major and minor version numbers.
  // win7 is 6.1; win8 is 6.2; win 10 is 10.0
  const parsedRelease = /([0-9]+).([0-9]+)/.exec(release)
  // if parsing fails for some reason, default to doing nothing
  if (!parsedRelease) return false
  const majorRelease = parseInt(parsedRelease[1])
  const minorRelease = parseInt(parsedRelease[2])

  if (majorRelease === 6 && minorRelease >= 2) return true
  return majorRelease >= 7
}

if (isWin8orAbove(os.release)) {
  // Make the tray icon visible by default
  promoteWindowsTrayItems()
}

This code assumes we should exclude all versions of windows lower than win7 (rel 6.1) and include all newer versions, but I haven't tested anything below win7.

If the win7 problem is replicating for others as well, I could submit a PR for this.

Sometimes System.AccessViolationException on Windows 10

Observed for multiple users under Windows 10:

Application: mixmax.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
  at Squirrel.ITrayNotify.SetPreference(Squirrel.NOTIFYITEM_Writable ByRef)
  at Squirrel.TrayStateChanger.PromoteTrayItems(System.String)
  at Startup+<Invoke>d__0.MoveNext()
  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Start[[Startup+<Invoke>d__0, tgfmyvbn, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]](<Invoke>d__0 ByRef)
  at Startup.Invoke(System.String)

Exception Info: System.Reflection.TargetInvocationException
  at System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean)
  at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object, System.Object[], System.Object[])
  at System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
  at EdgeCompiler+<>c__DisplayClass1.<CompileFunc>b__0(System.Object)
  at ClrFunc.Call(v8.Local<v8::Value>, v8.Local<v8::Value>, v8.Local<v8::Value>)
  at <Module>.clrFuncProxy(Nan.FunctionCallbackInfo<v8::Value>)
  at <Module>.Nan.imp.?A0x09be68f5.FunctionCallbackWrapper(v8.FunctionCallbackInfo<v8::Value>*)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.