{"id":347,"date":"2020-02-07T21:04:36","date_gmt":"2020-02-07T21:04:36","guid":{"rendered":"http:\/\/mohammedlakkadshaw.com\/blog\/?p=347"},"modified":"2020-02-07T21:04:36","modified_gmt":"2020-02-07T21:04:36","slug":"how-to-auto-start-electron-applications-on-startup","status":"publish","type":"post","link":"https:\/\/mohammedlakkadshaw.com\/blog\/how-to-auto-start-electron-applications-on-startup.html","title":{"rendered":"How to auto-start electron applications on startup"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I was developing an electron application that required to auto-start when the computer is booted and started up and it had to be cross-platform and automatic. So when the computer starts the program should run and there should be no setup required, once the user launches the application it should auto-start upon login.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To solve this problem I tried various methods and none of them worked reliably until I came across a very useful library by name of <a href=\"https:\/\/www.npmjs.com\/package\/auto-launch\">&#8220;auto-launch&#8221;<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To install the application run :<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>npm install auto-launch<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To configure it, edit the <code>main.js<\/code> file of your electron application and add the following code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var AutoLaunch = require('auto-launch');\nvar autoLauncher = new AutoLaunch({\n    name: \"MyApp\"\n});\n\/\/ Checking if autoLaunch is enabled, if not then enabling it.\nautoLauncher.isEnabled().then(function(isEnabled) {\n  if (isEnabled) return;\n   autoLauncher.enable();\n}).catch(function (err) {\n  throw err;\n});\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>name<\/code> parameter is optional and you can put any name in there but I recommend specifying the name parameter because if not specified AutoLaunch does not work correctly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Auto-Launch also provide other configuration options, you can check out the full documentation at it&#8217;s Github page <a href=\"https:\/\/github.com\/Teamwork\/node-auto-launch\">https:\/\/github.com\/Teamwork\/node-auto-launch<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s it! Let me know if you have any questions in the comment section.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was developing an electron application that required to auto-start when the computer is booted and started up and it had to be cross-platform and automatic. So when the computer starts the program should run and there should be no setup required, once the user launches the application it should auto-start upon login. To solve [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-347","post","type-post","status-publish","format-standard","hentry","category-nodejs"],"_links":{"self":[{"href":"https:\/\/mohammedlakkadshaw.com\/blog\/wp-json\/wp\/v2\/posts\/347","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mohammedlakkadshaw.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohammedlakkadshaw.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohammedlakkadshaw.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohammedlakkadshaw.com\/blog\/wp-json\/wp\/v2\/comments?post=347"}],"version-history":[{"count":0,"href":"https:\/\/mohammedlakkadshaw.com\/blog\/wp-json\/wp\/v2\/posts\/347\/revisions"}],"wp:attachment":[{"href":"https:\/\/mohammedlakkadshaw.com\/blog\/wp-json\/wp\/v2\/media?parent=347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohammedlakkadshaw.com\/blog\/wp-json\/wp\/v2\/categories?post=347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohammedlakkadshaw.com\/blog\/wp-json\/wp\/v2\/tags?post=347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}