Bike 2.0 Preview Extensions API Questions

A minor question, and no hurry:

This is working as I would expect, and very useful – returning any standard utf8 text content of the clipboard:

const text = bike.clipboard.readText("public.utf8-plain-text");

console.log(text);

In build 2.0 229, however, I notice that if we omit the uti argument, then only an undefined value seems to be returned, even when the public.utf8-plain-text pasteboard is populated.

(From the API files, I think I expected that omitting the argument would result in default selection of the public.utf8-plain-text pasteboard item, if there is one)

Thanks, I’ll fix in next release. I was expecting Javascript to Swift bridge to pass me nil values when not defined… but instead was passing “undefined” string, and that’s the UTI type that I was using to read.

1 Like

What is the best way to check the contents of an AppExtensionContext ?

In an extension which has this in the manifest.json:

"permissions": ["clipboardRead", "clipboardWrite"]

(and in which the clipboard methods are working well)

I tried, probably clumsily, to see a result of this kind of thing in the Safari debug console:

export async function activate(context: AppExtensionContext) {
  console.log(
      "Extension Permissions:", 
       JSON.stringify( context.permissions )
  );

  // ...
}

but perhaps an async activate function doesn’t really get a chance to leave a string in the console ?

This is working for me:

import { AppExtensionContext } from 'bike/app'

export async function activate(context: AppExtensionContext) {
  console.log('Extension Permissions:', context.permissions)
}

Few notes…

  1. The logging also works if I JSON.stringify, but just gives an empty dictionary. The context.permissions is a native object that javascript doesn’t know how to stringify.

  2. I have tried this is the latest preview release, so the difference isn’t because I’m running from Xcode… I tested with the download version

  3. Two potential problems that I can think of … a) Maybe you opened the wrong context from the Safari > Debug menu? (I did on my first test). For example I opened the “bike” context, but my logging code was in “tutorial” context. b) Make sure you are not filtering the log, default log level is “notice” and you won’t see that if you are filtering to only show warnings… Should be that “All” is highlighted above the log.

I’m not sure why you would not see this in your log.

Many thanks – I had mistaken context.permissions for a JS dictionary.

I can see it in Window > Logs Explorer > Script Context


FWIW still not seeing it here in the Safari debugger console:

( I assume that the Logs Explorer message about the name module is not relevant here )

[error] ScriptContext: Thrown Exception: Optional(ReferenceError: Can't find variable: module)


(In any case, not in any sense an impediment to progress – just me stumbling around a bit as I experiment to get a sense of things )

Scratch that, forgive me – perhaps I should have opened the console a few more lines – it’s showing now.

1 Like