本文整理汇总了TypeScript中electron.remote.app类的典型用法代码示例。如果您正苦于以下问题:TypeScript remote.app类的具体用法?TypeScript remote.app怎么用?TypeScript remote.app使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了remote.app类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
highlight: function(code: string, lang: string): string {
if (lang === undefined) {
return code;
}
if (lang === 'mermaid') {
if (!loaded_mermaid) {
const script = document.createElement('script');
script.src = 'file://' + remote.app.getAppPath() + '/bower_components/mermaid/dist/mermaid.min.js';
script.onload = () => {
mermaid.init(undefined, 'div.mermaid');
};
document.head.appendChild(script);
loaded_mermaid = true;
}
return '<div class="mermaid">' + he.encode(code) + '</div>';
}
if (lang === 'katex') {
return '<div class="katex">' + katex.renderToString(code, {displayMode: true}) + '</div>';
}
try {
return highlight(lang, code).value;
} catch (e) {
console.log('Error on highlight: ' + e.message);
return code;
}
},
示例2: prepareIpc
editor.on('process-attached', () => {
const client = editor.getClient();
client.listRuntimePaths()
.then((rtp: string[]) => {
component_loader.loadFromRTP(rtp);
component_loader.initially_loaded = true;
});
runtime_api.subscribe(client);
element.addEventListener('drop', e => {
e.preventDefault();
const f = e.dataTransfer.files[0];
if (f) {
client.command('edit! ' + f.path);
}
});
remote.app.on('open-file', (e: Event, p: string) => {
e.preventDefault();
client.command('edit! ' + p);
});
prepareIpc(client);
});
示例3: 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
)
}
示例4: 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();
}
示例5: 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("~");
}
});
示例6: 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)
}
})
}
示例7: function
value: function() {
// Note: First and second arguments are related to Electron
const a = remote.process.argv.slice(2);
a.push(
'--cmd', `let\ g:nyaovim_version="${remote.app.getVersion()}"`,
'--cmd', `set\ rtp+=${join(__dirname, '..', 'runtime').replace(' ', '\ ')}`
);
// XXX:
// Swap files are disabled because it shows message window on start up but frontend can't detect it.
a.push('-n');
return a;
},
示例8: 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, '/');
};
示例9: function
value: function() {
// Note:
// First and second arguments are related to Electron
// XXX:
// Spectron additionally passes many specific arguments to process and 'nvim' process
// will fail because of them. As a workaround, we stupidly ignore arguments on E2E tests.
const a = process.env.NYAOVIM_E2E_TEST_RUNNING ? [] : remote.process.argv.slice(2);
a.push(
'--cmd', `let\ g:nyaovim_version="${remote.app.getVersion()}"`,
'--cmd', `set\ rtp+=${join(__dirname, '..', 'runtime').replace(' ', '\ ')}`,
);
// XXX:
// Swap files are disabled because it shows message window on start up but frontend can't detect it.
a.push('-n');
return a;
},
示例10: 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)
}