GeezerVison is showing github.com — feat(mobile): start tasks and open t3 code from ios control center · pingdotgg/t3code@041cb5c
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/mobile/app.config.ts +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -444,7 +444,9 @@ const config: ExpoConfig = { | 444 | 444 | // Compile out the unused pedometer to avoid an iOS motion purpose string. | 445 | 445 | ["expo-sensors", { motionPermission: false }], | 446 | 446 | // Mods run in reverse order; expo-widgets must create and wipe the target before assets are added. | 447 | | - ...(!isIosPersonalTeamBuild ? ["./plugins/withWidgetLogoAsset.cjs", widgetsPlugin] : []), | | 447 | + ...(!isIosPersonalTeamBuild | | 448 | + ? ["./plugins/withWidgetLogoAsset.cjs", "./plugins/withIosControls.cjs", widgetsPlugin] | | 449 | + : []), | 448 | 450 | "./plugins/withAndroidNetworkSecurityConfig.cjs", | 449 | 451 | "./plugins/withAndroidGradleHeap.cjs", | 450 | 452 | "./plugins/withAndroidInputBackground.cjs", | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/fingerprint.config.js +10-1Lines changed: 10 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,5 +14,14 @@ if (!majorVersion) { | 14 | 14 |
| 15 | 15 | module.exports = { | 16 | 16 | nativeModuleSourceType: "files", | 17 | | - extraSources: [{ type: "contents", id: "appMajorVersion", contents: majorVersion }], | | 17 | + extraSources: [ | | 18 | + { type: "contents", id: "appMajorVersion", contents: majorVersion }, | | 19 | + // The controls plugin copies these native inputs outside Expo's module tracking. | | 20 | + ...[ | | 21 | + "plugins/ios/T3ControlIntents.swift", | | 22 | + "plugins/ios/T3StartTaskControl.swift", | | 23 | + "plugins/ios/T3OpenAppControl.swift", | | 24 | + "assets/widget/T3Mark.svg", | | 25 | + ].map((filePath) => ({ type: "file", filePath })), | | 26 | + ], | 18 | 27 | }; |
Collapse file Copy file name to clipboard +33Lines changed: 33 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import AppIntents | | 2 | +import Foundation | | 3 | + | | 4 | +#if !T3_WIDGET_EXTENSION | | 5 | +import UIKit | | 6 | +#endif | | 7 | + | | 8 | +@available(iOS 18.0, *) | | 9 | +struct T3StartTaskIntent: AppIntent { | | 10 | + static var title: LocalizedStringResource = "Start a task" | | 11 | + static var openAppWhenRun: Bool = true | | 12 | + | | 13 | + @MainActor | | 14 | + func perform() async throws -> some IntentResult { | | 15 | + // Control intents must also belong to the app so iOS runs this action in its process. | | 16 | + #if !T3_WIDGET_EXTENSION | | 17 | + if let url = URL(string: "__T3_SCHEME__://new") { | | 18 | + await UIApplication.shared.open(url) | | 19 | + } | | 20 | + #endif | | 21 | + return .result() | | 22 | + } | | 23 | +} | | 24 | + | | 25 | +@available(iOS 18.0, *) | | 26 | +struct T3OpenAppIntent: AppIntent { | | 27 | + static var title: LocalizedStringResource = "Open T3 Code" | | 28 | + static var openAppWhenRun: Bool = true | | 29 | + | | 30 | + func perform() async throws -> some IntentResult { | | 31 | + return .result() | | 32 | + } | | 33 | +} |
Collapse file Copy file name to clipboard +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import AppIntents | | 2 | +import SwiftUI | | 3 | +import WidgetKit | | 4 | + | | 5 | +@available(iOS 18.0, *) | | 6 | +struct T3OpenAppControl: ControlWidget { | | 7 | + var body: some ControlWidgetConfiguration { | | 8 | + StaticControlConfiguration(kind: "T3OpenAppControl") { | | 9 | + ControlWidgetButton(action: T3OpenAppIntent()) { | | 10 | + Label("Open T3 Code", image: "T3ControlMark") | | 11 | + } | | 12 | + } | | 13 | + .displayName("Open T3 Code") | | 14 | + .description("Open T3 Code.") | | 15 | + } | | 16 | +} |
Collapse file Copy file name to clipboard +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import AppIntents | | 2 | +import SwiftUI | | 3 | +import WidgetKit | | 4 | + | | 5 | +@available(iOS 18.0, *) | | 6 | +struct T3StartTaskControl: ControlWidget { | | 7 | + var body: some ControlWidgetConfiguration { | | 8 | + StaticControlConfiguration(kind: "T3StartTaskControl") { | | 9 | + ControlWidgetButton(action: T3StartTaskIntent()) { | | 10 | + Label("Start a task", systemImage: "square.and.pencil") | | 11 | + } | | 12 | + } | | 13 | + .displayName("Start a task") | | 14 | + .description("Start a new task in T3 Code.") | | 15 | + } | | 16 | +} |
Collapse file Copy file name to clipboard +31Lines changed: 31 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +"use strict"; | | 2 | + | | 3 | +function createControlSymbol(svg) { | | 4 | + const paths = [...svg.matchAll(/<path\b[^>]*\bd="([^"]+)"/g)].map((match) => match[1]); | | 5 | + if (paths.length === 0) throw new Error("The T3 widget mark has no symbol paths."); | | 6 | + const sizes = [ | | 7 | + ["S", 696], | | 8 | + ["M", 1326], | | 9 | + ["L", 1956], | | 10 | + ]; | | 11 | + const guides = sizes | | 12 | + .flatMap(([size, baseline]) => | | 13 | + [ | | 14 | + ["Baseline", baseline], | | 15 | + ["Capline", baseline - 71], | | 16 | + ].map(([name, y]) => `<line id="${name}-${size}" x1="0" y1="${y}" x2="3300" y2="${y}"/>`), | | 17 | + ) | | 18 | + .join(""); | | 19 | + const symbols = sizes | | 20 | + .map( | | 21 | + ([size, baseline]) => | | 22 | + `<g id="Regular-${size}" transform="translate(1393 ${baseline})">${paths | | 23 | + // Align the mark's ink bounds to the symbol cap height and baseline. | | 24 | + .map((d) => `<path d="${d}" transform="matrix(1.25 0 0 1.25 -19.413625 -117.45)"/>`) | | 25 | + .join("")}</g>`, | | 26 | + ) | | 27 | + .join(""); | | 28 | + return `<svg xmlns="http://www.w3.org/2000/svg" width="3300" height="2200" viewBox="0 0 3300 2200"><g id="Notes"><text id="template-version">2.0</text></g><g id="Guides">${guides}</g><g id="Symbols">${symbols}</g></svg>\n`; | | 29 | +} | | 30 | + | | 31 | +module.exports = { createControlSymbol }; |
Collapse file Copy file name to clipboard +77Lines changed: 77 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +"use strict"; | | 2 | + | | 3 | +const fs = require("fs"); | | 4 | +const path = require("path"); | | 5 | +const { withDangerousMod, withXcodeProject } = require("expo/config-plugins"); | | 6 | + | | 7 | +const TARGET_NAME = "ExpoWidgetsTarget"; | | 8 | +const INTENT_FILE = "T3ControlIntents.swift"; | | 9 | +const CONTROLS = ["T3StartTaskControl", "T3OpenAppControl"]; | | 10 | + | | 11 | +module.exports = function withIosControls(config) { | | 12 | + const scheme = config.scheme; | | 13 | + if (typeof scheme !== "string" || !/^[a-z][a-z0-9+.-]*$/i.test(scheme)) { | | 14 | + throw new Error("Start a task control requires a single app URL scheme."); | | 15 | + } | | 16 | + | | 17 | + config = withDangerousMod(config, [ | | 18 | + "ios", | | 19 | + (cfg) => { | | 20 | + const root = cfg.modRequest.platformProjectRoot; | | 21 | + const widgetRoot = path.join(root, TARGET_NAME); | | 22 | + const indexPath = path.join(widgetRoot, "index.swift"); | | 23 | + const source = fs.readFileSync(indexPath, "utf8"); | | 24 | + const body = "var body: some Widget {"; | | 25 | + if (!source.includes(body)) { | | 26 | + throw new Error("Cannot find the Expo widget bundle for the Start a task control."); | | 27 | + } | | 28 | + const missing = CONTROLS.filter((control) => !source.includes(`${control}()`)); | | 29 | + if (missing.length > 0) { | | 30 | + fs.writeFileSync( | | 31 | + indexPath, | | 32 | + source.replace( | | 33 | + body, | | 34 | + `${body}\n if #available(iOS 18.0, *) {\n ${missing.map((control) => `${control}()`).join("\n ")}\n }`, | | 35 | + ), | | 36 | + ); | | 37 | + } | | 38 | + const intent = fs | | 39 | + .readFileSync(path.join(__dirname, "ios", INTENT_FILE), "utf8") | | 40 | + .replaceAll("__T3_SCHEME__", scheme); | | 41 | + fs.writeFileSync(path.join(root, INTENT_FILE), intent); | | 42 | + fs.writeFileSync(path.join(widgetRoot, INTENT_FILE), intent); | | 43 | + for (const control of CONTROLS) { | | 44 | + fs.copyFileSync( | | 45 | + path.join(__dirname, "ios", `${control}.swift`), | | 46 | + path.join(widgetRoot, `${control}.swift`), | | 47 | + ); | | 48 | + } | | 49 | + return cfg; | | 50 | + }, | | 51 | + ]); | | 52 | + | | 53 | + return withXcodeProject(config, (cfg) => { | | 54 | + const project = cfg.modResults; | | 55 | + const target = Object.entries(project.pbxNativeTargetSection()).find( | | 56 | + ([key, value]) => !key.endsWith("_comment") && value.name === TARGET_NAME, | | 57 | + ); | | 58 | + if (!target) { | | 59 | + throw new Error("Register withIosControls before expo-widgets."); | | 60 | + } | | 61 | + const group = project.getFirstProject().firstProject.mainGroup; | | 62 | + project.addSourceFile(INTENT_FILE, { target: project.getFirstTarget().uuid }, group); | | 63 | + for (const file of [INTENT_FILE, ...CONTROLS.map((control) => `${control}.swift`)]) { | | 64 | + project.addSourceFile(`${TARGET_NAME}/${file}`, { target: target[0] }, group); | | 65 | + } | | 66 | + const list = project.pbxXCConfigurationList()[target[1].buildConfigurationList]; | | 67 | + for (const reference of list.buildConfigurations) { | | 68 | + const settings = project.pbxXCBuildConfigurationSection()[reference.value].buildSettings; | | 69 | + const flags = settings.SWIFT_ACTIVE_COMPILATION_CONDITIONS ?? '"$(inherited)"'; | | 70 | + const values = Array.isArray(flags) ? flags : [flags]; | | 71 | + if (!values.includes("T3_WIDGET_EXTENSION")) { | | 72 | + settings.SWIFT_ACTIVE_COMPILATION_CONDITIONS = [...values, "T3_WIDGET_EXTENSION"]; | | 73 | + } | | 74 | + } | | 75 | + return cfg; | | 76 | + }); | | 77 | +}; |
Collapse file Copy file name to clipboard +79Lines changed: 79 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import * as NodeFS from "node:fs"; | | 2 | +import * as NodeModule from "node:module"; | | 3 | +import * as NodeOS from "node:os"; | | 4 | +import * as NodePath from "node:path"; | | 5 | +import { expect, it } from "vite-plus/test"; | | 6 | + | | 7 | +const require = NodeModule.createRequire(import.meta.url); | | 8 | +const withIosControls = require("./withIosControls.cjs"); | | 9 | +const withWidgetLogoAsset = require("./withWidgetLogoAsset.cjs"); | | 10 | +const withWidgets = require("expo-widgets/app.plugin.js").default; | | 11 | + | | 12 | +it.each(["t3code", "t3code-dev", "t3code-preview"])( | | 13 | + "adds iOS controls and the T3 symbol to the Expo widget bundle using %s", | | 14 | + async (scheme) => { | | 15 | + const root = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-task-control-")); | | 16 | + try { | | 17 | + NodeFS.writeFileSync(NodePath.join(root, "Podfile"), 'target "T3Code" do\nend\n'); | | 18 | + NodeFS.mkdirSync(NodePath.join(root, "assets/widget"), { recursive: true }); | | 19 | + NodeFS.copyFileSync( | | 20 | + NodePath.join(import.meta.dirname, "../assets/widget/T3Mark.svg"), | | 21 | + NodePath.join(root, "assets/widget/T3Mark.svg"), | | 22 | + ); | | 23 | + const config = withWidgets( | | 24 | + withIosControls( | | 25 | + withWidgetLogoAsset({ | | 26 | + name: "T3 Code", | | 27 | + slug: "t3-code", | | 28 | + scheme, | | 29 | + _internal: { projectRoot: root }, | | 30 | + ios: { bundleIdentifier: "com.t3tools.t3code" }, | | 31 | + }), | | 32 | + ), | | 33 | + { | | 34 | + widgets: [ | | 35 | + { | | 36 | + name: "SubscriptionUsage", | | 37 | + displayName: "Subscription usage", | | 38 | + description: "Usage", | | 39 | + ios: { supportedFamilies: ["systemSmall"] }, | | 40 | + }, | | 41 | + ], | | 42 | + }, | | 43 | + ); | | 44 | + await config.mods.ios.dangerous({ | | 45 | + ...config, | | 46 | + modRequest: { projectRoot: root, platformProjectRoot: root, platform: "ios" }, | | 47 | + }); | | 48 | + const widgetRoot = NodePath.join(root, "ExpoWidgetsTarget"); | | 49 | + const index = NodeFS.readFileSync(NodePath.join(widgetRoot, "index.swift"), "utf8"); | | 50 | + expect(index).toContain("if #available(iOS 18.0, *)"); | | 51 | + expect(index).toContain("T3StartTaskControl()"); | | 52 | + expect(index).toContain("T3OpenAppControl()"); | | 53 | + expect(index).toContain("SubscriptionUsage()"); | | 54 | + expect(index).toContain("WidgetLiveActivity()"); | | 55 | + const intent = NodeFS.readFileSync(NodePath.join(root, "T3ControlIntents.swift"), "utf8"); | | 56 | + expect(intent).toContain(`"${scheme}://new"`); | | 57 | + expect(NodeFS.readFileSync(NodePath.join(widgetRoot, "T3ControlIntents.swift"), "utf8")).toBe( | | 58 | + intent, | | 59 | + ); | | 60 | + expect( | | 61 | + NodeFS.readFileSync(NodePath.join(widgetRoot, "T3StartTaskControl.swift"), "utf8"), | | 62 | + ).toContain("ControlWidgetButton(action: T3StartTaskIntent())"); | | 63 | + expect( | | 64 | + NodeFS.readFileSync(NodePath.join(widgetRoot, "T3OpenAppControl.swift"), "utf8"), | | 65 | + ).toContain("ControlWidgetButton(action: T3OpenAppIntent())"); | | 66 | + const symbolSet = NodePath.join(widgetRoot, "Assets.xcassets/T3ControlMark.symbolset"); | | 67 | + expect( | | 68 | + JSON.parse(NodeFS.readFileSync(NodePath.join(symbolSet, "Contents.json"), "utf8")), | | 69 | + ).toMatchObject({ | | 70 | + symbols: [{ filename: "T3ControlMark.svg", idiom: "universal" }], | | 71 | + }); | | 72 | + expect(NodeFS.readFileSync(NodePath.join(symbolSet, "T3ControlMark.svg"), "utf8")).toContain( | | 73 | + 'id="Regular-S"', | | 74 | + ); | | 75 | + } finally { | | 76 | + NodeFS.rmSync(root, { recursive: true, force: true }); | | 77 | + } | | 78 | + }, | | 79 | +); |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/plugins/withWidgetLogoAsset.cjs +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -6,6 +6,7 @@ const path = require("path"); | 6 | 6 | const fs = require("fs"); | 7 | 7 | const { withDangerousMod, withXcodeProject } = require("expo/config-plugins"); | 8 | 8 | const { addWidgetAssetCatalog } = require("./lib/addWidgetAssetCatalog.cjs"); | | 9 | +const { createControlSymbol } = require("./lib/createControlSymbol.cjs"); | 9 | 10 |
| 10 | 11 | const TARGET_NAME = "ExpoWidgetsTarget"; | 11 | 12 | const CATALOG_NAME = "Assets.xcassets"; | @@ -38,6 +39,19 @@ function withAssetFiles(config) { | 38 | 39 | fs.writeFileSync(path.join(catalogDir, "Contents.json"), CATALOG_CONTENTS); | 39 | 40 | fs.writeFileSync(path.join(imageSetDir, "Contents.json"), IMAGE_SET_CONTENTS); | 40 | 41 | fs.copyFileSync(source, path.join(imageSetDir, SVG_NAME)); | | 42 | + const symbolSetDir = path.join(catalogDir, "T3ControlMark.symbolset"); | | 43 | + fs.mkdirSync(symbolSetDir, { recursive: true }); | | 44 | + fs.writeFileSync( | | 45 | + path.join(symbolSetDir, "Contents.json"), | | 46 | + JSON.stringify({ | | 47 | + info: { author: "expo", version: 1 }, | | 48 | + symbols: [{ filename: "T3ControlMark.svg", idiom: "universal" }], | | 49 | + }), | | 50 | + ); | | 51 | + fs.writeFileSync( | | 52 | + path.join(symbolSetDir, "T3ControlMark.svg"), | | 53 | + createControlSymbol(fs.readFileSync(source, "utf8")), | | 54 | + ); | 41 | 55 | return cfg; | 42 | 56 | }, | 43 | 57 | ]); | |
Collapse file Copy file name to clipboardExpand all lines: docs/user/usage.md +6Lines changed: 6 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -192,6 +192,12 @@ Claude quotas. Tap it to open **Usage → Limits**; on Android this works while | 192 | 192 | the background, otherwise open the app from the launcher. On iOS, use **Edit Widget** to choose | 193 | 193 | Session, Weekly, or both for each provider. Reopen T3 to refresh expired readings. | 194 | 194 |
| | 195 | +## Start a task from Control Center | | 196 | + | | 197 | +On iOS 18 or later, open Control Center and choose **Add a Control**. | | 198 | +Find T3 Code and add **Start a task**. Tap the control to open the project chooser for a new task. | | 199 | +Add **Open T3 Code** to open the app without starting a task. | | 200 | + | 195 | 201 | ## Keyboard shortcuts | 196 | 202 |
| 197 | 203 | On web and desktop, open Usage from the command palette. While on Usage, | |
|