mockingbot / electron-color-picker

Pick color from Desktop, suitable for use with Electron.
MIT License
23 stars 5 forks source link

Use without ES6 #1

Closed swampthang closed 5 years ago

swampthang commented 6 years ago

When I stumbled upon this I was some kind of excited to think this is now possible so thanks for putting this up!

I'm not using react - just electron with nodejs, ie, const module = require('module');

In renderer I tried:

const electron = require('electron');
const clipboard = electron.clipboard;
const colorHexRGB = require('electron-color-picker');
const getColorHexRGB = colorHexRGB.getColorHexRGB;

A button click listener calls...

const getColor = async () => {
  const color = await getColorHexRGB;
  color && clipboard.writeText(color);
}

Can you give a little more info on how this is supposed to be used in this environment? Would be greatly appreciated.

I see the following error on click:

Uncaught (in promise) TypeError: Error processing argument at index 0, conversion failure from async()=>{const{possibleColorString:r}=await o() const[t]=e.exec(r.toUpperCase())||[] if(!t)throw new Error(`[e......t} at getColor()

ThatBean commented 6 years ago

First React is not required for by package... It's not in the package.json or README.md, where do you get that?


There may be multiple places need checking to make this work:

import { clipboard } from 'electron'
import { getColorHexRGB } from 'electron-color-picker'

const getColor = async () => {
  const color = await getColorHexRGB() // note the function call
  color && clipboard.writeText(color)
}
swampthang commented 5 years ago

Thanks for the reply and sorry for the delay in replying back. I don't remember seeing a notification that you replied.

First of all, I'm an idiot. I didn't mean react - I meant es6 - not able to use import. I may not be able to upgrade to the latest version of Electron because a few of the packages I'm using may not play together nicely. I'll give it a try. In the meantime, if you have any suggestions about how this can be done without having to use import I would greatly appreciate it.

ThatBean commented 5 years ago

The import syntax is actually not required to this package. Though the source code do have the import syntax, the published version of the package is babel compiled.

You can check the installed package under node_modules, or just download one with npm pack electron-color-picker.

Also you can check the newly added electron-color-picker#example for a basic setup.

ThatBean commented 5 years ago

An example of the release process of Electron app with this package is now add, after #2 .

A short description is added to #about-release-packaging. And a more complete dev & packing process has been added to example/, be sure to run & test that following #example.