Code Monkey home page Code Monkey logo

watson's Introduction

Watson

“It’s elementary, my dear…”

A best-practices application template for elementary OS 6 (Odin).

Looping GIF of a snippet of Aral Balkan’s video introducing Watson.

Watch the introductory screencast.

Status: Beta.

I’ve now backported everything I learned and created while making Comet into Watson.

Once Comet is on the AppCenter and I’m happy that Watson captures and supports the full elementary OS development cycle, I’ll remove the Beta status.

Want the wallpaper?

What Watson is (and what Watson is not).

Watson gets you up and running quickly with a bare-bones single-window elementary OS 6 (Odin) app that is based on the elementary OS Developer Documentation as well as a review of the conventions employed by the core apps that ship with elementary OS (like Code and Calculator).

It also makes it equally easy for other developers to build and run your application on their own machines after they clone your project’s repository.

Watson includes a number of scripts – to create and run Flatpak packages, update translations, and even take screenshots of your app and preview your app in AppCenter – that make the everyday tasks of working with your application easier.

Finally, Watson includes a simple web site for your app that’s automatically generated from your app’s metadata and contains a basic, progressively-enhanced and accessible carousel of your screenshots as well as a Flatpak repository for your app where people can sideload your app from. To host the generated site, you simply have to turn on GitHub Pages for your app and use the provided publish task script to publish your app and push to your GitHub repository. (You can also host your site on any static host, e.g., using Site.js. If you decide to put your app on the elementary OS AppCenter you can also uncomment a “Get It On AppCenter” button that will open AppCenter at your app’s page. To see an example how you can build on and customise this base site, see the web site for Comet.

When deciding what to include and what to leave out of the generated app, the guiding principle is to include base functionality expected of any elementary OS 6 app. The goal is for you to only have to add to the generated template, not remove from it or change the generated code for common types of apps (with the understanding that multi-window applications and highly custom apps might require a bit of fiddling).

Most importantly, the generated skeletal app complies with the elementary OS Human Interface Guidelines and follows other recommended elementary OS 6 conventions like coding style. If you haven’t already done so, please read through both of those important resources before continuing. Also, to refer to language or library details during development, bookmark Valadoc.

Once you’ve made the generated app your own by customising it and adding to it, you can submit it for inclusion in the elementary OS AppCenter as a curated app.

Watson is not a substitute for knowing what you’re doing. Watson is meant to lower the barrier of entry to creating an elementary OS application by automating the start of a new project to ensure you do not misconfigure your project or leave out important aspects (like window state preservation or translations). So, again, please read the above documents before starting to develop apps for elementary OS.

Goals

  1. The time from when a developer decides to make an elementary OS app to when they have a working project using Watson should be < 60 seconds.

  2. The time from when a developer clones a Watson-generated elementary OS application to when they have it up and running on their own machine should be < 60 seconds.

Furthermore, the generated project must:

Getting started

On GitHub:

  1. Press the green “Use this template” button for this repository to create your new project’s repository using Watson as the template.

On your development machine:

  1. Clone your project and switch to its directory in Terminal:

    git clone [email protected]:<my-org>/<my-app>.git
    cd <my-app>
  2. Initialise your project:

    ./watson

Note on the GitHub-centric workflow: The elementary OS AppCenter currently ties application bundle IDs and the directory structure for assets, etc., to the GitHub project. So your project’s application bundle ID will be something like com.github.small_tech.comet (the init script will automatically convert dashes to underscores as per flatpak’s naming requirements). I have raised my concerns about this both from a legal perspective as it is a trademark violation and, more generally, because it gives Microsoft a de-facto veto right on what apps are allowed on elementary OS. I do hope that this decision will be reviewed going forward. In the meanwhile, however, Watson is designed to make full use of the current system to make setting up a new elementary OS project as simple as possible while following all relevant platform guidelines and encouraging good practices. – Aral

What to expect

Interactive app configuration screens

Watson will ask for your app details in a series of graphical dialogue windows and update the necessary bits of the template files (application bundle IDs, asset paths, etc.) to customise them for your project based on your answers.

It will also replace this README and the CHANGELOG with your application’s versions, recreate the git repository (so you start with a fresh history), make an initial commit, and set up your git remote so origin points to your repository.

Next, Watson will run the install task (task/install).

The install task is also what developers who clone your project will run to ensure that they can build and run your project.

The install task

The install task first checks whether you have the elementary OS development libraries installed and asks you to install them if it can’t find them.

The elementary OS development libraries – also known as the elementary OS Software Development Kit (SDK) – are a metapackage of elementary OS libraries required when creating apps for elementary OS. You can see which libraries are included in the SDK based on the architecture of your development machine by reviewing the following metapackage definitions: AMD64, ARM64, ARMHF.

Next, Watson will check if you have VSCodium installed. If you do, it will check whether or not you have useful set of VSCodium extensions for elementary OS development installed and ask you to install them if you don’t.

You do not need to use VSCodium to create elementary OS apps. You can, for instance, use elementary OS Code, which comes preinstalled, or a different third-party editor like Builder. However, if you do have VSCodium installed, there are a number of extensions that will make creating your elementary OS app easier (Vala, Meson, CodeLLDB, XML, YAML). If Watson cannot find these extensions installed, it will ask you if you’d like to install them now. With these extensions installed, once you’ve initialised your project, you can simple open it in VSCodium and hit F5 to run/debug it and Ctrl + Shift + BBuild all targets to rebuild it after making changes. You will also get code intelligence, etc., for all your source files. Finally, your project will also inform VSCodium of the set of recommended extensions for your project so even if you choose not to install them now, you can easily find and install them later yourself.

Post install

Once the install task is done, Watson will delete itself, leaving only your project behind.

It will also commit and push the changes to your git repository.

And that’s it!

At this point, your project is ready and you can customise the template further to create your own unique and wonderful app, knowing you have a base that adheres to elementary OS guidelines.

You can also run your project using the run script:

task/run

Or, if you’re using VSCodium, just open your project and hit F5 to run/debug it and Ctrl + Shift + BBuild all targets to rebuild it after making changes.

You can find more task scripts in the task folder of your project and the workflow is also documented in the README file that’s generated for your project.

Here’s hoping Watson will make it easier for you to start building and maintaining excellent apps for elementary OS.

What’s included?

What’s not included?

Watson creates a basic single-window elementary OS application using good practices.

Watson’s goal with the generated app is that you should only have to either customise existing functionality (e.g., replace the app logo SVGs with your own), use existing functionality (e.g., add your custom icons or your own translations), or add specialised logic to the generated app. So you shouldn’t have to remove any of the generated functionality. This is why there are no sample widgets or even basic layout generated as that will differ from app to app.

The generated skeleton is just that, the structure you need to quickly get you started with building your own application.

In other words, Watson does not generate a sample app. For widget demos of the underlying libraries, see the Granite demo (sudo apt install granite-demo && granite-demo) and Gtk+ 3 examples/demo (sudo apt install gtk-3-examples && gtk3-demo).

Watson is also not meant to teach you how to build an elementary OS app (see the elementary OS Developer Documentation) and is not a substitute for knowing and applying the elementary OS Human Interface Guidelines as you develop your app.

Finally, while Watson will install the elementary OS development tools and even the recommended VSCodium extensions for you if you ask it to, you need to configure your GitHub account and set up git on your machine yourself. For instructions on how to do this, please see the Basic Setup section of the elementary OS Developer Documentation.

Common functionality you might want to add to your app

Here are some quick links showing you how to add common functionality to your app after you’ve generated it:

General resources

At the risk of sounding like a broken record, please work your way through the elementary OS Developer Documentation) and elementary OS Human Interface Guidelines before starting to create an app for elementary OS 6.

Also please review the AppCenter publishing requirements before you submit your app.

Other important references include:

Similar projects

Get the wallpaper

Illustration, Sherlock Holmes, Watson, Enola Holmes and the three cats from Catts are in a swamp full of alligators. Sherlock is standing on a makeshift wooden bridge examining a bird (one foot on an alligator’s nose). Watson is in the swamp gathering more wood for the bridge. Enola and the blue cat are in a row boat in the background. The purple and green cats are on branches.

The wallpaper you see in the screencast was commissioned for Watson from the singular Margo de Weerdt. And you’re welcome to download and use it in all its 4K glory on your own computer if you like.

(Also available with shallower depth of field – and even shallower depth of field – which you might prefer if you place icons on your desktop so they don’t get lost in the detail.)

Released under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Please credit Margo de Weerdt and Watson by Small Technology Foundation.

Like this? Fund us!

Small Technology Foundation is a tiny, independent not-for-profit.

We exist in part thanks to patronage by people like you. If you share our vision and want to support our work, please become a patron or donate to us today and help us continue to exist.

Copyright

© 2021-present Aral Balkan, Small Technology Foundation.

License

GPL version 3.0

watson's People

Contributors

antolius avatar aral avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

watson's Issues

Initialise localisation

This is something that’s missing from the elementary starter project also.

Add localisation initialisation code to Application initialiser:

GLib.Intl.setlocale (LocaleCategory.ALL, "");
GLib.Intl.bindtextdomain (Constants.GETTEXT_PACKAGE, Constants.LOCALEDIR);
GLib.Intl.bind_textdomain_codeset (Constants.GETTEXT_PACKAGE, "UTF-8");
GLib.Intl.textdomain (Constants.GETTEXT_PACKAGE);

And add the LOCALEDIR constant to the meson.build

conf_data = configuration_data()
conf_data.set_quoted('PROJECT_NAME', meson.project_name())
conf_data.set_quoted('GETTEXT_PACKAGE', meson.project_name())
conf_data.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir')))
conf_data.set_quoted('VERSION', meson.project_version())
config_header = configure_file(
    input : 'src' / 'config.vala.in',
    output : 'config.vala',
    configuration : conf_data
)

And add it to config.vala.in:

namespace Constants {
    public const string GETTEXT_PACKAGE = @GETTEXT_PACKAGE@;
    public const string PROJECT_NAME = @PROJECT_NAME@;
    public const string VERSION = @VERSION@;
    public const string LOCALEDIR = @LOCALEDIR@;
}

Move colour scheme setup to Application class’s activate method

The colour scheme setup is currently in the MainWindow class.

This is fine unless you want to, for example, parse command-line arguments, do some processing based on them (e.g., load a file) and display, say, an error dialogue. At which point you must duplicate the code to have the dialogue match the person’s colour scheme preference.

Instead, by moving it to the activate method of the Application class, the settings will be active everywhere in the app.

Implement task/publish to create app website and publish/update flatpak repository to it

Given that Flatpaks can be distributed in a decentralised manner, in the spirit of the Small Web, we should make this as easy to do as possible.

Proposed implementation

task/publish

Running this script:

  1. Creates (or updates) a web site for the app based on the app metadata in the project.
  2. Create (or updates) a flatpak repository for the app and a flatpak.ref and links it to the “Install” button on the site.

The site can then be served with Site.js.

Notes:

  • Site is localised.
  • People who install it also get updates.

Step 8 (Delete self) failed on line 239.

when running watson I get this error

Step 8 (Delete self) failed on line 239.

I was able to continue by looking at the steps in the watson file itself - but this might cause some people some confusion. I'll do some digging see what the issue is, but wanted to raise it here just so you're aware and in case anyone else experiences it.

Add config.vala.in file with constants to template and include the app version in it

In order to access constants (like the app version), core apps like elementary OS Code use a config.vala.in file that’s configured by Meson during the build process.

Implement this for the Watson template.

e.g.,

src/config.vala.in

namespace Constants {
    public const string GETTEXT_PACKAGE = @GETTEXT_PACKAGE@;
    public const string PROJECT_NAME = @PROJECT_NAME@;
    public const string VERSION = @VERSION@;
}

meson.build:

project(
    '',
    'vala',
    'c',
    version: '1.0.0'
)

…

conf_data = configuration_data()
conf_data.set_quoted('PROJECT_NAME', meson.project_name())
conf_data.set_quoted('GETTEXT_PACKAGE', meson.project_name())
conf_data.set_quoted('VERSION', meson.project_version())
config_header = configure_file(
    input : 'src' / 'config.vala.in',
    output : 'config.vala',
    configuration : conf_data
)

Locale?

In the core apps that ship with elementary OS, the Application constructor manually sets the locale and binds to the gettext package e.g. in Calculator:

Intl.setlocale (LocaleCategory.ALL, "");
GLib.Intl.bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
GLib.Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
GLib.Intl.textdomain (GETTEXT_PACKAGE);

The constants used come from the configuration file (Config.vala.in):

public const string GETTEXT_PACKAGE = @GETTEXT_PACKAGE@;
public const string LOCALEDIR = @LOCALEDIR@;

And the actual values are substituted in meson.build:

config_data = configuration_data()
config_data.set_quoted('LOCALEDIR', get_option('prefix') / get_option('localedir'))
config_data.set_quoted('GETTEXT_PACKAGE', meson.project_name())
config_file = configure_file(
    input: 'src/Config.vala.in',
    output: '@BASENAME@',
    configuration: config_data
)

However, none of this is shown in the Translations section of the elementary OS developer documentation.

Can someone with better knowledge of all this than me please answer:

  • What does the above code achieve, exactly? (And is there a link to a resource that explains it?)
  • Is it required for localisation to work?
  • If so, should we open an issue for it to be included in the Translations section of the developer guide?
  • Should a version of it be included in the project generated by Watson?

Thanks!

Update readme with instructions on how to submit an app for review

Unknowns

  • I do not yet know whether the Stripe Connect integration via the old dashboard will work with the new one. It seemed to succeed when I went through the process with the old/current one.
  • I do not know whether the beta of the new one is ready for use yet https://beta.developer.elementary.io/

Meson requires reconfiguration after running a flatpak build

Once task/package has been implemented, ensure that the task/build script runs meson build --prefix=/usr again if necessary as, otherwise, you get the following error if you run task/build after task/package:

~/Projects/elementary/comet/build ~/Projects/elementary/comet
ninja: error: loading 'build.ninja': No such file or directory

So check for this in the task/run and task/build scripts and reconfigure meson if you detect that the build.ninja file doesn’t exist. e.g.,

# The ninja build file may be missing if the
# person ran a flatpak build before running this script.
# If so, reconfigure meson.
if [[ ! -f build/build.ninja ]]; then
  meson build --prefix=/usr
fi

Include basic commandline argument handling and handle -v/--version argument and basic --help info

Apps generated with Watson should handle universal command-line options (like --help and -v/--version) properly by default.

This should be implemented in a manner that makes it easy for the developer to add further options should they desire (see the core apps, e.g., Code, for an example of a good, maintainable implementation.)

  • Handle the handle_local_options signal with a custom handler for -v/--version argument
  • Add the project description as the option context summary for use in the --help screen (set_option_context_summary())
  • Add the project copyright notice as the context description to be displayed at the bottom of the --help screen (set_option_context_description())

Two icons show up when a installed and run from flatpak

bug-screenshot

This seems to only happen from flatpak installs. When the flatpak app is run, the app spawns twice, one icon in plank with the app ID and one icon with the app name.

Even after closing the application, the one process with the app name sticks around for a couple of seconds and then closes by itself. Was unfortunately not able to figure out why this happens yet. The screenshot above demos whats going on.

I've created a sample repo for debugging this, its up here: https://github.com/BharatKalluri/double-icon-flatpak-bug

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.