GeezerVison is showing github.com — feat(mobile): start tasks and open t3 code from ios control center by CopyJosh · Pull Request #30462 · pingdotgg/t3code
feat(mobile): start tasks and open t3 code from ios control center
#30462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter
Filter by extension
.cjs
(3)
.js
(1)
.md
(1)
.mjs
(1)
.swift
(3)
.ts
(1)
All 6 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
feat(mobile): start tasks and open t3 code from ios control center
Loading branch information
Uh oh!
There was an error while loading. Please reload this page.
commit 041cb5c07a3058ca7601a5666601f781ca0d8c87
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -444,7 +444,9 @@ const config: ExpoConfig = {
// Compile out the unused pedometer to avoid an iOS motion purpose string.
["expo-sensors", { motionPermission: false }],
// Mods run in reverse order; expo-widgets must create and wipe the target before assets are added.
...(!isIosPersonalTeamBuild ? ["./plugins/withWidgetLogoAsset.cjs", widgetsPlugin] : []),
...(!isIosPersonalTeamBuild
? ["./plugins/withWidgetLogoAsset.cjs", "./plugins/withIosControls.cjs", widgetsPlugin]
: []),
"./plugins/withAndroidNetworkSecurityConfig.cjs",
"./plugins/withAndroidGradleHeap.cjs",
"./plugins/withAndroidInputBackground.cjs",
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -14,5 +14,14 @@ if (!majorVersion) {
module.exports = {
nativeModuleSourceType: "files",
extraSources: [{ type: "contents", id: "appMajorVersion", contents: majorVersion }],
extraSources: [
{ type: "contents", id: "appMajorVersion", contents: majorVersion },
// The controls plugin copies these native inputs outside Expo's module tracking.
...[
"plugins/ios/T3ControlIntents.swift",
"plugins/ios/T3StartTaskControl.swift",
"plugins/ios/T3OpenAppControl.swift",
"assets/widget/T3Mark.svg",
].map((filePath) => ({ type: "file", filePath })),
],
};
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,33 @@
import AppIntents
import Foundation
#if !T3_WIDGET_EXTENSION
import UIKit
#endif
@available(iOS 18.0, *)
struct T3StartTaskIntent: AppIntent {
static var title: LocalizedStringResource = "Start a task"
static var openAppWhenRun: Bool = true
@MainActor
func perform() async throws -> some IntentResult {
// Control intents must also belong to the app so iOS runs this action in its process.
#if !T3_WIDGET_EXTENSION
if let url = URL(string: "__T3_SCHEME__://new") {
await UIApplication.shared.open(url)
}
#endif
return .result()
}
}
@available(iOS 18.0, *)
struct T3OpenAppIntent: AppIntent {
static var title: LocalizedStringResource = "Open T3 Code"
static var openAppWhenRun: Bool = true
func perform() async throws -> some IntentResult {
return .result()
}
}
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,16 @@
import AppIntents
import SwiftUI
import WidgetKit
@available(iOS 18.0, *)
struct T3OpenAppControl: ControlWidget {
var body: some ControlWidgetConfiguration {
StaticControlConfiguration(kind: "T3OpenAppControl") {
ControlWidgetButton(action: T3OpenAppIntent()) {
Label("Open T3 Code", image: "T3ControlMark")
}
}
.displayName("Open T3 Code")
.description("Open T3 Code.")
}
}
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,16 @@
import AppIntents
import SwiftUI
import WidgetKit
@available(iOS 18.0, *)
struct T3StartTaskControl: ControlWidget {
var body: some ControlWidgetConfiguration {
StaticControlConfiguration(kind: "T3StartTaskControl") {
ControlWidgetButton(action: T3StartTaskIntent()) {
Label("Start a task", systemImage: "square.and.pencil")
}
}
.displayName("Start a task")
.description("Start a new task in T3 Code.")
}
}
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,31 @@
"use strict";
function createControlSymbol(svg) {
const paths = [...svg.matchAll(/<path\b[^>]*\bd="([^"]+)"/g)].map((match) => match[1]);
if (paths.length === 0) throw new Error("The T3 widget mark has no symbol paths.");
const sizes = [
["S", 696],
["M", 1326],
["L", 1956],
];
const guides = sizes
.flatMap(([size, baseline]) =>
[
["Baseline", baseline],
["Capline", baseline - 71],
].map(([name, y]) => `<line id="${name}-${size}" x1="0" y1="${y}" x2="3300" y2="${y}"/>`),
)
.join("");
const symbols = sizes
.map(
([size, baseline]) =>
`<g id="Regular-${size}" transform="translate(1393 ${baseline})">${paths
// Align the mark's ink bounds to the symbol cap height and baseline.
.map((d) => `<path d="${d}" transform="matrix(1.25 0 0 1.25 -19.413625 -117.45)"/>`)
.join("")}</g>`,
)
.join("");
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`;
}
module.exports = { createControlSymbol };
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,77 @@
"use strict";
const fs = require("fs");
const path = require("path");
const { withDangerousMod, withXcodeProject } = require("expo/config-plugins");
const TARGET_NAME = "ExpoWidgetsTarget";
const INTENT_FILE = "T3ControlIntents.swift";
const CONTROLS = ["T3StartTaskControl", "T3OpenAppControl"];
module.exports = function withIosControls(config) {
const scheme = config.scheme;
if (typeof scheme !== "string" || !/^[a-z][a-z0-9+.-]*$/i.test(scheme)) {
throw new Error("Start a task control requires a single app URL scheme.");
}
config = withDangerousMod(config, [
"ios",
(cfg) => {
const root = cfg.modRequest.platformProjectRoot;
const widgetRoot = path.join(root, TARGET_NAME);
const indexPath = path.join(widgetRoot, "index.swift");
const source = fs.readFileSync(indexPath, "utf8");
const body = "var body: some Widget {";
if (!source.includes(body)) {
throw new Error("Cannot find the Expo widget bundle for the Start a task control.");
}
const missing = CONTROLS.filter((control) => !source.includes(`${control}()`));
if (missing.length > 0) {
fs.writeFileSync(
indexPath,
source.replace(
body,
`${body}\n if #available(iOS 18.0, *) {\n ${missing.map((control) => `${control}()`).join("\n ")}\n }`,
),
);
}
const intent = fs
.readFileSync(path.join(__dirname, "ios", INTENT_FILE), "utf8")
.replaceAll("__T3_SCHEME__", scheme);
fs.writeFileSync(path.join(root, INTENT_FILE), intent);
fs.writeFileSync(path.join(widgetRoot, INTENT_FILE), intent);
for (const control of CONTROLS) {
fs.copyFileSync(
path.join(__dirname, "ios", `${control}.swift`),
path.join(widgetRoot, `${control}.swift`),
);
}
return cfg;
},
]);
return withXcodeProject(config, (cfg) => {
const project = cfg.modResults;
const target = Object.entries(project.pbxNativeTargetSection()).find(
([key, value]) => !key.endsWith("_comment") && value.name === TARGET_NAME,
);
if (!target) {
throw new Error("Register withIosControls before expo-widgets.");
}
const group = project.getFirstProject().firstProject.mainGroup;
project.addSourceFile(INTENT_FILE, { target: project.getFirstTarget().uuid }, group);
for (const file of [INTENT_FILE, ...CONTROLS.map((control) => `${control}.swift`)]) {
project.addSourceFile(`${TARGET_NAME}/${file}`, { target: target[0] }, group);
}
const list = project.pbxXCConfigurationList()[target[1].buildConfigurationList];
for (const reference of list.buildConfigurations) {
const settings = project.pbxXCBuildConfigurationSection()[reference.value].buildSettings;
const flags = settings.SWIFT_ACTIVE_COMPILATION_CONDITIONS ?? '"$(inherited)"';
const values = Array.isArray(flags) ? flags : [flags];
if (!values.includes("T3_WIDGET_EXTENSION")) {
settings.SWIFT_ACTIVE_COMPILATION_CONDITIONS = [...values, "T3_WIDGET_EXTENSION"];
}
}
return cfg;
});
};
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,79 @@
import * as NodeFS from "node:fs";
import * as NodeModule from "node:module";
import * as NodeOS from "node:os";
import * as NodePath from "node:path";
import { expect, it } from "vite-plus/test";
const require = NodeModule.createRequire(import.meta.url);
const withIosControls = require("./withIosControls.cjs");
const withWidgetLogoAsset = require("./withWidgetLogoAsset.cjs");
const withWidgets = require("expo-widgets/app.plugin.js").default;
it.each(["t3code", "t3code-dev", "t3code-preview"])(
"adds iOS controls and the T3 symbol to the Expo widget bundle using %s",
async (scheme) => {
const root = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-task-control-"));
try {
NodeFS.writeFileSync(NodePath.join(root, "Podfile"), 'target "T3Code" do\nend\n');
NodeFS.mkdirSync(NodePath.join(root, "assets/widget"), { recursive: true });
NodeFS.copyFileSync(
NodePath.join(import.meta.dirname, "../assets/widget/T3Mark.svg"),
NodePath.join(root, "assets/widget/T3Mark.svg"),
);
const config = withWidgets(
withIosControls(
withWidgetLogoAsset({
name: "T3 Code",
slug: "t3-code",
scheme,
_internal: { projectRoot: root },
ios: { bundleIdentifier: "com.t3tools.t3code" },
}),
),
{
widgets: [
{
name: "SubscriptionUsage",
displayName: "Subscription usage",
description: "Usage",
ios: { supportedFamilies: ["systemSmall"] },
},
],
},
);
await config.mods.ios.dangerous({
...config,
modRequest: { projectRoot: root, platformProjectRoot: root, platform: "ios" },
});
const widgetRoot = NodePath.join(root, "ExpoWidgetsTarget");
const index = NodeFS.readFileSync(NodePath.join(widgetRoot, "index.swift"), "utf8");
expect(index).toContain("if #available(iOS 18.0, *)");
expect(index).toContain("T3StartTaskControl()");
expect(index).toContain("T3OpenAppControl()");
expect(index).toContain("SubscriptionUsage()");
expect(index).toContain("WidgetLiveActivity()");
const intent = NodeFS.readFileSync(NodePath.join(root, "T3ControlIntents.swift"), "utf8");
expect(intent).toContain(`"${scheme}://new"`);
expect(NodeFS.readFileSync(NodePath.join(widgetRoot, "T3ControlIntents.swift"), "utf8")).toBe(
intent,
);
expect(
NodeFS.readFileSync(NodePath.join(widgetRoot, "T3StartTaskControl.swift"), "utf8"),
).toContain("ControlWidgetButton(action: T3StartTaskIntent())");
expect(
NodeFS.readFileSync(NodePath.join(widgetRoot, "T3OpenAppControl.swift"), "utf8"),
).toContain("ControlWidgetButton(action: T3OpenAppIntent())");
const symbolSet = NodePath.join(widgetRoot, "Assets.xcassets/T3ControlMark.symbolset");
expect(
JSON.parse(NodeFS.readFileSync(NodePath.join(symbolSet, "Contents.json"), "utf8")),
).toMatchObject({
symbols: [{ filename: "T3ControlMark.svg", idiom: "universal" }],
});
expect(NodeFS.readFileSync(NodePath.join(symbolSet, "T3ControlMark.svg"), "utf8")).toContain(
'id="Regular-S"',
);
} finally {
NodeFS.rmSync(root, { recursive: true, force: true });
}
},
);
Original file line number
Diff line number
Diff line change
Expand Up
@@ -6,6 +6,7 @@ const path = require("path");
const fs = require("fs");
const { withDangerousMod, withXcodeProject } = require("expo/config-plugins");
const { addWidgetAssetCatalog } = require("./lib/addWidgetAssetCatalog.cjs");
const { createControlSymbol } = require("./lib/createControlSymbol.cjs");
const TARGET_NAME = "ExpoWidgetsTarget";
const CATALOG_NAME = "Assets.xcassets";
Expand Down
Expand Up
@@ -38,6 +39,19 @@ function withAssetFiles(config) {
fs.writeFileSync(path.join(catalogDir, "Contents.json"), CATALOG_CONTENTS);
fs.writeFileSync(path.join(imageSetDir, "Contents.json"), IMAGE_SET_CONTENTS);
fs.copyFileSync(source, path.join(imageSetDir, SVG_NAME));
const symbolSetDir = path.join(catalogDir, "T3ControlMark.symbolset");
fs.mkdirSync(symbolSetDir, { recursive: true });
fs.writeFileSync(
path.join(symbolSetDir, "Contents.json"),
JSON.stringify({
info: { author: "expo", version: 1 },
symbols: [{ filename: "T3ControlMark.svg", idiom: "universal" }],
}),
);
fs.writeFileSync(
path.join(symbolSetDir, "T3ControlMark.svg"),
createControlSymbol(fs.readFileSync(source, "utf8")),
);
return cfg;
},
]);
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -192,6 +192,12 @@ Claude quotas. Tap it to open **Usage → Limits**; on Android this works while
the background, otherwise open the app from the launcher. On iOS, use **Edit Widget** to choose
Session, Weekly, or both for each provider. Reopen T3 to refresh expired readings.
## Start a task from Control Center
On iOS 18 or later, open Control Center and choose **Add a Control**.
Find T3 Code and add **Start a task**. Tap the control to open the project chooser for a new task.
Add **Open T3 Code** to open the app without starting a task.
## Keyboard shortcuts
On web and desktop, open Usage from the command palette. While on Usage,
Expand Down
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.