Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

fs.readFileSync not working in SDK 5.0

I have noticed that my settings do not work in 5.0, but worked fine in 4.0. I think the problem is that the fs.readFileSync() function is returning undefined and causing problems. I have pasted my app/simple/device-settings code below.

 

/*
  Responsible for loading, applying and saving settings.
  Requires companion/simple/companion-settings.js
  Callback should be used to update your UI.
*/
import { me } from "appbit";
import { me as device } from "device";
import * as fs from "fs";
import * as messaging from "messaging";

const SETTINGS_TYPE = "cbor";
const SETTINGS_FILE = "settings.cbor";

let settings, onsettingschange;

export function initialize(callback) {
  console.log("init");
  settings = loadSettings();
  onsettingschange = callback;
  onsettingschange(settings);
}

// Received message containing settings data
messaging.peerSocket.addEventListener("message", function(evt) {
  console.log(evt.data.value);
  console.log(settings);
  settings[evt.data.key] = evt.data.value;
  onsettingschange(settings);
})

// Register for the unload event
me.addEventListener("unload", saveSettings);

// Load settings from filesystem
function loadSettings() {
  try {
    console.log("file loaded")
    return fs.readFileSync(SETTINGS_FILE, SETTINGS_TYPE);
  } catch (ex) {
    console.log("no file found")
    return {};
  }
}

// Save settings to the filesystem
function saveSettings() {
  fs.writeFileSync(SETTINGS_FILE, settings, SETTINGS_TYPE);
}
Best Answer
0 Votes
2 REPLIES 2

Has the 'simple' code and its documentation been updated for SDK 5/6? I'm pretty sure that readFileSync still works.

This is a long shot, but I wonder if the old-style import statements might be problematic.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

@Gondwana I am not sure if it has been updated, but something in its infrastructure may not be supported in SDK 5/6. I will look into the import statements.

Best Answer
0 Votes