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

icon doesnt load inside pkg #6

Closed
si458 opened this issue Aug 22, 2021 · 3 comments
Closed

icon doesnt load inside pkg #6

si458 opened this issue Aug 22, 2021 · 3 comments

Comments

@si458
Copy link

si458 commented Aug 22, 2021

i have tried a basic app to show a tray icon when built with pkg, but i cant get it to work?
i have verified the icon is included with the bundle so im not sure whats going on?

PS C:\Users\Simon\Documents\crap> .\testapp.exe
------------------------------- virtual file system
C:\snapshot
  testapp-pkg                               776563
    index.js                                   610
    icon.ico                                370070
    node_modules                            776563
      delay                                   6907
        package.json                          1961
        index.js                              1761
        index.d.ts                            3185
      not-the-systray                       400475
        package.json                          1901
        index.js                              3943
        index.d.ts                            9868
        notify_icon.node                    377856
      @types                                405883
        node                                  5408
          package.json                        5408
Total size =  776563
C:\snapshot\testapp-pkg\icon.ico
C:\snapshot\testapp-pkg\node_modules\not-the-systray\index.js:33
                    return Icon.loadFile(pathOrId, size);
                                ^
Error [Win32Error]: The system cannot find the file specified.
    at Function.Icon_load [as load] (C:\snapshot\testapp-pkg\node_modules\not-the-systray\index.js:33:33)
    at Object.<anonymous> (C:\snapshot\testapp-pkg\index.js)
    at Module._compile (pkg/prelude/bootstrap.js:1751:22)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at Function.runMain (pkg/prelude/bootstrap.js:1804:12)
    at internal/main/run_main_module.js:17:47 {
  syscall: 'LoadImageW',
  errno: 2
}
const delay = require("delay");
const path = require("path");
const { NotifyIcon, Icon, Menu } = require("not-the-systray");
const theicon = path.join(__dirname,"icon.ico");
console.log(theicon);
const appIcon = new NotifyIcon({
    icon: Icon.load(theicon, Icon.small), // Notify icons should use 
    tooltip: "testApp",
});
(async () => {
    console.log('Hello World');
    await delay(10000);
    console.log("Goodbye World");
    process.exit(0);
})();
@si458
Copy link
Author

si458 commented Aug 22, 2021

the only way around this i have found is to NOT include the icon in the bundle and include it next to my built exe
and change the path to use the raw folder instead const theicon = path.join(process.cwd(),"icon.ico");

@simonbuchan
Copy link
Owner

Yeah, this isn't really easily possible, see #4. That used another option, embedding the icon in your output executable.

@si458
Copy link
Author

si458 commented Aug 23, 2021

@simonbuchan i also found another way around too which might be helpful

  1. bundle icon
  2. when you first run, create temp folder and copy icon to that temp folder
  3. load systray with the temp icon
const theicon = path.join(__dirname, "icon.ico");
const tempfolder = fs.mkdtempSync(`${os.tmpdir()}${path.sep}`);
const tempicon = path.join(tempfolder, "icon.ico");
if (!fs.existsSync(tempicon)) {
    const sourceData = fs.readFileSync(theicon);
    fs.writeFileSync(tempicon, sourceData);
}
const myicon = Icon.load(tempicon, Icon.small);

EDIT: copyFile doesnt work so you have to read/write file instead - vercel/pkg#420

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

2 participants