Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3787b55ca5 | ||
|
|
1f16f5dd44 | ||
|
|
e7cfb3dbd9 | ||
|
|
b21e74307e | ||
|
|
aebf253226 | ||
|
|
b7f354cd12 | ||
|
|
5f93ad815e | ||
|
|
39945c5e99 | ||
|
|
9be4ee4225 | ||
|
|
8c20c3d3a6 | ||
|
|
9b97fb8c32 | ||
|
|
cef9f28dfd | ||
|
|
96d5ae40e1 | ||
|
|
8f64937367 | ||
|
|
441de85b82 | ||
|
|
7277ecf589 | ||
|
|
2a8cc22ff9 | ||
|
|
72c933ca61 | ||
|
|
68d834cd72 | ||
|
|
e6adb35e5b | ||
|
|
d03e9493f0 | ||
|
|
dc01018105 | ||
|
|
8efd06d2b5 | ||
|
|
ac6321aa3e | ||
|
|
e54429fa3b | ||
|
|
47f6e5a890 | ||
|
|
dd89b87aea | ||
|
|
d47e42401c | ||
|
|
39511a3224 | ||
|
|
1b7bbe4b8a | ||
|
|
00c221a805 |
@@ -9,6 +9,10 @@ on:
|
|||||||
- 'v*'
|
- 'v*'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: build
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
increment-version:
|
increment-version:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -76,6 +80,13 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
node-version: '22'
|
node-version: '22'
|
||||||
|
|
||||||
|
- name: Cache npm packages
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json', 'cinny/package-lock.json') }}
|
||||||
|
restore-keys: ${{ runner.os }}-npm-
|
||||||
|
|
||||||
- name: Setup Java
|
- name: Setup Java
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v4
|
||||||
with:
|
with:
|
||||||
@@ -88,6 +99,15 @@ jobs:
|
|||||||
# Google removed the legacy `tools` package; v3 still tries to install it.
|
# Google removed the legacy `tools` package; v3 still tries to install it.
|
||||||
packages: platform-tools
|
packages: platform-tools
|
||||||
|
|
||||||
|
- name: Cache Gradle
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.gradle/caches
|
||||||
|
~/.gradle/wrapper/dists
|
||||||
|
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
|
||||||
|
restore-keys: ${{ runner.os }}-gradle-
|
||||||
|
|
||||||
- name: Install dependencies (root)
|
- name: Install dependencies (root)
|
||||||
run: npm ci --prefer-offline
|
run: npm ci --prefer-offline
|
||||||
|
|
||||||
|
|||||||
@@ -377,29 +377,74 @@ class MatrixSyncService : Service() {
|
|||||||
val isMessageLike =
|
val isMessageLike =
|
||||||
eventType == "m.room.message" ||
|
eventType == "m.room.message" ||
|
||||||
eventType == "m.room.encrypted" ||
|
eventType == "m.room.encrypted" ||
|
||||||
eventType == "m.sticker"
|
eventType == "m.sticker" ||
|
||||||
|
eventType == "m.reaction"
|
||||||
if (!isMessageLike) continue
|
if (!isMessageLike) continue
|
||||||
if (sender.isNotBlank() && sender == myUserId) continue
|
if (sender.isNotBlank() && sender == myUserId) continue
|
||||||
if (eventId.isNotBlank() && !shownEventIds.add(eventId)) continue
|
if (eventId.isNotBlank() && !shownEventIds.add(eventId)) continue
|
||||||
|
|
||||||
val content = event.optJSONObject("content") ?: JSONObject()
|
val content = event.optJSONObject("content") ?: JSONObject()
|
||||||
|
|
||||||
|
// Reactions have no media, so use the emoji as the icon and quote the
|
||||||
|
// reacted-to message as the body.
|
||||||
|
if (eventType == "m.reaction") {
|
||||||
|
val relates = content.optJSONObject("m.relates_to")
|
||||||
|
val key = relates?.optString("key").orEmpty()
|
||||||
|
if (key.isBlank()) continue
|
||||||
|
val parentEventId = relates?.optString("event_id").orEmpty()
|
||||||
|
val snippet =
|
||||||
|
if (parentEventId.isNotBlank())
|
||||||
|
fetchEventBodySnippet(homeserver, token, roomId, parentEventId)
|
||||||
|
else ""
|
||||||
|
val reactionBody =
|
||||||
|
if (snippet.isNotBlank()) "reacted with $key to \"$snippet\""
|
||||||
|
else "reacted with $key"
|
||||||
|
|
||||||
|
val profile = try {
|
||||||
|
resolveProfile(sender, homeserver, token)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.w(TAG, "profile fetch failed: ${e.message}")
|
||||||
|
UserProfile(sender.substringAfter("@").substringBefore(":").ifBlank { "Someone" }, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.i(TAG, "notify room=$roomId type=$eventType sender=$sender")
|
||||||
|
showMessageNotification(
|
||||||
|
nm,
|
||||||
|
roomId,
|
||||||
|
profile.displayName,
|
||||||
|
reactionBody,
|
||||||
|
renderEmojiBitmap(key),
|
||||||
|
null,
|
||||||
|
resolveGroupInfo(roomId, notifyCtx),
|
||||||
|
)
|
||||||
|
notifiedForRoom = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
val encrypted = eventType == "m.room.encrypted"
|
val encrypted = eventType == "m.room.encrypted"
|
||||||
|
val msgtype = content.optString("msgtype")
|
||||||
|
val rawBody = content.optString("body")
|
||||||
val body = when {
|
val body = when {
|
||||||
encrypted -> "Encrypted message"
|
encrypted -> "Encrypted message"
|
||||||
eventType == "m.sticker" -> "Sticker"
|
eventType == "m.sticker" -> "Sticker"
|
||||||
else -> {
|
else -> when (msgtype) {
|
||||||
val msgtype = content.optString("msgtype")
|
"m.image" -> "Photo"
|
||||||
val rawBody = content.optString("body")
|
"m.video" -> rawBody.ifBlank { "Video" }
|
||||||
when (msgtype) {
|
"m.audio" -> rawBody.ifBlank { "Audio" }
|
||||||
"m.image" -> "Photo"
|
"m.file" -> rawBody.ifBlank { "File" }
|
||||||
"m.video" -> rawBody.ifBlank { "Video" }
|
else -> rawBody.takeIf { it.isNotBlank() }
|
||||||
"m.audio" -> rawBody.ifBlank { "Audio" }
|
|
||||||
"m.file" -> rawBody.ifBlank { "File" }
|
|
||||||
else -> rawBody.takeIf { it.isNotBlank() }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} ?: continue
|
} ?: continue
|
||||||
|
|
||||||
|
// Fetch an inline preview for image/sticker events. Plaintext only —
|
||||||
|
// encrypted media can't be decrypted inside the raw-sync listener.
|
||||||
|
val inlineImage =
|
||||||
|
if (!encrypted && (msgtype == "m.image" || eventType == "m.sticker")) {
|
||||||
|
resolveInlineImage(content, homeserver, token)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val profile = try {
|
val profile = try {
|
||||||
resolveProfile(sender, homeserver, token)
|
resolveProfile(sender, homeserver, token)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -414,7 +459,7 @@ class MatrixSyncService : Service() {
|
|||||||
profile.displayName,
|
profile.displayName,
|
||||||
body,
|
body,
|
||||||
profile.avatar,
|
profile.avatar,
|
||||||
null,
|
inlineImage,
|
||||||
resolveGroupInfo(roomId, notifyCtx),
|
resolveGroupInfo(roomId, notifyCtx),
|
||||||
)
|
)
|
||||||
notifiedForRoom = true
|
notifiedForRoom = true
|
||||||
@@ -580,6 +625,25 @@ class MatrixSyncService : Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Fetch the body of the event a reaction points at, as a short single-line snippet. */
|
||||||
|
private fun fetchEventBodySnippet(
|
||||||
|
homeserver: String,
|
||||||
|
token: String,
|
||||||
|
roomId: String,
|
||||||
|
eventId: String,
|
||||||
|
maxLength: Int = 60,
|
||||||
|
): String {
|
||||||
|
val obj = fetchJson(
|
||||||
|
"$homeserver/_matrix/client/v3/rooms/${urlEncode(roomId)}/event/${urlEncode(eventId)}",
|
||||||
|
token,
|
||||||
|
) ?: return ""
|
||||||
|
val content = obj.optJSONObject("content") ?: return ""
|
||||||
|
val rawBody = content.optString("body")
|
||||||
|
if (rawBody.isBlank()) return ""
|
||||||
|
val trimmed = rawBody.replace(Regex("\\s+"), " ").trim()
|
||||||
|
return if (trimmed.length > maxLength) trimmed.substring(0, maxLength) + "…" else trimmed
|
||||||
|
}
|
||||||
|
|
||||||
private fun resolveProfile(mxid: String, homeserver: String, token: String): UserProfile {
|
private fun resolveProfile(mxid: String, homeserver: String, token: String): UserProfile {
|
||||||
val cachedName = displayNameCache[mxid]
|
val cachedName = displayNameCache[mxid]
|
||||||
if (cachedName != null) return UserProfile(cachedName, avatarCache[mxid])
|
if (cachedName != null) return UserProfile(cachedName, avatarCache[mxid])
|
||||||
@@ -678,6 +742,37 @@ class MatrixSyncService : Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve an inline preview bitmap for an image/sticker event content.
|
||||||
|
* Prefers a small thumbnail (keeps the notification light), falling back to the
|
||||||
|
* full download. Only works for plaintext events — encrypted media can't be
|
||||||
|
* decrypted inside the raw-sync listener.
|
||||||
|
*/
|
||||||
|
private fun resolveInlineImage(
|
||||||
|
content: JSONObject,
|
||||||
|
homeserver: String,
|
||||||
|
token: String,
|
||||||
|
): Bitmap? {
|
||||||
|
val info = content.optJSONObject("info")
|
||||||
|
val thumbnailMxc =
|
||||||
|
info?.optString("thumbnail_url")?.takeIf { it.startsWith("mxc://") }
|
||||||
|
?: info?.optJSONObject("thumbnail_file")?.optString("url")?.takeIf { it.startsWith("mxc://") }
|
||||||
|
if (thumbnailMxc != null) {
|
||||||
|
for (url in mxcToThumbnailUrls(thumbnailMxc, homeserver, 512)) {
|
||||||
|
downloadBitmap(url, token)?.let { return it }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val fullMxc =
|
||||||
|
content.optString("url").takeIf { it.startsWith("mxc://") }
|
||||||
|
?: content.optJSONObject("file")?.optString("url")?.takeIf { it.startsWith("mxc://") }
|
||||||
|
if (fullMxc != null) {
|
||||||
|
for (url in mxcToDownloadUrls(fullMxc, homeserver)) {
|
||||||
|
downloadBitmap(url, token)?.let { return it }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
private data class NotificationGroupInfo(
|
private data class NotificationGroupInfo(
|
||||||
val groupId: String,
|
val groupId: String,
|
||||||
val groupName: String,
|
val groupName: String,
|
||||||
@@ -1126,6 +1221,25 @@ class MatrixSyncService : Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Render a reaction emoji to a bitmap so it can be used as the notification icon. */
|
||||||
|
fun renderEmojiBitmap(emoji: String): Bitmap? {
|
||||||
|
return try {
|
||||||
|
val size = 128
|
||||||
|
val bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888)
|
||||||
|
val canvas = Canvas(bitmap)
|
||||||
|
val paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||||
|
paint.textSize = size * 0.7f
|
||||||
|
paint.textAlign = Paint.Align.CENTER
|
||||||
|
val fontMetrics = paint.fontMetrics
|
||||||
|
val y = size / 2f - (fontMetrics.ascent + fontMetrics.descent) / 2f
|
||||||
|
canvas.drawText(emoji, size / 2f, y, paint)
|
||||||
|
bitmap
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.w(TAG, "Failed to render emoji icon: ${e.message}")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Crop a bitmap into a circle for the notification avatar slot. */
|
/** Crop a bitmap into a circle for the notification avatar slot. */
|
||||||
fun toCircularBitmap(bitmap: Bitmap): Bitmap {
|
fun toCircularBitmap(bitmap: Bitmap): Bitmap {
|
||||||
val size = minOf(bitmap.width, bitmap.height)
|
val size = minOf(bitmap.width, bitmap.height)
|
||||||
|
|||||||
+1
-1
Submodule cinny updated: 47979718eb...f0495cccca
@@ -6,16 +6,8 @@ export const Editor = style([
|
|||||||
{
|
{
|
||||||
backgroundColor: color.SurfaceVariant.Container,
|
backgroundColor: color.SurfaceVariant.Container,
|
||||||
color: color.SurfaceVariant.OnContainer,
|
color: color.SurfaceVariant.OnContainer,
|
||||||
boxShadow: `inset 0 0 0 ${config.borderWidth.B300} ${color.SurfaceVariant.ContainerLine}`,
|
borderTop: `${config.borderWidth.B300} solid ${color.SurfaceVariant.ContainerLine}`,
|
||||||
borderRadius: config.radii.R400,
|
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
selectors: {
|
|
||||||
// Keyboard-flush dock: only a top edge so the input can sit on the IME.
|
|
||||||
'[data-composer-flush="true"] &': {
|
|
||||||
borderRadius: 0,
|
|
||||||
boxShadow: `inset 0 ${config.borderWidth.B300} 0 0 ${color.SurfaceVariant.ContainerLine}`,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ export function RoomView({ room, eventId }: { room: Room; eventId?: string }) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const flushComposer = immersive;
|
const flushComposer = immersive;
|
||||||
const composerPadding = flushComposer ? '0' : `0 ${config.space.S400}`;
|
const composerPadding = '0';
|
||||||
const showHeader = !immersive;
|
const showHeader = !immersive;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import React, { useEffect } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { MatrixClient } from 'matrix-js-sdk';
|
import { MatrixClient } from 'matrix-js-sdk';
|
||||||
|
import * as lucide from 'lucide-react';
|
||||||
import { Plugin, createPluginContext } from '@paarrot/plugin-manager';
|
import { Plugin, createPluginContext } from '@paarrot/plugin-manager';
|
||||||
import { pluginMarketplaceManager, pluginRegistry } from './PluginAPI';
|
import { pluginMarketplaceManager, pluginRegistry } from './PluginAPI';
|
||||||
import { sendNotification } from '../../../utils/tauri';
|
import { sendNotification } from '../../../utils/tauri';
|
||||||
@@ -80,6 +81,7 @@ export function PluginLoader({ matrixClient, children }: PluginLoaderProps) {
|
|||||||
matrixClient.off(eventType as any, handler as any),
|
matrixClient.off(eventType as any, handler as any),
|
||||||
},
|
},
|
||||||
React,
|
React,
|
||||||
|
lucide,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('[PluginLoader] compatContext.React:', !!compatContext.React);
|
console.log('[PluginLoader] compatContext.React:', !!compatContext.React);
|
||||||
|
|||||||
@@ -104,14 +104,52 @@ async function waitForEventDecryption(mx: MatrixClient, mEvent: MatrixEvent) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Short, single-line snippet of an event's body for use inside a notification. */
|
||||||
|
function eventBodySnippet(mEvent: MatrixEvent, maxLength = 60): string {
|
||||||
|
const content = mEvent.getClearContent() ?? mEvent.getContent();
|
||||||
|
const rawBody = typeof content.body === 'string' ? content.body : '';
|
||||||
|
if (!rawBody) return '';
|
||||||
|
const trimmed = rawBody.replace(/\s+/g, ' ').trim();
|
||||||
|
return trimmed.length > maxLength ? `${trimmed.slice(0, maxLength)}…` : trimmed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Render a reaction emoji to a PNG base64 string so it can be used as the notification icon. */
|
||||||
|
async function renderEmojiToBase64(emoji: string): Promise<string | undefined> {
|
||||||
|
try {
|
||||||
|
const size = 128;
|
||||||
|
const canvas = document.createElement('canvas');
|
||||||
|
canvas.width = size;
|
||||||
|
canvas.height = size;
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
if (!ctx) return undefined;
|
||||||
|
|
||||||
|
ctx.font = `${Math.floor(size * 0.7)}px "Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji",sans-serif`;
|
||||||
|
ctx.textBaseline = 'middle';
|
||||||
|
ctx.textAlign = 'center';
|
||||||
|
ctx.fillText(emoji, size / 2, size / 2);
|
||||||
|
|
||||||
|
const dataUrl = canvas.toDataURL('image/png');
|
||||||
|
return dataUrl.split(',')[1];
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('[Notifications] Failed to render emoji icon:', err);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Build a human-readable notification body from (possibly decrypted) event content. */
|
/** Build a human-readable notification body from (possibly decrypted) event content. */
|
||||||
function notificationBodyFromEvent(mEvent: MatrixEvent): string | undefined {
|
function notificationBodyFromEvent(mx: MatrixClient, mEvent: MatrixEvent): string | undefined {
|
||||||
const content = mEvent.getClearContent() ?? mEvent.getContent();
|
const content = mEvent.getClearContent() ?? mEvent.getContent();
|
||||||
const eventType = mEvent.getType();
|
const eventType = mEvent.getType();
|
||||||
|
|
||||||
if (eventType === 'm.reaction') {
|
if (eventType === 'm.reaction') {
|
||||||
const reactionKey = content['m.relates_to']?.key;
|
const relates = content['m.relates_to'];
|
||||||
return reactionKey ? `reacted with ${reactionKey}` : 'reacted to a message';
|
const reactionKey = relates?.key;
|
||||||
|
const parent = relates?.event_id ? mx.getCachedEventById(relates.event_id) : undefined;
|
||||||
|
const snippet = parent ? eventBodySnippet(parent) : '';
|
||||||
|
|
||||||
|
if (reactionKey && snippet) return `reacted with ${reactionKey} to "${snippet}"`;
|
||||||
|
if (reactionKey) return `reacted with ${reactionKey}`;
|
||||||
|
return 'reacted to a message';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eventType === 'm.room.encrypted' || mEvent.isDecryptionFailure()) {
|
if (eventType === 'm.room.encrypted' || mEvent.isDecryptionFailure()) {
|
||||||
@@ -684,12 +722,26 @@ function MessageNotifications() {
|
|||||||
: Promise.resolve(undefined),
|
: Promise.resolve(undefined),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const messageBody = notificationBodyFromEvent(mEvent);
|
// Reactions have no media, so render the reaction emoji as the notification icon.
|
||||||
|
let finalIconBase64 = iconBase64;
|
||||||
|
let finalRoomAvatar = roomAvatar;
|
||||||
|
if (mEvent.getType() === 'm.reaction') {
|
||||||
|
const emoji = (mEvent.getClearContent() ?? mEvent.getContent())['m.relates_to']?.key;
|
||||||
|
if (emoji) {
|
||||||
|
const emojiBase64 = await renderEmojiToBase64(emoji);
|
||||||
|
if (emojiBase64) {
|
||||||
|
finalIconBase64 = emojiBase64;
|
||||||
|
finalRoomAvatar = `data:image/png;base64,${emojiBase64}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const messageBody = notificationBodyFromEvent(mx, mEvent);
|
||||||
|
|
||||||
notify({
|
notify({
|
||||||
roomName: room.name ?? 'Unknown',
|
roomName: room.name ?? 'Unknown',
|
||||||
roomAvatar,
|
roomAvatar: finalRoomAvatar,
|
||||||
iconBase64,
|
iconBase64: finalIconBase64,
|
||||||
bigPictureBase64,
|
bigPictureBase64,
|
||||||
username,
|
username,
|
||||||
messageBody,
|
messageBody,
|
||||||
|
|||||||
+2
-1
@@ -1,12 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "paarrot",
|
"name": "paarrot",
|
||||||
"version": "4.11.171",
|
"version": "4.11.186",
|
||||||
"description": "Paarrot - A Matrix client based on Cinny",
|
"description": "Paarrot - A Matrix client based on Cinny",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18.0.0"
|
"node": ">=18.0.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"apply-overlay": "node scripts/apply-overlay.mjs",
|
"apply-overlay": "node scripts/apply-overlay.mjs",
|
||||||
|
"push": "bash scripts/push.sh",
|
||||||
"android:prepare": "cd cinny && npm run build && cd .. && npx cap sync android",
|
"android:prepare": "cd cinny && npm run build && cd .. && npx cap sync android",
|
||||||
"android:open": "npx cap open android",
|
"android:open": "npx cap open android",
|
||||||
"android:run": "npx cap run android",
|
"android:run": "npx cap run android",
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ if (cinnyStatus.trim()) {
|
|||||||
// Ensure android/ junction is excluded from the cinny git view — otherwise
|
// Ensure android/ junction is excluded from the cinny git view — otherwise
|
||||||
// `git stash -u` would traverse the junction into the root android/ directory
|
// `git stash -u` would traverse the junction into the root android/ directory
|
||||||
// and delete files there when the stash is created.
|
// and delete files there when the stash is created.
|
||||||
const cinnyExclude = join(CINNY, '.git', 'info', 'exclude');
|
const gitDir = resolve(CINNY, execSync('git rev-parse --git-dir', { cwd: CINNY, encoding: 'utf8' }).trim());
|
||||||
|
const cinnyExclude = join(gitDir, 'info', 'exclude');
|
||||||
const excludeContent = existsSync(cinnyExclude) ? readFileSync(cinnyExclude, 'utf8') : '';
|
const excludeContent = existsSync(cinnyExclude) ? readFileSync(cinnyExclude, 'utf8') : '';
|
||||||
if (!excludeContent.includes('android/')) {
|
if (!excludeContent.includes('android/')) {
|
||||||
writeFileSync(cinnyExclude, excludeContent + (excludeContent.endsWith('\n') || !excludeContent ? '' : '\n') + 'android/\n', 'utf8');
|
writeFileSync(cinnyExclude, excludeContent + (excludeContent.endsWith('\n') || !excludeContent ? '' : '\n') + 'android/\n', 'utf8');
|
||||||
|
|||||||
Executable
+197
@@ -0,0 +1,197 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Commit working changes, rebase onto the tracked remote branch, and push.
|
||||||
|
# Stashes leftover dirty files (common: cinny submodule pointer, gradlew +x)
|
||||||
|
# around the pull/push so they don't block rebase.
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# scripts/push.sh -m "commit message" [path ...]
|
||||||
|
# scripts/push.sh "commit message" [path ...]
|
||||||
|
#
|
||||||
|
# If no paths are given:
|
||||||
|
# - uses already-staged files, or
|
||||||
|
# - auto-stages modified tracked files + overlay/android/scripts/config changes
|
||||||
|
# (skips cinny submodule + android/gradlew unless -a)
|
||||||
|
#
|
||||||
|
# Flags:
|
||||||
|
# -m MSG Commit message
|
||||||
|
# -a Include noisy paths (cinny, android/gradlew) when auto-staging
|
||||||
|
# -n Dry run: show what would be committed, then exit
|
||||||
|
# -h Help
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||||
|
cd "$ROOT"
|
||||||
|
|
||||||
|
MSG=""
|
||||||
|
INCLUDE_NOISE=0
|
||||||
|
DRY_RUN=0
|
||||||
|
PATHS=()
|
||||||
|
STAGED_PATHS=()
|
||||||
|
|
||||||
|
NOISE_PATHS=(
|
||||||
|
"cinny"
|
||||||
|
"android/gradlew"
|
||||||
|
)
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
awk '
|
||||||
|
NR == 1 { next }
|
||||||
|
/^#/ { sub(/^# ?/, ""); print; next }
|
||||||
|
{ exit }
|
||||||
|
' "$0"
|
||||||
|
exit "${1:-0}"
|
||||||
|
}
|
||||||
|
|
||||||
|
is_noise() {
|
||||||
|
local p="$1"
|
||||||
|
for n in "${NOISE_PATHS[@]}"; do
|
||||||
|
[[ "$p" == "$n" || "$p" == "./$n" ]] && return 0
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
should_autostage() {
|
||||||
|
local p="$1"
|
||||||
|
case "$p" in
|
||||||
|
overlay/*|android/*|scripts/*|package.json|package-lock.json|.gitea/*|config.json|capacitor.config.json)
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
# Modified tracked files outside those dirs are fine; skip random untracked junk.
|
||||||
|
git ls-files --error-unmatch -- "$p" >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
-m)
|
||||||
|
[[ $# -ge 2 ]] || { echo "error: -m needs a message" >&2; exit 1; }
|
||||||
|
MSG="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
-a)
|
||||||
|
INCLUDE_NOISE=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-n)
|
||||||
|
DRY_RUN=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-h|--help)
|
||||||
|
usage 0
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
PATHS+=("$@")
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
-*)
|
||||||
|
echo "error: unknown flag: $1" >&2
|
||||||
|
usage 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
if [[ -z "$MSG" ]]; then
|
||||||
|
MSG="$1"
|
||||||
|
else
|
||||||
|
PATHS+=("$1")
|
||||||
|
fi
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -z "$MSG" ]]; then
|
||||||
|
echo "error: commit message required" >&2
|
||||||
|
usage 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||||
|
echo "error: not a git repo" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
|
||||||
|
if [[ "$BRANCH" == "HEAD" ]]; then
|
||||||
|
echo "error: detached HEAD — check out a branch first" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
REMOTE="$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null || true)"
|
||||||
|
if [[ -n "$REMOTE" ]]; then
|
||||||
|
REMOTE_NAME="${REMOTE%%/*}"
|
||||||
|
REMOTE_BRANCH="${REMOTE#*/}"
|
||||||
|
else
|
||||||
|
REMOTE_NAME="origin"
|
||||||
|
REMOTE_BRANCH="$BRANCH"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ${#PATHS[@]} -gt 0 ]]; then
|
||||||
|
STAGED_PATHS=("${PATHS[@]}")
|
||||||
|
git add -- "${STAGED_PATHS[@]}"
|
||||||
|
elif git diff --cached --quiet; then
|
||||||
|
mapfile -t candidates < <({
|
||||||
|
git diff --name-only --diff-filter=ACMRD
|
||||||
|
git ls-files --others --exclude-standard
|
||||||
|
} | awk 'NF && !seen[$0]++')
|
||||||
|
|
||||||
|
for p in "${candidates[@]}"; do
|
||||||
|
[[ -z "$p" ]] && continue
|
||||||
|
if [[ "$INCLUDE_NOISE" -eq 0 ]] && is_noise "$p"; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if should_autostage "$p"; then
|
||||||
|
STAGED_PATHS+=("$p")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ ${#STAGED_PATHS[@]} -eq 0 ]]; then
|
||||||
|
echo "error: nothing to commit (pass paths, or stage files first)" >&2
|
||||||
|
git status -sb
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
git add -- "${STAGED_PATHS[@]}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if git diff --cached --quiet; then
|
||||||
|
echo "error: nothing staged to commit" >&2
|
||||||
|
git status -sb
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "==> branch $BRANCH (tracking ${REMOTE_NAME}/${REMOTE_BRANCH})"
|
||||||
|
echo "==> staged:"
|
||||||
|
git diff --cached --stat
|
||||||
|
|
||||||
|
if [[ "$DRY_RUN" -eq 1 ]]; then
|
||||||
|
if [[ ${#STAGED_PATHS[@]} -gt 0 ]]; then
|
||||||
|
git reset -q HEAD -- "${STAGED_PATHS[@]}"
|
||||||
|
fi
|
||||||
|
echo "==> dry run; not committing or pushing"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
STASHED=0
|
||||||
|
if [[ -n "$(git diff --name-only)" || -n "$(git ls-files --others --exclude-standard)" ]]; then
|
||||||
|
echo "==> stashing leftover dirty files"
|
||||||
|
git stash push --keep-index -u -m "push.sh leftover before ${BRANCH} push"
|
||||||
|
STASHED=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "==> commit"
|
||||||
|
git commit -m "$MSG"
|
||||||
|
|
||||||
|
echo "==> pull --rebase ${REMOTE_NAME}/${REMOTE_BRANCH}"
|
||||||
|
git pull --rebase "$REMOTE_NAME" "$REMOTE_BRANCH"
|
||||||
|
|
||||||
|
echo "==> push ${REMOTE_NAME} HEAD"
|
||||||
|
git push "$REMOTE_NAME" HEAD
|
||||||
|
|
||||||
|
if [[ "$STASHED" -eq 1 ]]; then
|
||||||
|
echo "==> restoring stash"
|
||||||
|
git stash pop
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "==> done"
|
||||||
|
git status -sb
|
||||||
|
git log -1 --oneline
|
||||||
Reference in New Issue
Block a user