36 |
37 |
38 |
39 |
40 |
41 |
The Start Task onClick handler is defined as
42 |
43 | $(#start-task).onClick = function()
44 | {
45 | var taskElem = $(div#tasks > select)
46 | .$append(<option>Task { ++taskNo }
47 | <progress max=100 />
48 | <span.result /></option>);
49 | function onProgress(p100) {
50 | taskElem.$(progress).value = p100;
51 | }
52 | function onDone(taskId) {
53 | taskElem.$(span.result).text = "Done!";
54 | taskElem.$(progress).remove();
55 | }
56 | view.exec_task(taskId, onProgress, onDone);
57 | }
58 |
59 |
60 |
It defines couple of callback functions and calls view.exec_task() with them.
61 |
The view.exec_task() native method is implemented in EventHandler::exec_task().
62 |
The EventHandler::exec_task() starts worker thread passing taskNo, onProgress and
63 | onDone parameters to it.
64 |
Worker thread body is defined in Rust code as:
65 |
66 | // worker thread body, simulate time consuming task
67 | fn thread_body(task_no: i32, progress: Value, done: Value)
68 | {
69 | for i in 1..100 {
70 | std::thread::sleep(std::time::Duration::from_millis(100));
71 | progress.call(None, &make_args!(i), None).unwrap(); // report task progress
72 | }
73 | // report task completion,
74 | // we can pass some result data here, for now just taskId
75 | done.call(None, &make_args!(task_no), None).unwrap();
76 | }
77 |
78 |
As you see it calls passed callback functions.
79 |
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/.github/workflows/sciter-tis.yml:
--------------------------------------------------------------------------------
1 | name: TIScript
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | - travis
8 |
9 | pull_request:
10 | branches:
11 | - master
12 |
13 | # Look:
14 | # https://github.com/actions/starter-workflows/blob/master/ci/rust.yml
15 | #
16 | # Simple, right? Right.
17 | # But we need to:
18 | # * download a specific Sciter library matching the running OS
19 | # * figure out where to save it
20 | # * add it to the $PATH
21 | #
22 | # yet,
23 | # * in case of macOS realize that it doesn't have Rust installed, so
24 | # * install it manually and don't forget to add cargo and rustc to the $PATH on each step
25 | # * and in case of Linux install additional packages for GTK3
26 | #
27 | # So, now we're ended up with this ugly script.
28 |
29 | jobs:
30 | build:
31 | name: Build and test
32 |
33 | runs-on: ${{ matrix.os }}
34 | strategy:
35 | fail-fast: false
36 | matrix:
37 | os: [macos-latest, ubuntu-latest, windows-latest]
38 |
39 | steps:
40 | - uses: actions/checkout@v2
41 |
42 | - name: Windows deps
43 | if: runner.os == 'Windows'
44 | # Windows: download sciter library
45 | run: curl -sSLo "%SCITER_DEPS%/sciter.dll" "https://raw.githubusercontent.com/c-smile/sciter-sdk/master/bin.win/x64/sciter.dll"
46 | shell: cmd
47 | env:
48 | SCITER_DEPS: ${{ runner.workspace }}
49 |
50 | - name: Linux deps
51 | if: runner.os == 'Linux'
52 | # Linux: download sciter library && install libgtk-3-dev
53 | run: |
54 | curl -so "$SCITER_DEPS/libsciter-gtk.so" "https://raw.githubusercontent.com/c-smile/sciter-sdk/master/bin.lnx/x64/libsciter-gtk.so"
55 | sudo apt-get update -y && sudo apt-get install libgtk-3-dev libgtk-3-0 -y
56 | env:
57 | SCITER_DEPS: ${{ runner.workspace }}
58 |
59 | - name: macOS deps
60 | if: runner.os == 'macOS'
61 | # OSX: download sciter library
62 | run: |
63 | curl -so "$SCITER_DEPS/libsciter.dylib" "https://raw.githubusercontent.com/c-smile/sciter-sdk/master/bin.osx/libsciter.dylib"
64 | env:
65 | SCITER_DEPS: ${{ runner.workspace }}
66 |
67 | - name: Build
68 | shell: bash
69 | run: |
70 | cargo build --all
71 | cargo build --examples
72 |
73 | - name: serde
74 | shell: bash
75 | continue-on-error: true
76 | run: |
77 | export PATH="$PATH:$SCITER_DEPS"
78 | cargo build -p sciter-serde
79 | cargo test -p sciter-serde
80 | env:
81 | SCITER_DEPS: ${{ runner.workspace }}
82 |
83 | - name: windowless
84 | shell: bash
85 | continue-on-error: true
86 | run: |
87 | cargo build -p windowless
88 |
89 | - name: extension
90 | shell: bash
91 | continue-on-error: true
92 | run: |
93 | cargo build -p extension
94 |
95 | - name: Tests
96 | shell: bash
97 | run: |
98 | export PATH="$PATH:$SCITER_DEPS"
99 | cargo run --example first
100 | cargo test -p sciter-rs
101 | env:
102 | SCITER_DEPS: ${{ runner.workspace }}
103 |
--------------------------------------------------------------------------------
/src/capi/sctypes.rs:
--------------------------------------------------------------------------------
1 | //! Sciter platform-dependent types.
2 |
3 | #![allow(non_camel_case_types, non_snake_case)]
4 |
5 | extern crate libc;
6 |
7 | use self::libc::*;
8 |
9 |
10 | // common
11 | MAKE_HANDLE!(#[doc = "Window native handle."] HWINDOW, _HWINDOW); // HWND or NSView* or GtkWidget*
12 | MAKE_HANDLE!(#[doc = "Archive native handle."] HSARCHIVE, _HSARCHIVE);
13 |
14 | pub type BYTE = u8;
15 | pub type INT = i32;
16 | pub type LONG = i32;
17 | pub type UINT = u32;
18 | pub type INT64 = i64;
19 | pub type UINT64 = u64;
20 |
21 | pub type FLOAT_VALUE = f64;
22 |
23 | pub type WPARAM = size_t;
24 | pub type LPARAM = ssize_t;
25 |
26 | pub type UINT_PTR = uintptr_t;
27 | pub type LRESULT = ssize_t;
28 |
29 | pub type CHAR = c_char;
30 | pub type LPSTR = *mut CHAR;
31 | pub type LPCSTR = *const CHAR;
32 |
33 | pub type WCHAR = u16;
34 | pub type LPWSTR = *mut WCHAR;
35 | pub type LPCWSTR = *const WCHAR;
36 |
37 | pub type LPCBYTE = *const BYTE;
38 | pub type LPUINT = *mut UINT;
39 |
40 | pub type VOID = c_void;
41 | pub type LPVOID = *mut VOID;
42 | pub type LPCVOID = *const VOID;
43 |
44 | #[cfg(windows)]
45 | pub type BOOL = i32;
46 |
47 | #[cfg(not(windows))]
48 | pub type BOOL = i8;
49 |
50 | pub type PBOOL = *mut BOOL;
51 |
52 | /// Defines the coordinates of the upper-left and lower-right corners of a rectangle.
53 | #[repr(C)]
54 | #[derive(Clone, Copy, PartialEq)]
55 | #[derive(Default, Debug)]
56 | pub struct RECT {
57 | pub left: LONG,
58 | pub top: LONG,
59 | pub right: LONG,
60 | pub bottom: LONG,
61 | }
62 | pub type LPRECT = *mut RECT;
63 | pub type LPCRECT = *const RECT;
64 |
65 | impl RECT {
66 | /// Calculate the height of the rect.
67 | pub fn height(&self) -> LONG {
68 | self.bottom - self.top
69 | }
70 |
71 | /// Calculate the width of the rect.
72 | pub fn width(&self) -> LONG {
73 | self.right - self.left
74 | }
75 |
76 | /// Return the size of the rect in width and height form.
77 | pub fn size(&self) -> SIZE {
78 | SIZE {
79 | cx: self.width(),
80 | cy: self.height(),
81 | }
82 | }
83 |
84 | /// Returns the top-left point of the rect.
85 | pub fn topleft(&self) -> POINT {
86 | POINT {
87 | x: self.left,
88 | y: self.top,
89 | }
90 | }
91 | }
92 |
93 | /// Defines the `x` and `y` coordinates of a point.
94 | #[repr(C)]
95 | #[derive(Clone, Copy, PartialEq)]
96 | #[derive(Default, Debug)]
97 | pub struct POINT {
98 | pub x: LONG,
99 | pub y: LONG,
100 | }
101 | pub type LPPOINT = *mut POINT;
102 |
103 | /// Specifies the width and height of a rectangle.
104 | #[repr(C)]
105 | #[derive(Clone, Copy, PartialEq)]
106 | #[derive(Default, Debug)]
107 | pub struct SIZE {
108 | pub cx: LONG,
109 | pub cy: LONG,
110 | }
111 | pub type LPSIZE = *mut SIZE;
112 |
113 |
114 | #[cfg(windows)]
115 | #[repr(C)]
116 | #[derive(Debug)]
117 | pub struct MSG {
118 | pub hwnd: HWINDOW,
119 | pub message: UINT,
120 | pub wParam: WPARAM,
121 | pub lParam: LPARAM,
122 | pub time: UINT,
123 | pub pt: POINT,
124 | }
125 |
126 | #[cfg(windows)]
127 | pub type LPMSG = *mut MSG;
128 |
129 | #[cfg(not(windows))]
130 | pub type LPMSG = LPVOID;
131 |
--------------------------------------------------------------------------------
/.github/workflows/sciter-js.yml:
--------------------------------------------------------------------------------
1 | name: JavaScript
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | - travis
8 |
9 | pull_request:
10 | branches:
11 | - master
12 |
13 | # Look:
14 | # https://github.com/actions/starter-workflows/blob/master/ci/rust.yml
15 | #
16 | # Simple, right? Right.
17 | # But we need to:
18 | # * download a specific Sciter library matching the running OS
19 | # * figure out where to save it
20 | # * add it to the $PATH
21 | #
22 | # yet,
23 | # * in case of macOS realize that it doesn't have Rust installed, so
24 | # * install it manually and don't forget to add cargo and rustc to the $PATH on each step
25 | # * and in case of Linux install additional packages for GTK3
26 | #
27 | # So, now we're ended up with this ugly script.
28 |
29 | jobs:
30 | build:
31 | name: Build and test
32 |
33 | runs-on: ${{ matrix.os }}
34 | strategy:
35 | fail-fast: false
36 | matrix:
37 | os: [macos-latest, ubuntu-latest, windows-latest]
38 |
39 | steps:
40 | - uses: actions/checkout@v2
41 |
42 | - name: Windows deps
43 | if: runner.os == 'Windows'
44 | # Windows: download sciter library
45 | run: curl -sSLo "%SCITER_DEPS%/sciter.dll" "https://raw.githubusercontent.com/c-smile/sciter-js-sdk/main/bin/windows/x64/sciter.dll"
46 | shell: cmd
47 | env:
48 | SCITER_DEPS: ${{ runner.workspace }}
49 |
50 | - name: Linux deps
51 | if: runner.os == 'Linux'
52 | # Linux: download sciter library && install libgtk-3-dev
53 | run: |
54 | curl -so "$SCITER_DEPS/libsciter-gtk.so" "https://raw.githubusercontent.com/c-smile/sciter-js-sdk/main/bin/linux/x64/libsciter-gtk.so"
55 | sudo apt-get update -y && sudo apt-get install libgtk-3-dev libgtk-3-0 -y
56 | env:
57 | SCITER_DEPS: ${{ runner.workspace }}
58 |
59 | - name: macOS deps
60 | if: runner.os == 'macOS'
61 | # OSX: download sciter library
62 | run: |
63 | curl -so "$SCITER_DEPS/libsciter.dylib" "https://raw.githubusercontent.com/c-smile/sciter-js-sdk/main/bin/macosx/libsciter.dylib"
64 | env:
65 | SCITER_DEPS: ${{ runner.workspace }}
66 |
67 | - name: Build
68 | shell: bash
69 | run: |
70 | cargo build --all
71 | cargo build --examples
72 |
73 | - name: serde
74 | shell: bash
75 | continue-on-error: true
76 | run: |
77 | export PATH="$PATH:$SCITER_DEPS"
78 | cargo build -p sciter-serde
79 | cargo test -p sciter-serde
80 | env:
81 | SCITER_DEPS: ${{ runner.workspace }}
82 |
83 | - name: windowless
84 | shell: bash
85 | continue-on-error: true
86 | run: |
87 | cargo build -p windowless
88 |
89 | - name: extension
90 | shell: bash
91 | continue-on-error: true
92 | run: |
93 | cargo build -p extension
94 |
95 | - name: Tests
96 | shell: bash
97 | run: |
98 | export PATH="$PATH:$SCITER_DEPS"
99 | cargo run --example first
100 | cargo test -p sciter-rs
101 | env:
102 | SCITER_DEPS: ${{ runner.workspace }}
103 |
--------------------------------------------------------------------------------
/serde/src/lib.rs:
--------------------------------------------------------------------------------
1 | // This component uses Sciter Engine,
2 | // copyright Terra Informatica Software, Inc.
3 | // (http://terrainformatica.com/).
4 |
5 | /*!
6 |
7 | [Serde](https://docs.rs/serde) support for [Sciter](https://docs.rs/sciter-rs) engine.
8 |
9 | While technically you could just use the `serde_json` crate and perform serialization via
10 | an intermediate string (something like `sciter::Value::from_str(&serde_json::to_string(