本文整理汇总了TypeScript中electron.remote.app.getPath方法的典型用法代码示例。如果您正苦于以下问题:TypeScript remote.app.getPath方法的具体用法?TypeScript remote.app.getPath怎么用?TypeScript remote.app.getPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类electron.remote.app
的用法示例。
在下文中一共展示了remote.app.getPath方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getHistoryModel
export function getHistoryModel(
options,
basePath = remote.app.getPath('userData')
) {
let buffer: any[] = []
let promise = q()
const fileName = basePath + '/' + options.file
const history = {
push(item) {
promise = promise.then(() => {
buffer.splice(0, 0, item)
if (buffer.length > options.max) {
buffer = buffer.slice(0, options.min)
}
return q.nfcall(
writeFile,
fileName,
buffer.map(obj => JSON.stringify(obj)).join(',')
)
})
return promise
},
list: () => buffer,
}
return q.nfcall(readFile, fileName).then(
content => {
buffer = JSON.parse('[' + content + ']')
return history
},
() => history
)
}
示例2: cwdKernelFallback
export function cwdKernelFallback() {
// HACK: If we see they're at /, we assume that was the OS launching the Application
// from a launcher (launchctl on macOS)
if (process.cwd() === "/") {
return remote.app.getPath("home");
}
return process.cwd();
}
示例3: test
test("replaces the user directory with ~", () => {
const fixture = path.join(remote.app.getPath("home"), "test-notebooks");
const result = nativeWindow.tildify(fixture);
if (process.platform === "win32") {
expect(result).toBe(fixture);
} else {
expect(result).toContain("~");
}
});
示例4: writeFile
export const saveSettings = (
settings: ISettings,
baseDir = remote.app.getPath('userData')
) => {
const fileName = baseDir + '/settings.json'
writeFile(fileName, JSON.stringify(settings, null, 4), err => {
if (err) {
console.log('error saving settings', err.message)
}
})
}
示例5: if
export const getPath = (...relativePaths: string[]) => {
let path: string;
if (remote) {
path = remote.app.getPath('userData');
} else if (app) {
path = app.getPath('userData');
} else {
return null;
}
return resolve(path, ...relativePaths).replace(/\\/g, '/');
};
示例6: getSettings
export function getSettings(
baseDir = remote.app.getPath('userData')
): Promise<ISettings> {
const fileName = baseDir + '/settings.json'
return new Promise((resolve, reject) => {
readFile(fileName, (_, data) => {
if (data) {
resolve(data)
} else {
const str = JSON.stringify(defaultSettings)
writeFile(fileName, str, writeErr => {
if (writeErr) {
reject(writeErr)
} else {
resolve(str)
}
})
}
})
}).then(JSON.parse)
}
示例7: ofType
import { actions } from "@nteract/core";
import { remote } from "electron";
import { readFileObservable, writeFileObservable } from "fs-observable";
import { ActionsObservable, ofType, StateObservable } from "redux-observable";
import { map, mapTo, mergeMap, switchMap } from "rxjs/operators";
import { DesktopNotebookAppState } from "../state";
import * as path from "path";
import { Actions } from "../actions";
const HOME = remote.app.getPath("home");
export const CONFIG_FILE_PATH = path.join(HOME, ".jupyter", "nteract.json");
/**
* An epic that loads the configuration.
*/
export const loadConfigEpic = (action$: ActionsObservable<Actions>) =>
action$.pipe(
ofType(actions.LOAD_CONFIG),
switchMap(() =>
readFileObservable(CONFIG_FILE_PATH).pipe(
map(data =>
actions.configLoaded({
config: JSON.parse(data.toString())
})
)
)
)
);
示例8: getPath
private getPath() {
return path.join(remote.app.getPath('appData'), 'Livelang', `${this.id}.json`);
}
示例9: m
export const createBookmarkModel = (m, fs, pubsub, editor, createPopupmenu) => {
let show = false
const description = m.prop('')
let bookmarks
let nameEl
let content
const basePath = remote.app.getPath('userData')
let fileName = basePath + '/bookmarks.json'
const configName = el => {
nameEl = el
}
const writeToFile = () => {
fs.writeFile(fileName, JSON.stringify(bookmarks), err => {
// TODO error handling
console.log(err)
})
}
const save = () => {
const bookmark: IBookmarkItem = {
name: nameEl.value.trim(),
value: content,
description: description(),
}
nameEl.value = ''
bookmarks.push(bookmark)
writeToFile()
show = false
pubsub.emit('editor-focus', {})
}
const showAdd = () => {
m.startComputation()
content = editor.getSelection() || editor.getCursorStatement()
description(content)
show = true
m.endComputation()
setTimeout(nameEl.focus.bind(nameEl), 0)
}
const popupController: IController<IBookmarkItem> = {
getList: () => bookmarks || [],
renderItem: bookmark => [
m('div.p-menu-item-text', [
m('div', m.trust(bookmark.highlighted[0])),
m(
'div',
{ class: 'hint-remarks p-menu-item-small' },
bookmark.item.value
),
]),
],
itemSelected: bookmark => {
const i = bookmarks.indexOf(bookmark)
bookmarks.splice(i, 1)
writeToFile()
pubsub.emit('editor-focus', {})
},
}
const listView = createPopupmenu(pubsub, popupController, m)
pubsub.on('bookmark-add', showAdd)
pubsub.on('bookmark-delete', listView.toggleShow)
pubsub.on('connected', connection => {
const settings = connection.settings()
fileName =
basePath +
'/' +
(settings.bookmarksFile || settings.name + '.bookmarks.json')
fs.readFile(fileName, (err, data) => {
bookmarks = err ? [] : JSON.parse(data)
pubsub.emit('bookmarks', bookmarks)
})
})
document.addEventListener('keyup', e => {
if (e.keyCode === 27 && show) {
m.startComputation()
show = false
pubsub.emit('bookmark-closed')
m.endComputation()
}
})
return {
view() {
return m('div', [
m(
'div',
{
class: 'container popup form' + (show ? '' : ' hidden'),
},
[
m(
'h2',
{
class: 'popup-title',
},
'Add bookmark'
),
m(
'div',
{
class: 'form-element',
//.........这里部分代码省略.........
示例10: get
import { remote } from 'electron';
import * as fs from 'fs';
import exists from './utils/exists';
import safeEmitter from './utils/safeEmitter';
const path = remote.app.getPath('userData') + '/settings.json';
const defaultSettings = {
editorTheme: 'tomorrow_night_bright',
editorFontSize: '16px'
};
export const emitter = new (safeEmitter(Object.keys(defaultSettings)))();
let settings: typeof defaultSettings;
if (exists(path)) {
settings = JSON.parse(fs.readFileSync(path, 'utf-8'));
fixMissing();
} else {
settings = defaultSettings;
write();
}
export function get() {
return settings;
}
export function set(setting: string, value: any) {
emitter.emit(setting, value);
settings[setting] = value;