Skip to content

Commit

Permalink
Merge pull request #19 from jcsalterego/build-0.4.0
Browse files Browse the repository at this point in the history
Version 0.4.0
  • Loading branch information
jcsalterego authored Sep 14, 2024
2 parents 22ac694 + 76f0ae3 commit ce72896
Show file tree
Hide file tree
Showing 13 changed files with 257 additions and 176 deletions.
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ keyboard shortcuts, Dark Mode Sync, and notification badges.

_If you're looking for the official Bluesky Social iOS app, [head on over to the App Store](https://apps.apple.com/us/app/bluesky-social/id6444370199)._

The current release is [**0.3.9**](https://github.com/jcsalterego/Sky.app/releases/latest).
The current release is [**0.4.0**](https://github.com/jcsalterego/Sky.app/releases/latest).

![](Docs/screenshot.png)

Expand All @@ -30,26 +30,26 @@ In Compact Mode:

* `⌘-1` Home
* `⌘-2` Search
* `⌘-3` Feeds
* `⌘-3` Chat
* `⌘-4` Notifications
* `⌘-5` Profile

In Desktop Mode:

* `⌘-1` Home
* `⌘-2` Search
* `⌘-3` Feeds
* `⌘-4` Notifications
* `⌘-5` Lists
* `⌘-6` Moderation
* `⌘-3` Notifications
* `⌘-4` Chat
* `⌘-5` Feed
* `⌘-6` Lists
* `⌘-7` Profile
* `⌘-8` Settings

### Other

* `⌘-,` Settings...
* `⌘-K` Jump To...
* `⌘-T` Open in Browser
* `⌘-⇧-D` Toggle Dark Mode
* `⌘-⇧-C` Copy Share URL
* `^-⌘-⇧-C` Copy Current URL

Expand All @@ -63,6 +63,15 @@ Check for Updates powered by [Sparkle](https://sparkle-project.org).

## Changelog

### 0.4.0

* Add (`⌘-,`) to go to the Settings page
* Fix color scheme sync
* Remove "Toggle Dark Mode" (for now?)
* Notification badges now include unread chat messages
* Fix notification badges
* Fix keybindings and menu items between Compact and Desktop modes

### 0.3.9

* Remove Developer Console [#7](https://github.com/jcsalterego/Sky.app/issues/7)
Expand Down
9 changes: 9 additions & 0 deletions Sky/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {

var lastBadgeCount = 0
var notificationReadStatuses = [String:Int]()
var convoUnreadCounts = [String:Int]()
var firstRun = true

var mutedTermsHits = 0
Expand Down Expand Up @@ -104,12 +105,17 @@ class AppDelegate: NSObject, NSApplicationDelegate {

func clearNotifCounts() {
notificationReadStatuses.removeAll()
convoUnreadCounts.removeAll()
}

func setNotificationReadStatus(uri: String, isRead: Int) {
notificationReadStatuses[uri] = isRead
}

func setConvoUnreadCount(id: String, unreadCount: Int) {
convoUnreadCounts[id] = unreadCount
}

func refreshBadge() {
// NSLog("notificationReadStatuses = \(notificationReadStatuses)")
var totalBadgeCount = 0
Expand All @@ -118,6 +124,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
totalBadgeCount += 1
}
}
for (_, unreadCount) in convoUnreadCounts {
totalBadgeCount += unreadCount
}
if totalBadgeCount != lastBadgeCount {
if totalBadgeCount == 0 {
NSApp.dockTile.badgeLabel = nil
Expand Down
152 changes: 100 additions & 52 deletions Sky/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Sky/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.3.10-pre</string>
<string>0.4.0</string>
<key>CFBundleVersion</key>
<string>0.3.10-pre</string>
<string>0.4.0</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
5 changes: 3 additions & 2 deletions Sky/JsLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ class JsLoader {

class func loadWKUserScript(
_ name: String,
_ context: [String: String] = [:]
_ context: [String: String] = [:],
_ injectionTime: WKUserScriptInjectionTime = .atDocumentStart
) -> WKUserScript {
let source = JsLoader.loadScriptContents(name, context)
return WKUserScript(
source: source,
injectionTime: .atDocumentEnd,
injectionTime: injectionTime,
forMainFrameOnly: false
)
}
Expand Down
27 changes: 24 additions & 3 deletions Sky/ScriptMessageHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ class ScriptMessageHandler: NSObject, WKScriptMessageHandler {

func windowColorSchemeChange(_ message: WKScriptMessage) {
if let messageBody = message.body as? NSDictionary {
if let darkMode = messageBody["darkMode"] as? Int {
if let darkMode = messageBody["darkMode"] as? Int,
let backgroundColor = messageBody["backgroundColor"] as? String
{
if darkMode == 1 {
viewController.updateTitleBar(.dark)
viewController.updateTitleBar(.dark, backgroundColor: backgroundColor)
} else {
viewController.updateTitleBar(.light)
viewController.updateTitleBar(.light, backgroundColor: backgroundColor)
}
}
}
Expand Down Expand Up @@ -82,6 +84,22 @@ class ScriptMessageHandler: NSObject, WKScriptMessageHandler {
}
}

func handleFetchListConversations(_ doc : NSDictionary) {
if let convosList = doc["convos"] as? [NSDictionary] {
var mutedThreadUris: [String] = []
for convo in convosList {
if let convoId = convo["id"] as? String,
let convoUnreadCount = convo["unreadCount"] as? Int
{
AppDelegate.shared.setConvoUnreadCount(
id: convoId, unreadCount: convoUnreadCount
)
}
}
AppDelegate.shared.refreshBadge()
}
}

func fetch(_ message: WKScriptMessage) {
if let messageBody = message.body as? NSDictionary {
if let urlString = messageBody["url"] as? String,
Expand All @@ -90,6 +108,9 @@ class ScriptMessageHandler: NSObject, WKScriptMessageHandler {
if urlString.contains("listNotifications") {
handleFetchListNotifications(response)
}
if urlString.contains("listConvos") {
handleFetchListConversations(response)
}
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions Sky/Scripts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,4 @@ class Scripts {
)
}

static func toggleDarkMode() -> String {
return JsLoader.loadScriptContents(
"Scripts/toggle_dark_mode", [:]
)
}

}
14 changes: 12 additions & 2 deletions Sky/Scripts/hook_fetch.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
$INCLUDE("_filters.js");

async function overrideGet(...args) {
const url = args[0];
let request = args[0];
let url = null;
if (request.constructor.name === "Request") {
url = request.url;
} else if (request.constructor.name === "URL") {
url = request.href;
} else if (request.constructor.name === "String") {
url = request;
} else {
console.warn("Unknown request type", request);
return window._fetch(...args);
}
const response = await window._fetch(...args);
const contentType = response.headers.get("Content-Type");
if (
Expand All @@ -21,7 +32,6 @@ async function overrideGet(...args) {
});

let altered = false;

let isSearch = url.indexOf("https://search.bsky.social/search/posts") === 0;
let featureOrderPosts = localStorage.getItem("featureOrderPosts") === "yes";
let featureHideHomeReplies = localStorage.getItem("featureHideHomeReplies") === "yes";
Expand Down
33 changes: 12 additions & 21 deletions Sky/Scripts/hook_window_color_scheme.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
$INCLUDE("_with_retry");
function setColorScheme(darkMode) {
const DARK_MODE_FOREGROUND = "#79787c";
const DARK_MODE_BACKGROUND = "#000000";
const LIGHT_MODE_FOREGROUND = "#c3c3c3";
const LIGHT_MODE_BACKGROUND = "#fafafa";
function updateColorScheme() {
let background = document.body.style.backgroundColor;
let foreground = document.body.style.color;
let darkMode = false;
if (background === "rgb(255, 255, 255)") {
darkMode = false;
} else {
darkMode = true;
}
window.webkit.messageHandlers.windowColorSchemeChange.postMessage({
darkMode: darkMode,
backgroundColor: background,
});
if (darkMode) {
foreground = DARK_MODE_FOREGROUND;
background = DARK_MODE_BACKGROUND;
} else {
foreground = LIGHT_MODE_FOREGROUND;
background = LIGHT_MODE_BACKGROUND;
}
let rules = [
`::-webkit-scrollbar { width: auto }`,
`::-webkit-scrollbar-track { background: ${background}; }`,
Expand All @@ -24,14 +22,11 @@ function setColorScheme(darkMode) {
for (let rule of rules) {
stylesheet.insertRule(rule, stylesheet.rules.length - 1);
}
elems = Array.from(document.querySelectorAll("div")).filter((div) => {
return div.scrollHeight > window.innerHeight;
});
}

function setColorSchemeChange() {
let done = false;
let elems = Array.from(document.querySelectorAll("#root div div"));
let elems = Array.from(document.querySelectorAll("body"));
if (elems.length > 0) {
let elem = elems[0];
if (elem.dataset.windowColorSchemeObserverSet === undefined) {
Expand All @@ -45,11 +40,7 @@ function setColorSchemeChange() {
let backgroundColor =
window.getComputedStyle(elem).backgroundColor;
if (elem.dataset.lastBackgroundColor !== backgroundColor) {
if (backgroundColor === "rgb(0, 0, 0)") {
setColorScheme(true);
} else {
setColorScheme(false);
}
updateColorScheme();
elem.dataset.lastBackgroundColor = backgroundColor;
break;
}
Expand Down
34 changes: 0 additions & 34 deletions Sky/Scripts/toggle_dark_mode.js

This file was deleted.

1 change: 1 addition & 0 deletions Sky/SkyUrls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ enum SkyUrls {
static let notifications = "\(root)/notifications"
static let moderation = "\(root)/moderation"
static let settings = "\(root)/settings"
static let messages = "\(root)/messages"
}
Loading

0 comments on commit ce72896

Please sign in to comment.