about summary refs log tree commit diff
path: root/modules/expo-bluesky-swiss-army/ios/DevicePrefs/ExpoBlueskyDevicePrefsModule.swift
blob: b13a9fe3faf75c4907d05b653828ffd406acc343 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import ExpoModulesCore

public class ExpoBlueskyDevicePrefsModule: Module {
  func getDefaults(_ useAppGroup: Bool) -> UserDefaults? {
    if useAppGroup {
      return UserDefaults(suiteName: "group.app.bsky")
    } else {
      return UserDefaults.standard
    }
  }

  public func definition() -> ModuleDefinition {
    Name("ExpoBlueskyDevicePrefs")

    AsyncFunction("getStringValueAsync") { (key: String, useAppGroup: Bool) in
      return self.getDefaults(useAppGroup)?.string(forKey: key)
    }

    AsyncFunction("setStringValueAsync") { (key: String, value: String?, useAppGroup: Bool) in
      self.getDefaults(useAppGroup)?.setValue(value, forKey: key)
    }
  }
}