Scratch 3.0 as a self-contained desktop application
Find a file
Christopher Willis-Ford f95ec41f35
Some checks are pending
CI/CD / ci-cd (macos-latest) (push) Waiting to run
CI/CD / ci-cd (windows-latest) (push) Waiting to run
Merge pull request #367 from scratchfoundation/renovate/major-github-artifact-actions
chore(deps): update actions/upload-artifact action to v4
2024-11-06 07:53:24 -08:00
.github chore(deps): update actions/upload-artifact action to v4 2024-11-06 15:30:22 +00:00
buildResources fix: see if we need usb entitlement, exempt encryption 2023-08-15 09:13:09 -04:00
fastlane ci: Pull Matchfile info from secrets 2023-11-30 08:29:08 -05:00
scripts use provisionprofiles from Fastlane Match 2022-01-27 16:44:13 -08:00
src feat: high contrast support 2023-07-28 11:41:06 -04:00
.babelrc test: give babel-eslint a correct browser query 2024-02-21 15:14:58 -08:00
.editorconfig Use eslint-config-scratch 2018-09-27 14:28:23 -07:00
.eslintignore Use eslint-config-scratch 2018-09-27 14:28:23 -07:00
.eslintrc.js Add media library assets, fetch script 2018-10-19 15:19:41 -07:00
.gitattributes move About window styling into a CSS file 2020-10-06 14:34:01 -07:00
.gitignore ci: Pull Matchfile info from secrets 2023-11-30 08:29:08 -05:00
.npmignore Initial commit 2018-09-06 11:20:27 -07:00
.nvmrc chore(deps): pin dependencies 2024-02-20 19:14:23 +00:00
electron-builder.yaml fix: see if we need usb entitlement, exempt encryption 2023-08-15 09:13:09 -04:00
electron-webpack.json5 assume direct control of webpack config 2020-08-11 17:17:15 -07:00
LICENSE Update LICENSE 2019-03-06 12:59:20 -05:00
package-lock.json chore(deps): update babel monorepo to v7.26.0 2024-10-28 18:58:59 +00:00
package.json chore(deps): update babel monorepo to v7.26.0 2024-10-28 18:58:59 +00:00
README.md feat: high contrast support 2023-07-28 11:41:06 -04:00
renovate.json5 chore(deps): use Scratch js-app Renovate config 2024-02-20 11:13:14 -08:00
TRADEMARK Update TRADEMARK 2019-03-06 12:59:41 -05:00
webpack.main.js assume direct control of webpack config 2020-08-11 17:17:15 -07:00
webpack.makeConfig.js ci: Revert changes to WP config 2023-11-30 08:28:51 -05:00
webpack.renderer.js feat: high contrast support 2023-07-28 11:41:06 -04:00

scratch-desktop

Scratch 3.0 as a standalone desktop application

Developer Instructions

Releasing a new version

Let's assume that you want to make a new release, version 3.999.0, corresponding to scratch-gui version 0.1.0-prerelease.20yymmdd.

  1. Merge scratch-gui:
    1. cd scratch-gui
    2. git pull --all --tags
    3. git checkout scratch-desktop
    4. git merge 0.1.0-prerelease.20yymmdd
    5. Resolve conflicts if necessary
    6. git tag scratch-desktop-v3.999.0
    7. git push
    8. git push --tags
  2. Prep scratch-desktop:
    1. cd scratch-desktop
    2. git pull --all --tags
    3. git checkout develop
    4. npm install --save-dev 'scratch-gui@github:scratchfoundation/scratch-gui#scratch-desktop-v3.999.0'
    5. git add package.json package-lock.json
    6. Make sure the app works, the diffs look reasonable, etc.
    7. git commit -m "bump scratch-gui to scratch-desktop-v3.999.0"
    8. npm version 3.999.0
    9. git push
    10. git push --tags
  3. Wait for the CI build and collect the release from the build artifacts

A note about scratch-gui

Eventually, the scratch-desktop branch of the Scratch GUI repository will be merged with that repository's main development line. For now, though, the scratch-desktop branch holds a few changes that are necessary for the Scratch app to function correctly but are not yet merged into the main development branch. If you only intend to build or work on the scratch-desktop repository then you can ignore this, but if you intend to work on scratch-gui as well, make sure you use the scratch-desktop branch there.

Previously it was necessary to explicitly build scratch-gui before building scratch-desktop. This is no longer necessary and the related build scripts, such as build-gui, have been removed.

Prepare media library assets

In the scratch-desktop directory, run npm run fetch. Re-run this any time you update scratch-gui or make any other changes which might affect the media libraries.

Run in development mode

npm start

Make a packaged build

npm run dist

Node that on macOS this will require installing various certificates.

Signing the NSIS installer (Windows, non-store)

This section is relevant only to members of the Scratch Team.

By default all Windows installers are unsigned. An APPX package for the Microsoft Store shouldn't be signed: it will be signed automatically as part of the store submission process. On the other hand, the non-Store NSIS installer should be signed.

To generate a signed NSIS installer:

  1. Acquire our latest digital signing certificate and save it on your computer as a p12 file.
  2. Set WIN_CSC_LINK to the path to your certificate file. For maximum compatibility I use forward slashes.
    • CMD: set WIN_CSC_LINK=C:/Users/You/Somewhere/Certificate.p12
    • PowerShell: $env:WIN_CSC_LINK = "C:/Users/You/Somewhere/Certificate.p12"
  3. Set WIN_CSC_KEY_PASSWORD to the password string associated with your P12 file.
    • CMD: set WIN_CSC_KEY_PASSWORD=superSecret
    • PowerShell: $env:WIN_CSC_KEY_PASSWORD = "superSecret"
  4. Build the NSIS installer only: building the APPX installer will fail if these environment variables are set.
    • npm run dist -- -w nsis

Workaround for code signing issue in macOS

Sometimes the macOS build process will result in a build which crashes on startup. If this happens, check in Console for an entry similar to this:

failed to parse entitlements for Scratch[12345]: OSUnserializeXML: syntax error near line 1

This appears to be an issue with codesign itself. Rebooting your computer and trying to build again might help. Yes, really.

See this issue for more detail: https://github.com/electron/electron-osx-sign/issues/218

Make a semi-packaged build

This will simulate a packaged build without actually packaging it: instead the files will be copied to a subdirectory of dist.

npm run dist:dir

Debugging

You can debug the renderer process by opening the Chromium development console. This should be the same keyboard shortcut as Chrome on your platform. This won't work on a packaged build.

You can debug the main process the same way as any Node.js process. I like to use Visual Studio Code with a configuration like this:

    "launch": {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Desktop",
                "type": "node",
                "request": "launch",
                "cwd": "${workspaceFolder:scratch-desktop}",
                "runtimeExecutable": "npm",
                "autoAttachChildProcesses": true,
                "runtimeArgs": ["start", "--"],
                "protocol": "inspector",
                "skipFiles": [
                    // it seems like skipFiles only reliably works with 1 entry :(
                    //"<node_internals>/**",
                    "${workspaceFolder:scratch-desktop}/node_modules/electron/dist/resources/*.asar/**"
                ],
                "sourceMaps": true,
                "timeout": 30000,
                "outputCapture": "std"
            }
        ]
    },

Resetting the Telemetry System

This application includes a telemetry system which is only active if the user opts in. When testing this system, it's sometimes helpful to reset it by deleting the telemetry.json file.

The location of this file depends on your operating system and whether or not you're running a packaged build. Running from npm start or equivalent is a non-packaged build.

In addition, macOS may store the file in one of two places depending on the OS version and a few other variables. If in doubt, I recommend removing both.

  • Windows, packaged build: %APPDATA%\Scratch\telemetry.json
  • Windows, non-packaged: %APPDATA%\Electron\telemetry.json
  • macOS, packaged build: ~/Library/Application Support/Scratch/telemetry.json or ~/Library/Containers/edu.mit.scratch.scratch-desktop/Data/Library/Application Support/Scratch/telemetry.json
  • macOS, non-packaged build: ~/Library/Application Support/Electron/telemetry.json or ~/Library/Containers/edu.mit.scratch.scratch-desktop/Data/Library/Application Support/Electron/telemetry.json

Deleting this file will:

  • Remove any pending telemetry packets
  • Reset the opt in/out state: the app should display the opt in/out modal on next launch
  • Remove the random client UUID: the app will generate a new one on next launch