Олег Поздняков, OpenWeather
Small
Medium
Large
Extra-Large
const widget = new ListWidget();
const text = widget.addText('Hello World!');
text.textColor = Color.red();
if (config.runsInWidget) {
Script.setWidget(widget);
} else {
await widget.presentMedium();
}
...else {
// Создаём новый алерт и наполняем его контентом
let alert = new Alert();
alert.title = "Enter Code";
alert.addTextField("0000#0000", "");
alert.addAction("OK");
alert.addAction("Cancel");
// "Презентуем" алерт и проверяем, что пользователь нажал на кнопку OK
if (await alert.present() == 0) {
// Получаем текст из поля ввода и выводим его в консоль
let text = alert.textFieldValue(0);
console.log("Entered Text: " + text);
}
}
❌ Больно
Ускорено в 5 раз. В реальности видео длиной 2:37
❌ Дорого
✅ ДААА!!!
Путь к папке Scriptable в iCloud:
~/Library/MobileDocuments/iCloud~dk~simonbs~Scriptable/Documents
Scriptable Gallery
let widget = new ListWidget();
// Show app icon and title
let titleStack = widget.addStack();
let appIconElement = titleStack.addImage(appIcon);
appIconElement.imageSize = new Size(15, 15);
appIconElement.cornerRadius = 4;
titleStack.addSpacer(4);
let titleElement = titleStack.addText(title);
titleElement.textColor = Color.white();
titleElement.textOpacity = 0.7;
titleElement.font = Font.mediumSystemFont(13);
widget.addSpacer(12);
Не пытайтесь понять что тут происходит. Честно.
Полный код сприпта в gist.d.ts, .tsx, TypeScript.js и
.scriptable
const widget = new ListWidget();
const text = widget.addText('Hello World!');
text.textColor = Color.red();
if (config.runsInWidget) {
Script.setWidget(widget);
} else {
await widget.presentMedium();
}
import {ScriptableJSX} from "@jag-k/scriptable-tsx";
const widget = (
<widget>
<text color={Color.red()}>Hello World!</text>
</widget>
);
if (config.runsInWidget) {
Script.setWidget(widget);
} else {
await widget.presentMedium();
}
const widget = (
ScriptableJSX.createElement("widget", null,
ScriptableJSX.createElement("text", { color: Color.red() },
"Hello World!"
)
)
);
if (config.runsInWidget) {
Script.setWidget(widget);
}
else {
await widget.presentMedium();
}
.scriptable и .js файлыconst createElements = [widgetCreateElement, alertCreateElement];
class ScriptableJSX {
static createElement(element, props, ...children) {
for (const creator of createElements) {
const res = creator(element, props, ...children);
if (res) {
return res;
}
}
}
}
Полный код
function widgetCreateElement(element, props, ...children) {
switch (element) {
case "widget":
const widget = new ListWidget();
processContainerChildren(widget, children);
processWidgetProps(widget, props || {});
return widget;
case "stack":
return { type: element, props, children };
case "spacer":
case "image":
case "date":
return { type: element, props };
}
}
Полный код
function processContainerChildren(widget, children) {
for (const child of children) {
if (typeof child === "string" || ...) { widget.addText(String(child)); }
else if (typeof child === "object") {
if (child instanceof Array) { processContainerChildren(widget, child); }
else if (child instanceof Date) { widget.addDate(child); }
else if (child instanceof Image) { widget.addImage(child); }
else if ("type" in child) {
switch (child.type) {
case "text": {
const text = widget.addText(child.text);
processTextProps(text, child.props || {});
break;
}
case "date": ...
case "stack": ...
case "spacer": ...
case "image": ...
...
Полный код
{
"compilerOptions": {
"jsx": "react",
"jsxFactory": "ScriptableJSX.createElement",
"typeRoots": [
"./node_modules/@jag-k/scriptable-jsx",
],
"types": [
"node",
"@jag-k/scriptable-jsx/types",
"@types/scriptable-ios",
]
}
}
import typescript from '@rollup/plugin-typescript';
import scriptableBundle from "@jag-k/rollup-plugin-scriptable";
import * as config from "./config.json";
import {nodeResolve} from '@rollup/plugin-node-resolve';
export default {
input: 'src/main.ts',
output: [
{
file: `dist/${config.name}.js`, format: 'es',
plugins: [scriptableBundle(config)]
},
],
plugins: [ nodeResolve(), typescript() ],
};
{
"always_run_in_app": false,
"icon": {
"color": "yellow",
"glyph":"magic" // SF Symbols
},
"name":"Hello JSX",
"share_sheet_inputs": [], // Это настраивается в самом Scriptable
}
{
"always_run_in_app": false,
"icon": {
"color": "yellow",
"glyph":"magic" // SF Symbols
},
"name":"Hello JSX",
"share_sheet_inputs": [], // Это настраивается в самом Scriptable
"script":"function processJSXColor(color) {..."
}
СберФуд — Система лояльности от Сбербанка. Теперь называется Plazius
Виджет для отображения баланса бейджика сотрудника Яндекса
Просто узнать кто сейчас находится дома. Берёт данные из HomeAssistant