Appearance
Introducing the "Package" Feature in Brainwrite Swift: A Step-by-Step Guide
Hello everyone! Hope you're all safe and healthy wherever you are. Today, I’m excited to introduce you to a fantastic new feature in Brainwrite Swift called "Package." This tool is designed to make developing routines easier and more efficient.
What is a Package?
In Brainwrite Swift, a Package is essentially a group of blocks that perform a specific task within a routine. Think of it as a reusable component that can be integrated into various routines to achieve a common goal. This modular approach simplifies routine creation and promotes reuse.
Creating Your First Package with SweetAlert2
Let's walk through creating a Package using the SweetAlert2 library, which enhances JavaScript alerts with beautiful, customizable alerts.
Access the Packages Menu: Go to the Brainwrite Swift dashboard and click on the "Packages" menu. Create a new package named "SweetAlert2."
Build the Package:
- Add an "Active Tab" block.
- Insert a "JavaScript Code" block.
- Check the "Execute every new tab" option.
- Add a preload script by copying the SweetAlert script from the SweetAlert2 website's installation guide and pasting it with the HTTPS protocol.
Code the Alert:
- Fill the JavaScript Code block with an example from SweetAlert2’s usage section.
- Ensure you leave the
bwswiftNextBlock
function at the end of your JavaScript code.
Save and Describe:
- Save the package.
- Add a description in the "Details" section.
- In "Settings," check "Set package as block" and define the block inputs and outputs.
- Set the "Active Tab" as a block input and the JavaScript Code as a block output. Name these inputs and outputs as "start" and "finish" respectively.
- Save your changes.
Using the Package in a Routine
Now that your SweetAlert2 package is ready, let’s integrate it into a routine.
Create a Routine: From the "Routines" menu, create a new routine named "Test SweetAlert2."
Add the Package:
- Open the routine and click "Open packages."
- Drag and drop the SweetAlert2 package.
- Connect it to a "Trigger" block.
Test the Routine:
- Save the routine.
- Visit any web page, for example, the Brainwrite Swift homepage.
- Run the routine using the Brainwrite Swift extension. You should see the SweetAlert2 alert in action.
Updating the Package
Let’s make the SweetAlert2 package more dynamic by pulling data from Brainwrite Swift variables.
Modify JavaScript Code:
- Update the title and text properties in the JavaScript Code block to fetch data using
bwswiftRefData('variables', 'title')
andbwswiftRefData('variables', 'text')
.
- Update the title and text properties in the JavaScript Code block to fetch data using
Adjust the Routine:
- Save the updated package.
- Refresh your routine and add an "Insert Data" block.
- Create variables for the title ("Whooops") and text ("Data not found").
- Connect these blocks appropriately.
- Save and run the routine to see the updated alert with dynamic data.
Using Shared Packages from the Brainwrite Swift Marketplace
You can also use packages shared by the community from the Brainwrite Swift Marketplace.
Add a Marketplace Package:
- Visit the Brainwrite Swift Marketplace, find the "Send with Gmail" package, and click "Add package."
- The package will appear in your Brainwrite Swift dashboard.
Create a Routine with the New Package:
- Create a routine named "Test Gmail."
- Drag and drop the Gmail package and connect it with a "Trigger" block.
- Add an "Insert Data" block with variables for emailAccount, emailTo, subject, and emailBody.
Run the Routine:
- Save and execute the routine.
- Check your email inbox to confirm the message was sent successfully.
Sharing Your Package with the Community
Finally, share your SweetAlert2 package with others.
Describe and Share:
- Add a description, for example, "A beautiful alert for your routines."
- Provide a longer description, such as "It uses the SweetAlert2 library."
- Save and share the package.
Get the URL:
- Obtain the shareable URL and open it to verify the package is available for others to install.
If you have any questions or seek further insights into Brainwrite Swift's capabilities, we encourage you to join our Discord server and share your thoughts. We're here to help you unlock the full potential of automation with Brainwrite Swift.