├── project
├── build.properties
└── plugins.sbt
├── .gitignore
├── src
└── main
│ ├── scala
│ └── electron
│ │ └── quickstart
│ │ ├── Window.scala
│ │ └── App.scala
│ └── electron
│ └── index.html
├── LICENSE.md
├── .ctags
├── package.json
└── README.md
/project/build.properties:
--------------------------------------------------------------------------------
1 | sbt.version=0.13.9
2 |
--------------------------------------------------------------------------------
/project/plugins.sbt:
--------------------------------------------------------------------------------
1 | addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.9")
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | target
3 | /tags
4 | /src/main/electron/scalajs-electron-quick-start*
5 |
--------------------------------------------------------------------------------
/src/main/scala/electron/quickstart/Window.scala:
--------------------------------------------------------------------------------
1 | package electron.quickstart
2 |
3 | import scala.scalajs.js
4 | import scala.scalajs.js.Dynamic.global
5 | import scala.scalajs.js.annotation.JSExport
6 |
7 | @JSExport("ElectronQuickStart.Window")
8 | class Window {
9 | global.document.getElementsByTagName("BODY").asInstanceOf[js.Array[js.Dynamic]].apply(0).style = "background: #eee;"
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/electron/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Hello World!
6 |
16 |
17 |
18 | Hello World!
19 |
20 | We are using node ,
21 | Chromium ,
22 | and Electron .
23 |
24 |
25 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Copyright (C) 2016 by Matthew Scharley
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/.ctags:
--------------------------------------------------------------------------------
1 | --langdef=scala
2 | --langmap=scala:.scala
3 | --regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*class[ \t]+([a-zA-Z0-9_]+)/\4/c,classes/
4 | --regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*object[ \t]+([a-zA-Z0-9_]+)/\4/c,objects/
5 | --regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*case class[ \t]+([a-zA-Z0-9_]+)/\4/c,case classes/
6 | --regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*case object[ \t]+([a-zA-Z0-9_]+)/\4/c,case objects/
7 | --regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*trait[ \t]+([a-zA-Z0-9_]+)/\4/t,traits/
8 | --regex-scala=/^[ \t]*type[ \t]+([a-zA-Z0-9_]+)/\1/T,types/
9 | --regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*def[ \t]+([a-zA-Z0-9_]+)/\3/m,methods/
10 | --regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*val[ \t]+([a-zA-Z0-9_]+)/\3/l,constants/
11 | --regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*var[ \t]+([a-zA-Z0-9_]+)/\3/l,variables/
12 | --regex-scala=/^[ \t]*package[ \t]+([a-zA-Z0-9_.]+)/\1/p,packages/
13 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "scalajs-electron-quick-start",
3 | "version": "1.0.0",
4 | "description": "A minimal Electron application with Scala.js support",
5 | "scripts": {
6 | "start": "rm -fv src/main/electron/${npm_package_name}* && sbt fullOptJS && cp -v target/scala-*/${npm_package_name}* src/main/electron/ && electron src/main/electron/${npm_package_name}-launcher.js",
7 | "debug": "rm -fv src/main/electron/${npm_package_name}* && sbt clean fastOptJS && cp -v target/scala-*/${npm_package_name}* src/main/electron/ && electron src/main/electron/${npm_package_name}-launcher.js",
8 | "test": "sbt test"
9 | },
10 | "repository": {
11 | "type": "git",
12 | "url": "git+https://github.com/mscharley/scalajs-electron-quick-start.git"
13 | },
14 | "keywords": [
15 | "Electron",
16 | "Scala",
17 | "Scala.js"
18 | ],
19 | "author": "Matthew Scharley",
20 | "license": "MIT",
21 | "bugs": {
22 | "url": "https://github.com/mscharley/scalajs-electron-quick-start/issues"
23 | },
24 | "homepage": "https://github.com/mscharley/scalajs-electron-quick-start#readme",
25 | "devDependencies": {
26 | "electron-prebuilt": "^1.1.1",
27 | "source-map-support": "^0.4.0"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # electron-quick-start (Scala.js port)
2 |
3 | **Clone and run for a quick way to see an Electron in action.**
4 |
5 | This is a minimal Electron application based on the [Quick Start Guide](http://electron.atom.io/docs/latest/tutorial/quick-start) within the Electron documentation.
6 |
7 | **Use this app along with the [Electron API Demos](http://electron.atom.io/#get-started) app for API code examples to help you get started.**
8 |
9 | A basic Electron application needs just these files:
10 |
11 | - `package.json` - Points to the app's main file and lists its details and dependencies.
12 | - `main.js` - Starts the app and creates a browser window to render HTML. This is the app's **main process**.
13 | - `index.html` - A web page to render. This is the app's **renderer process**.
14 |
15 | You can learn more about each of these components within the [Quick Start Guide](http://electron.atom.io/docs/latest/tutorial/quick-start).
16 |
17 | ## To use
18 |
19 | To clone and run this repository you'll need [Git](https://git-scm.com) and [Node.js](https://nodejs.org/en/download/) (which comes with [npm](http://npmjs.com)) as well as [SBT](http://www.scala-sbt.org/) installed on your computer. From your command line:
20 |
21 | ```bash
22 | # Clone this repository
23 | git clone https://github.com/mscharley/scalajs-electron-quick-start
24 | # Go into the repository
25 | cd scalajs-electron-quick-start
26 | # Install dependencies and run the app
27 | npm install && npm start
28 | ```
29 |
30 | Learn more about Electron and its API in the [documentation](http://electron.atom.io/docs/latest).
31 |
32 | ## Scala.js notes
33 |
34 | The `main.js` in the documentation mostly translates to `App.scala` in this repository.
35 | For a more in-depth review of some of the features that Scala.js can bring to
36 | Electron then please [have a look at the Scala.js demo app][demo-app].
37 |
38 | #### License [MIT](LICENSE.md)
39 |
40 | [demo-app]: https://github.com/mscharley/scalajs-electron-demo
41 |
--------------------------------------------------------------------------------
/src/main/scala/electron/quickstart/App.scala:
--------------------------------------------------------------------------------
1 | package electron.quickstart
2 |
3 | import electron._
4 |
5 | import scala.scalajs.js
6 | import scala.scalajs.js.Dynamic.{global, literal => JsObject}
7 | import scala.scalajs.js.annotation.JSExport
8 |
9 | @JSExport("ElectronQuickStart.App")
10 | class App(dirName: String, require: js.Function1[String, js.Any]) extends ElectronApp(require) with js.JSApp {
11 | // Keep a global reference of the window object, if you don't, the window will
12 | // be closed automatically when the JavaScript object is garbage collected.
13 | var mainWindow: Option[BrowserWindow] = None
14 | val console = global.console
15 |
16 | def createWindow() = {
17 | // Create the browser window.
18 | mainWindow = Some(BrowserWindow(JsObject(width = 800, height = 600)))
19 | mainWindow foreach { window =>
20 | // and load the index.html of the app.
21 | window.loadURL("file://" + dirName + "/index.html")
22 |
23 | // Open the DevTools.
24 | window.webContents.openDevTools()
25 |
26 | // Emitted when the window is closed.
27 | // Dereference the window object, usually you would store windows
28 | // in an array if your app supports multi windows, this is the time
29 | // when you should delete the corresponding element.
30 | window.on("closed"){ () => mainWindow = None }
31 | }
32 | }
33 |
34 | def main() = {
35 | console.log("Starting scalajs-electron-quick-start...");
36 |
37 | // This method will be called when Electron has finished initialization and is ready to create browser windows.
38 | electronApp onceReady createWindow _
39 |
40 | process.platform.asInstanceOf[String] match {
41 | case "darwin" =>
42 | // On OS X it is common for applications and their menu bar to stay active until the user quits explicitly
43 | // with Cmd + Q and re-create a window in the app when the dock icon is clicked and there are no other
44 | // windows open.
45 | electronApp onActivate { () =>
46 | if (mainWindow.isEmpty) {
47 | createWindow()
48 | }
49 | }
50 |
51 | case _ =>
52 | // For everyone else, we just die immediately.
53 | electronApp onWindowAllClosed { () => electronApp.quit() }
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------