Research
Recent Trends in Malicious Packages Targeting Discord
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
tauri-settings
Advanced tools
Readme
A user settings manager for Tauri inspired by electron-settings.
The package is available on npm and can be installed using npm or yarn.
# using npm
npm install tauri-settings
# using yarn
yarn add tauri-settings
# using pnpm
pnpm add tauri-settings
If you haven't installed @tauri-apps/api
then you will have to install it using npm or yarn as this package internally uses the API.
# using npm
npm install @tauri-apps/api
# using yarn
yarn add @tauri-apps/api
The following APIs need to be added to the Tauri allowlist.
{
"allowlist": {
"fs": { // see https://tauri.app/v1/api/config/#fsallowlistconfig
"createDir": true,
"readDir": true,
"readFile": true,
"writeFile": true,
"scope": ["$APPCONFIG", "$APPCONFIG/*"]
},
"path": {
"all": true
}
}
}
tauri-settings
exports a set of standalone functions for quick usage or a SettingsManager
class with extra features such as caching.
Typescript typings and JSDoc is provided for all the API methods.
The API also uses typescript generics to allow a defined schema to be used. In the following sections, SettingsSchema
is an optional generic type for the settings schema.
It is highly recommended to use a defined schema to prevent runtime errors.
SettingsManager
class can also be initialized with a SettingsSchema
generic. This generic will be used by all the methods of the class instance.
Apart from basic setters and getters, the SettingsManager
class also caches the value of the settings in the memory for quick access. This can also be used to make the api calls synchronous. See Differences From electron-settings
: Asynchronous.
Using both the standalone methods and SettingsManager
together can cause unexpected behaviour. If a setting is accessed both by the frontend and the backend then not using the caching feature is recommended.
tauri-settings
exports the following API methods to directly set or get settings for quick usage. Alternatively you can also use SettingsManager
.
Each of the following methods has an options
parameter. See the Config to learn more.
async has<SettingsSchema>(key, options = {})
: Async function that resolves with a boolean which is true if the given key exists in the settings.async get<SettingsSchema>(key, options = {})
: Async function that resolves with the value of the setting corresponding to the given key.async set<SettingsSchema>(key, value, options = {})
: Async function that sets the value of a given setting. Resolves with the entire settings object.async getAll<SettingsSchema>(, options = {})
: Async function that resolves with the entire settings object.Here key
uses dot notation.
type Schema = {
theme: 'dark' | 'light';
startFullscreen: boolean;
}
get<Schema>('theme').then((theme) => {
// change the theme
})
// when the theme is changed by the user
set<Schema>('theme').then(() => console.log('theme changed succesfully'));
See the complete API Docs.
SettingsManager
is a class that can be used not only to set and get settings but it is meant to be a complete settings manager.
It provides additional features such as caching the settings in the memory, setting defaults and in the future, listening to changes in the settings.
The caching feature stores a copy of the settings on the RAM and does not directly alter the settings file on persistent storage. This can be useful in multiple cases:
electron-settings
: Asynchronous)The cached settings can be accessed by using the hasCache
, getCache
or setCache
methods.
The cache can be synced (written to persistent storage) at any time or the persistent storage can be accessed at any time using the has
, get
and set
methods.
Dot notation is also supported here.
SettingsManager
class can also be initialized with the SettingsSchema
generic. (see Usage)
// TypeScript
import { SettingsManager } from 'tauri-settings';
type Schema = {
theme: 'dark' | 'light';
startFullscreen: boolean;
}
const settingsManager = new SettingsManager<Schema>(
{ // defaults
theme: 'light',
startFullscreen: false
},
{ // options
fileName: 'customization-settings'
}
)
// checks whether the settings file exists and created it if not
// loads the settings if it exists
settingsManager.initialize().then(() => {
// any key other than 'theme' and 'startFullscreen' will be invalid.
// theme key will only accept 'dark' or 'light' as a value due to the generic.
settingsManager.setCache('theme', 'dark');
}
// at a later time
await settingsManager.syncCache();
// JavaScript
import { SettingsManager } from 'tauri-settings';
const settingsManager = new SettingsManager(
{ // defaults
theme: 'light',
startFullscreen: false
},
{ // options
fileName: 'customization-settings'
}
);
// checks whether the settings file exists and created it if not
// loads the settings if it exists
settingsManager.initialize().then(() => {
// there is no schema, so any key will be accepted
// the user needs to add their own validation scheme
settingsManager.setCache('theme', 'dark');
}
// at a later time
await settingsManager.syncCache();
See the complete API Docs.
electron-settings
Since the Tauri fs
API is asynchronous, the API methods exported by tauri-settings
are also asynchronous. Methods setSync
, getSync
, and hasSync
from electron-settings
are not available.
Even though synchronous fs
API is not available, the caching feature of SettingsManager
can be used to synchronously set and read the settings.
electron-settings
allows you to access settings by using dot notation.
tauri-settings
supports (Thanks to https://github.com/harshkhandeparkar/tauri-settings/pull/3) the above feature without the array notation key.array[4]
.
Example: If the settings schema looks like this:
{
theme: {
mode: 'dark',
accent: 'red'
}
}
get('theme.mode')
will return dark
.
The following will NOT work:
{
search: {
recents: ['keyword1', 'keyword2', 'keyword3']
}
}
get('search.recents[3]')
will return null
whereas get('search.recents')
will return the entire recents
array.
electron-settings
exports a configure()
method to configure some of the options such as the fileName.
However, tauri-settings
doesn't export such a variable due to various reasons. Instead each API method such as get
and set
, as well as the SettingsManager
class have an optional options
parameter (See API Docs).
FAQs
A user settings manager for Tauri inspired by electron-settings.
The npm package tauri-settings receives a total of 55 weekly downloads. As such, tauri-settings popularity was classified as not popular.
We found that tauri-settings demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
Security News
Socket CEO Feross Aboukhadijeh joins a16z partners to discuss how modern, sophisticated supply chain attacks require AI-driven defenses and explore the challenges and solutions in leveraging AI for threat detection early in the development life cycle.
Security News
NIST's new AI Risk Management Framework aims to enhance the security and reliability of generative AI systems and address the unique challenges of malicious AI exploits.