当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript remote.app.getPath方法代码示例

本文整理汇总了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
    )
}
开发者ID:jakobrun,项目名称:gandalf,代码行数:32,代码来源:history.ts

示例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();
}
开发者ID:nteract,项目名称:nteract,代码行数:8,代码来源:menu.ts

示例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("~");
   }
 });
开发者ID:nteract,项目名称:nteract,代码行数:9,代码来源:native-window.spec.ts

示例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)
        }
    })
}
开发者ID:jakobrun,项目名称:gandalf,代码行数:11,代码来源:settings.ts

示例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, '/');
};
开发者ID:laquereric,项目名称:wexond,代码行数:13,代码来源:paths.ts

示例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)
}
开发者ID:jakobrun,项目名称:gandalf,代码行数:21,代码来源:settings.ts

示例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())
          })
        )
      )
    )
  );
开发者ID:nteract,项目名称:nteract,代码行数:31,代码来源:config.ts

示例8: getPath

 private getPath() {
     return path.join(remote.app.getPath('appData'), 'Livelang', `${this.id}.json`);
 }  
开发者ID:shnud94,项目名称:livelang,代码行数:3,代码来源:index.ts

示例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',
//.........这里部分代码省略.........
开发者ID:jakobrun,项目名称:gandalf,代码行数:101,代码来源:bookmark.ts

示例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;
开发者ID:qsctr,项目名称:java-editor,代码行数:31,代码来源:settings.ts


注:本文中的electron.remote.app.getPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。