<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Duncan McClean</title>
    <description>The latest articles on DEV Community by Duncan McClean (@duncanmcclean).</description>
    <link>https://dev.to/duncanmcclean</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F152411%2F3e3e5f0e-2270-4b46-97e7-e369833c47cc.jpg</url>
      <title>DEV Community: Duncan McClean</title>
      <link>https://dev.to/duncanmcclean</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/duncanmcclean"/>
    <language>en</language>
    <item>
      <title>Setting up for Statamic addon development</title>
      <dc:creator>Duncan McClean</dc:creator>
      <pubDate>Sun, 19 Jan 2020 17:55:56 +0000</pubDate>
      <link>https://dev.to/duncanmcclean/setting-up-for-statamic-addon-development-19ha</link>
      <guid>https://dev.to/duncanmcclean/setting-up-for-statamic-addon-development-19ha</guid>
      <description>&lt;p&gt;The Statamic 3 beta has been out since the middle of November if I can remember correctly. V3 basically turns it into a package for Laravel rather than a pre-built Laravel app. This is the change which allows for Statamic add ons to finally become Laravel packages.&lt;/p&gt;

&lt;p&gt;I’m gonna quickly give you a walk through of how you get started building an addon, including setting up the environment.&lt;/p&gt;

&lt;p&gt;I’m going on the assumption that you already have v3 installed on your site. If not its only [a composer command away](&lt;a href="https://statamic.dev/installation" rel="nofollow"&gt;Installation // Statamic 3 Docs&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Anyways, firstly you want to create the folder structure of where you want your addon to live.&lt;/p&gt;

&lt;p&gt;So for example - if you wanted to create an addon called &lt;code&gt;GithubGists&lt;/code&gt; and your Github username was &lt;code&gt;damcclean&lt;/code&gt;, then your folder structure could look like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;addons/
    damcclean/
        GithubGists/
            src/
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Obviously you can create the folder structure in whatever way you want but this is the recommended way to do it, from what I can gather.&lt;/p&gt;

&lt;p&gt;In your terminal, navigate to inside of your &lt;code&gt;GithubGists&lt;/code&gt; folder (or whatever you called it) and run &lt;code&gt;composer init&lt;/code&gt;. It’ll lead you through a wizard. When it asks you for a package type, type in &lt;code&gt;statamic-addon&lt;/code&gt;. This will let Statamic know that your package will be a Statamic addon.&lt;/p&gt;

&lt;p&gt;Then you can open up the &lt;code&gt;composer.json&lt;/code&gt; file and make a few changes.&lt;/p&gt;

&lt;p&gt;You’ll want to add in this snippet. It’ll let composer know where to load in your namespace from. In my code, I’m loading in the &lt;code&gt;Damcclean\GithubGists&lt;/code&gt; namespace from my &lt;code&gt;src&lt;/code&gt; folder.&lt;/p&gt;

&lt;pre&gt;&lt;span&gt;&lt;span&gt;"&lt;/span&gt;autoload&lt;span&gt;"&lt;/span&gt;&lt;/span&gt;: {
        &lt;span&gt;&lt;span&gt;"&lt;/span&gt;psr-4&lt;span&gt;"&lt;/span&gt;&lt;/span&gt;: {
            &lt;span&gt;&lt;span&gt;"&lt;/span&gt;Damcclean&lt;span&gt;\\&lt;/span&gt;GithubGists&lt;span&gt;\\&lt;/span&gt;&lt;span&gt;"&lt;/span&gt;&lt;/span&gt;: &lt;span&gt;&lt;span&gt;"&lt;/span&gt;src&lt;span&gt;"&lt;/span&gt;&lt;/span&gt;
        }
},&lt;/pre&gt;

&lt;p&gt;This next bit of code does two things. It lets Statamic know the name and description of the addon, so it can display it inside the Control Panel. And then the second bit talks to Laravel to tell where the Service Provider is, we’ll get round to actually creating this in a bit.&lt;/p&gt;

&lt;pre&gt;&lt;span&gt;&lt;span&gt;"&lt;/span&gt;extra&lt;span&gt;"&lt;/span&gt;&lt;/span&gt;: {
        &lt;span&gt;&lt;span&gt;"&lt;/span&gt;statamic&lt;span&gt;"&lt;/span&gt;&lt;/span&gt;: {
            &lt;span&gt;&lt;span&gt;"&lt;/span&gt;name&lt;span&gt;"&lt;/span&gt;&lt;/span&gt;: &lt;span&gt;&lt;span&gt;"&lt;/span&gt;Github Gists&lt;span&gt;"&lt;/span&gt;&lt;/span&gt;,
            &lt;span&gt;&lt;span&gt;"&lt;/span&gt;description&lt;span&gt;"&lt;/span&gt;&lt;/span&gt;: &lt;span&gt;&lt;span&gt;"&lt;/span&gt;Awesome addon to display Github gists on your website.&lt;span&gt;"&lt;/span&gt;&lt;/span&gt;
        },
        &lt;span&gt;&lt;span&gt;"&lt;/span&gt;laravel&lt;span&gt;"&lt;/span&gt;&lt;/span&gt;: {
            &lt;span&gt;&lt;span&gt;"&lt;/span&gt;providers&lt;span&gt;"&lt;/span&gt;&lt;/span&gt;: [
                &lt;span&gt;&lt;span&gt;"&lt;/span&gt;Damcclean&lt;span&gt;\\&lt;/span&gt;GithubGists&lt;span&gt;\\&lt;/span&gt;ServiceProvider&lt;span&gt;"&lt;/span&gt;&lt;/span&gt;
            ]
        }
},&lt;/pre&gt;

&lt;p&gt;I think that’s pretty much it for &lt;code&gt;composer.json&lt;/code&gt;. Next we can create our service provider.&lt;/p&gt;

&lt;p&gt;I’d recommend just calling it &lt;code&gt;ServiceProvider&lt;/code&gt; and putting it in the &lt;code&gt;src&lt;/code&gt; directory. That’s the way most people do it.&lt;/p&gt;

&lt;p&gt;For those of you who are new to the concept of service providers, it’s basically a class that Laravel goes to where you call everything you need to make your addon work.&lt;/p&gt;

&lt;p&gt;So your routes would be registered in your service provider, so would your widgets, your tags etc.&lt;/p&gt;

&lt;p&gt;In your service provider, you need to extend the &lt;code&gt;AddonServiceProvider&lt;/code&gt; class and have two methods, &lt;code&gt;boot&lt;/code&gt; and &lt;code&gt;register&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;span&gt;&amp;lt;?php&lt;/span&gt;&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;namespace&lt;/span&gt; &lt;span&gt;Damcclean\GithubGists&lt;/span&gt;;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;use&lt;/span&gt; &lt;span&gt;Statamic\Providers\AddonServiceProvider&lt;/span&gt;;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;class&lt;/span&gt; &lt;span&gt;ServiceProvider&lt;/span&gt; &lt;span&gt;extends&lt;/span&gt; &lt;span&gt;AddonServiceProvider&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;{&lt;/span&gt;
&lt;span&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;function&lt;/span&gt; &lt;span&gt;boot&lt;/span&gt;()&lt;/span&gt;
&lt;span&gt;    {&lt;/span&gt;
&lt;span&gt;        &lt;span&gt;parent&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;boot();&lt;/span&gt;
&lt;span&gt;    }&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;function&lt;/span&gt; &lt;span&gt;register&lt;/span&gt;()&lt;/span&gt;
&lt;span&gt;    {&lt;/span&gt;
&lt;span&gt;        &lt;span&gt;parent&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;register();&lt;/span&gt;
&lt;span&gt;    }&lt;/span&gt;
&lt;span&gt;}&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Now we’re almost done!! The next thing is to actually install our addon in our Statamic site.&lt;/p&gt;

&lt;p&gt;So for that, in your main &lt;code&gt;composer.json&lt;/code&gt;, add in the name of your package to the &lt;code&gt;require&lt;/code&gt; section. Also, just add &lt;code&gt;dev-master&lt;/code&gt; as the version.&lt;/p&gt;

&lt;pre&gt;&lt;span&gt;&lt;span&gt;"&lt;/span&gt;require&lt;span&gt;"&lt;/span&gt;&lt;/span&gt;: {
    &lt;span&gt;&lt;span&gt;"&lt;/span&gt;damcclean/github-gists&lt;span&gt;"&lt;/span&gt;&lt;/span&gt;: &lt;span&gt;&lt;span&gt;"&lt;/span&gt;dev-master&lt;span&gt;"&lt;/span&gt;&lt;/span&gt;
},&lt;/pre&gt;

&lt;p&gt;Just so it knows where your project lives, as its not live on Composer, you’ll need to add it as a repository which is pretty easy, just add this code to the bottom of the same file. Obviously changing out the folder names etc for the ones you have setup.&lt;/p&gt;

&lt;pre&gt;&lt;span&gt;&lt;span&gt;"&lt;/span&gt;repositories&lt;span&gt;"&lt;/span&gt;&lt;/span&gt;: [
        {
            &lt;span&gt;&lt;span&gt;"&lt;/span&gt;type&lt;span&gt;"&lt;/span&gt;&lt;/span&gt;: &lt;span&gt;&lt;span&gt;"&lt;/span&gt;path&lt;span&gt;"&lt;/span&gt;&lt;/span&gt;,
            &lt;span&gt;&lt;span&gt;"&lt;/span&gt;url&lt;span&gt;"&lt;/span&gt;&lt;/span&gt;: &lt;span&gt;&lt;span&gt;"&lt;/span&gt;addons/damcclean/GithubGists&lt;span&gt;"&lt;/span&gt;&lt;/span&gt;
        }
]&lt;/pre&gt;

&lt;p&gt;After that, just run &lt;code&gt;composer install&lt;/code&gt; in your project’s root directory and you’ll be as good as gold.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Force Remove Service Worker from Chrome</title>
      <dc:creator>Duncan McClean</dc:creator>
      <pubDate>Wed, 06 Nov 2019 23:44:27 +0000</pubDate>
      <link>https://dev.to/duncanmcclean/how-to-force-remove-service-worker-from-chrome-1n2f</link>
      <guid>https://dev.to/duncanmcclean/how-to-force-remove-service-worker-from-chrome-1n2f</guid>
      <description>&lt;p&gt;So I recently created a service worker for one of my apps so I could turn it into a Progressive Web App.&lt;/p&gt;

&lt;p&gt;Although, for some reason I was under the impression that I should cache the &lt;strong&gt;main&lt;/strong&gt; page of my app. I later realised that it was a very bad idea.&lt;/p&gt;

&lt;p&gt;I think I'm the only user of the site that came across this issue before I patched it but I found it quite a pain to unregister the service worker and bust it's cache so I could get the latest version of the page from the server.&lt;/p&gt;

&lt;p&gt;I had to do this process on both my MacBook and on my Android phone, so here's both of those processes:&lt;/p&gt;

&lt;h2&gt;
&lt;span&gt;&lt;/span&gt;Chrome on the MacBook&lt;/h2&gt;

&lt;p&gt;The first thing to do is to open up Developer Tools and head to the 'Application' tab. In there it has its own little sidebar. Go to the 'Service worker' part of that. There it should give you the option of 'Unregistering' your service worker. Click on that link and also go and clear the whole site's cache because why not.&lt;/p&gt;

&lt;h2&gt;
&lt;span&gt;&lt;/span&gt;Chrome on the Android phone&lt;/h2&gt;

&lt;p&gt;The first thing to do is to go to the site, tap on the site's security padlock (or warning sign ⚠️) and tap on 'Site settings'. Then tap on 'Clear &amp;amp; reset'. Then just refresh the page and you should be good to go!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
