How to use the alfy.cache function in alfy

To help you get started, we’ve selected a few alfy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bikenik / alfred-anki / index.js View on Github external
if (/!.*/.test(input)) {
		const options = commands.map(command => ({
			title: command.meta.name,
			subtitle: `${command.meta.help} | Usage: ${command.meta.usage}`,
			autocomplete: command.meta.autocomplete,
			text: {
				largetype: `${command.meta.help} | Usage: ${command.meta.usage}`
			},
			icon: command.meta.icon,
			valid: false
		}))
		return alfy.inputMatches(options, 'title')
	}
}

if (!alfy.cache.get('start-PID')) {
	alfy.cache.set('start-PID', process.pid, {maxAge: 30000}) // 30 sec.
}

(async () => {
	if (alfy.config.get('theme') === undefined) {
		alfy.config.set('theme', 'dark')
	}

	try {
		if (alfy.cache.get('start-PID') === process.pid) {
			await runApplescript(`
				tell application "Alfred 4"
					run trigger ¬
						"refresh" in workflow ¬
						"org.bikenik.anki"
				end tell
github bikenik / alfred-anki / index.js View on Github external
const options = commands.map(command => ({
			title: command.meta.name,
			subtitle: `${command.meta.help} | Usage: ${command.meta.usage}`,
			autocomplete: command.meta.autocomplete,
			text: {
				largetype: `${command.meta.help} | Usage: ${command.meta.usage}`
			},
			icon: command.meta.icon,
			valid: false
		}))
		return alfy.inputMatches(options, 'title')
	}
}

if (!alfy.cache.get('start-PID')) {
	alfy.cache.set('start-PID', process.pid, {maxAge: 30000}) // 30 sec.
}

(async () => {
	if (alfy.config.get('theme') === undefined) {
		alfy.config.set('theme', 'dark')
	}

	try {
		if (alfy.cache.get('start-PID') === process.pid) {
			await runApplescript(`
				tell application "Alfred 4"
					run trigger ¬
						"refresh" in workflow ¬
						"org.bikenik.anki"
				end tell
		`)
github bikenik / alfred-anki / src / anki / anki-models.js View on Github external
module.exports.modelExist = async (model = note_type) => {
	try {
		alfy.cache.set('validOutput', 'true')
		const result = await ankiConnect('modelFieldNames', 6, {modelName: model})
		jsonfile.writeFile(fileAnkiModelFields, result === null ? [] : result, {
			spaces: 2
		}, error => {
			if (error !== null) {
				console.log(error)
			}
		})
		return result
	} catch (error) {
		alfy.cache.set('validOutput', 'false')
		return new WorkflowError(error, error === 'failed to connect to AnkiConnect' ? errorAction('main') : error === 'collection is not available' ? errorAction('profile') : /model was not found/.test(error) ? errorAction('modelExist') : errorAction('main'))
	}
}
github patrickkahl / alfred-tyme / cache.js View on Github external
cache.default = () => {
  alfy.cache.clear()

  if (!sh.test('-f', TYME_PATH + TYME_HOOKS_FILE))
    sh.cp(TYME_HOOKS_FILE, TYME_PATH)

  cache.createTaskOutput()
  cache.createTasksNotesOutput()
}
github bikenik / alfred-anki / src / anki / anki-decks.js View on Github external
const outresult = async function () {
		try {
			alfy.cache.set('validOutput', 'true')
			const resultAll = await ankiConnect('deckNames', 6)
			return resultAll
		} catch (error) {
			alfy.cache.set('validOutput', 'false')
			throw new WorkflowError(error, error === 'failed to connect to AnkiConnect' ? errorAction('main') : error === 'collection is not available' ? errorAction('profile') : /model was not found/.test(error) ? errorAction('modelExist') : errorAction('main'))
		}
	}
github nikersify / alfred-polyglot / lib / util.js View on Github external
constructor(key) {
		this.key = key

		if (!alfy.cache.has(this.key)) {
			alfy.cache.set(this.key, [])
		}
	}
github patrickkahl / alfred-tyme / cache.js View on Github external
{
            title: '-- Add new note --',
          },
          ...taskRecords
            .sort((a, b) => new Date(b.timeend) - new Date(a.timeend))
            .map(taskRecord => taskRecord.note)
            .filter((elem, pos, arr) => {
              return arr.indexOf(elem) == pos
            })
            .map(note => ({
              title: note,
              arg: note,
            })),
        ]

        alfy.cache.set(`handle.getNotes.${task.id}`, items)
      })
    })
github bchatard / alfred-jetbrains / src / project.js View on Github external
const getItems = product => {
  const cacheKey = `projects.${product.key}`;
  const cachedProjects = alfy.cache.get(cacheKey);
  if (!cachedProjects) {
    const projects = [];
    const paths = projectPaths.get(product.preferencePath);
    paths.forEach(path => {
      const item = buildProductItem(product, path);
      if (item) {
        projects.push(item);
      }
    });
    alfy.cache.set(cacheKey, projects, {
      maxAge: +process.env.jb_project_cache_lifetime * 1000
    });

    return projects;
  }
  return cachedProjects;
};
github bikenik / alfred-anki / update-config.js View on Github external
}

	alfy.config.set('fields', fields)
}

if (alfy.config.get('fields') === undefined) {
	alfy.config.set('fields', {})
}

if (env.config_variable_deck) {
	alfy.config.set(env.config_variable_deck, env.config_value)
}

if (env.config_variable_profile) {
	alfy.config.set(env.config_variable_profile, env.config_value)
	alfy.cache.set('new-profile', true)
	alfy.cache.set('refresh-done', false)
}

if (env.config_variable_model) {
	(async () => {
		alfy.config.set(env.config_variable_model, JSON.parse(env.config_value))
		alfy.cache.set('new-profile', false)
		const newFields = await modelExist(Object.keys(alfy.config.get('default-model'))[0])
		await updateFieldsConfig(newFields)
	})()
} else {
	updateFieldsConfig(modelFieldNames)
}

if (alfy.config.get('Tag') === undefined) {
	alfy.config.set('Tag', 'not_rli')
github jonrohan / alfred-figma / lib / utils.js View on Github external
}).then(data => {
    alfy.cache.set(url, data, {maxAge: 1000 * 60 * 60 * 24})
    return data
  })
}