Archive for May 23, 2022

Monday, May 23, 2022

Combine’s .collect(.byTime) Timer

Jesse Grosjean:

The biggest bug in Bike’s 1.0 release was excessive CPU use while in background.

[…]

First, I didn’t realize that each time you use .collect(.byTime) you are setting up a new repeating timer. I had expected a timer was involved, but thought it would only get scheduled when new items were coming into the publisher. Nope, it’s repeating once the pipeline is setup.

[…]

I’ve posted a .collect(.byTime) replacement (for my use case) here. It solves the problem by only scheduling on the runloop once per group of incoming results.

Previously:

How to Open a Window in SwiftUI

Rob N:

I’d like to show a second window with different content in a SwiftUI app on macOS. I can’t find any documentation on this.

Malcolm Hall (tweet, forum):

In your ContentView create a button and open a URL for your app and another View e.g. Viewer to be shown in the window we will open[…]

[…]

In your App add another WindowGroup for your viewer and set it to enable handling of external launch events (an internal event in our case).

[…]

Now in Project->Info->URL Types type in myappname in the URL Schemes field (and the identifier field too) to register our app with the system.

Tony Arnold:

Is that a workaround? That’s a workaround for missing API, right? 😳

Malcolm Hall:

No, its a declarative state-driven API that handles the reason why you would want a new window. You aren’t going to get an imperative open window in SwiftUI because that’s not how it is designed.

Marcin Krzyzanowski:

I’m not convinced this is designed. It’s more like something that happens, but doesn’t really is well thought for the scenario where the app needs to open multiple windows. URL cannot be the way. It’s missing window state management. Windows are hierarchical. This is not.

It’s great that there is a way to do this without calling into AppKit, but using URLs seems gross.

Khoa Pham:

A common trick is to use an NSViewRepresentable to get underlying view.window and attach this to our SwiftUI view

[…]

For a common macOS SwiftUI app with a search bar on the toolbar and a normal settings screen, here’s how I usually do

Setup NSWindow programmatically

Previously:

Update (2022-07-12): Natalia Panferova (tweet):

In macOS 13 we finally have a way to programmatically present a window in SwiftUI. We can call the new openWindow action from the environment and pass it a scene id or a value.

Previously:

Proposed EU DMA: USB-C, Messaging, NFC

European Parliament:

Mobile phones, tablets, digital cameras, headphones and headsets, handheld videogame consoles and portable speakers, rechargeable via a wired cable, would have to be equipped with a USB Type-C port, regardless of the manufacturer. Exemptions would apply only for devices that are too small to have a USB Type-C port, such as smart watches, health trackers, and some sports equipment.

Via Nick Heer:

The straight-line way of reading this is that future iPhones and iPads will have to have a USB-C port instead of a Lightning one.

Casey Newton:

The act applies to what it calls “gatekeepers” — defined as any platform that has a market capitalization of €75 billion, or more than €7.5 billion in European revenue. So: yes to WhatsApp and iMessage; no to Signal and Telegram.

[…]

Disdain for the new requirements is not universal; Matrix, a nonprofit organization working to build an open-source standard for encrypted communication, published a blog post Friday explaining some possible technical paths forward.

But it’s clear that, to the extent that there might be a way for services like iMessage and WhatsApp to interoperate and preserve encryption, that way has yet to be invented.

Via Nick Heer:

To be clear, it does not appear that the draft law mandates the creation of no privacy or security risks; the segment posted by Benedict Evans — the full draft text is currently confidential — says platform providers must create a “high level of security and personal data protection”. It is about finding an appropriate level of risk with the caveat that it will never get to zero. But the core of the question seems correct: is there a way to make encrypted messaging services work together while ensuring negligible difference in security and privacy levels?

[…]

Remember Adium? That is a great piece of software I have not touched in about ten years as phone-centred messaging clients have replaced desktop-based ones. Something like that could be possible again.

Hartley Charlton:

The latest provisional agreement sets out plans to establish a “High-Level Group” of central European digital regulators to coordinate national regulators across EU member states and requires “gatekeepers” to create an independent “compliance function.” The new group must include compliance officers to monitor their company’s compliance with EU legislation using sufficient authority, resources, and access to management, and be headed by an “independent senior manager with distinct responsibility for the compliance function.” The rule would effectively require companies like Apple to set up an internal department dedicated to meeting pro-competition regulations.

In addition, new rules specifically targeted to address companies like Apple that have “a dual role” with control over both hardware and software look to allow any developer to gain access to any existing hardware feature, such as “near-field communication technology, secure elements and processors, authentication mechanisms, and the software used to control those technologies.” This could have major implications for the level of integration that developers can achieve on Apple platforms, such as allowing contactless payment services to operate on the iPhone and Apple Watch just like Apple Pay.

John Gruber:

This is bananas. All third party developers get control over the secure enclave and the software that controls it?

[…]

This is profoundly anti-consumer. Consumers aren’t asking for any of this shit. Actual people love their phones more than their computers — whether Macs or PCs — not despite the fact that their phones are tightly controlled consoles, but because they are tightly controlled consoles. These regulators don’t see it that way, because they’re idiots. They think they can legislate their way to a world where the iPhone (and Android, which is also console-like) remains far safer and more reliable than PCs while mandating that all the protections that have made them far safer and more reliable than PCs be removed. It’s absurd.

I think this is conflating a lot of different things. The main reasons that phones are safer and more reliable are sandboxing (so apps run mostly independently from each other and the system) and the hidden file system (so users can’t mess things up). Those would remain in place. I still think it’s far from clear that adding an API to access NFC would cause harm. The bit about the Secure Enclave strikes me as differing interpretations, like when Microsoft told the court that Internet Explorer couldn’t be removed from Windows because—thinking of the frameworks, not just the app—then it would no longer boot. Obviously, the EU doesn’t want it opened up in a way that would make it useless.

I would imagine though, if this comes to fruition, E.U. citizens are going to wind up buying iPhones that operate very differently from those sold everywhere else in the world, and they will suffer for it.

Steve Troughton-Smith:

Why does Apple see a ‘European’ iPhone variant as an existential threat, but not its stripped-down feature-restricted variant for e.g. China (which it has shipped for a decade)? Because everybody will want one with this unrestricted featureset, of course. Hence the unrelenting PR

Previously:

Five Things You Still Can’t Do With a MacBook Pro

Tim Hardwick:

Unfortunately, the HDMI port that returned isn’t so top-of-the-line – it’s an HDMI 2.0 port instead of an HDMI 2.1 port.

[…]

The SD card slot on the new MacBook Pros supports UHS-II cards, but only up to 250MB/s of data transfer, not the 312MB/s speeds that the standard is theoretically capable of.

[…]

Ethernet Port

[…]

Lenovo, Samsung, Acer, Dell, and HP all offer laptops with 5G connectivity, yet no Mac in Apple’s notebook lineup currently supports the cellular standard.

My suggestions:

  1. Shrink the trackpad.
  2. Add an external power button so that I can turn on the Mac or enter Recovery while in clamshell mode.
  3. Add more USB ports. I have not had good experiences with hubs/docks, even Apple’s own Studio Display. Being able to directly connect more devices in a pinch, or at least not have to plug one hub into another, would help.
  4. Make a first-party Thunderbolt dock. The current ones are pricey, and people still report them being flakey. Maybe this is inherent to the technology, but maybe if Apple made all the pieces (computer, OS, and dock) it would be better able to ensure that they work together.

Previously: