當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。