mirror of
https://github.com/fluxscape/fluxscape.git
synced 2026-01-11 14:52:54 +01:00
Initial commit
Co-Authored-By: Eric Tuvesson <eric.tuvesson@gmail.com> Co-Authored-By: mikaeltellhed <2311083+mikaeltellhed@users.noreply.github.com> Co-Authored-By: kotte <14197736+mrtamagotchi@users.noreply.github.com> Co-Authored-By: Anders Larsson <64838990+anders-topp@users.noreply.github.com> Co-Authored-By: Johan <4934465+joolsus@users.noreply.github.com> Co-Authored-By: Tore Knudsen <18231882+torekndsn@users.noreply.github.com> Co-Authored-By: victoratndl <99176179+victoratndl@users.noreply.github.com>
This commit is contained in:
16
packages/noodl-platform-electron/package.json
Normal file
16
packages/noodl-platform-electron/package.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "@noodl/platform-electron",
|
||||
"version": "2.7.0",
|
||||
"main": "src/index.ts",
|
||||
"description": "Cross platform implementation of platform specific features.",
|
||||
"author": "Noodl <info@noodl.net>",
|
||||
"homepage": "https://noodl.net",
|
||||
"dependencies": {
|
||||
"@noodl/platform": "file:../noodl-platform",
|
||||
"@noodl/platform-node": "file:../noodl-platform-node"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@electron/remote": ">=2.0.8",
|
||||
"electron": ">=20.1.0"
|
||||
}
|
||||
}
|
||||
23
packages/noodl-platform-electron/src/filesystem-electron.ts
Normal file
23
packages/noodl-platform-electron/src/filesystem-electron.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { dialog } from '@electron/remote';
|
||||
import { OpenDialogOptions as EOpenDialogOptions } from 'electron';
|
||||
import { OpenDialogOptions } from '@noodl/platform';
|
||||
import { FileSystemNode } from '@noodl/platform-node/src/filesystem-node';
|
||||
|
||||
export class FileSystemElectron extends FileSystemNode {
|
||||
openDialog(args: OpenDialogOptions): Promise<string> {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
const properties: EOpenDialogOptions['properties'] = ['openDirectory'];
|
||||
if (args?.allowCreateDirectory) {
|
||||
properties.push('createDirectory');
|
||||
}
|
||||
|
||||
dialog.showOpenDialog({ properties }).then((res) => {
|
||||
if (res.canceled) {
|
||||
reject();
|
||||
} else {
|
||||
resolve(res.filePaths[0]);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
9
packages/noodl-platform-electron/src/index.ts
Normal file
9
packages/noodl-platform-electron/src/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { setFileSystem, setPlatform, setStorage } from '@noodl/platform';
|
||||
import { StorageNode } from '@noodl/platform-node/src/storage-node';
|
||||
|
||||
import { FileSystemElectron } from './filesystem-electron';
|
||||
import { PlatformElectron } from './platform-electron';
|
||||
|
||||
setPlatform(new PlatformElectron());
|
||||
setFileSystem(new FileSystemElectron());
|
||||
setStorage(new StorageNode());
|
||||
82
packages/noodl-platform-electron/src/platform-electron.ts
Normal file
82
packages/noodl-platform-electron/src/platform-electron.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { shell, clipboard } from 'electron';
|
||||
import { addTrailingSlash, IPlatform, PlatformOS } from '@noodl/platform';
|
||||
import { processPlatformToPlatformOS } from '@noodl/platform-node/src/helper';
|
||||
|
||||
export class PlatformElectron implements IPlatform {
|
||||
get name(): string {
|
||||
return 'Electron';
|
||||
}
|
||||
|
||||
get os(): PlatformOS {
|
||||
return this._os;
|
||||
}
|
||||
|
||||
private _os: PlatformOS;
|
||||
private _userDataPath: string;
|
||||
private _documentsPath: string;
|
||||
private _tempPath: string;
|
||||
private _appPath: string;
|
||||
private _buildNumber: string;
|
||||
private _version: string;
|
||||
private _versionTag: string;
|
||||
private _versionId: string;
|
||||
|
||||
constructor() {
|
||||
const app = require('electron').app || require('@electron/remote').app;
|
||||
this._userDataPath = app.getPath('userData');
|
||||
this._documentsPath = app.getPath('documents');
|
||||
this._tempPath = addTrailingSlash(app.getPath('temp'));
|
||||
this._appPath = addTrailingSlash(app.getAppPath());
|
||||
|
||||
const packagePath = path.join(this._appPath, 'package.json');
|
||||
if (!fs.existsSync(packagePath)) {
|
||||
throw 'Cannot find package.json, to get the build version.';
|
||||
}
|
||||
|
||||
const packageJson = fs.readFileSync(packagePath, 'utf8');
|
||||
const packageContent = JSON.parse(packageJson);
|
||||
this._buildNumber = packageContent.buildNumber || 1;
|
||||
this._version = require('@electron/remote').app.getVersion();
|
||||
this._versionId = packageContent.fullVersion;
|
||||
this._versionTag = packageContent.versionTag;
|
||||
|
||||
this._os = processPlatformToPlatformOS();
|
||||
}
|
||||
|
||||
getBuildNumber(): string | undefined {
|
||||
return this._buildNumber;
|
||||
}
|
||||
getFullVersion(): string {
|
||||
return this._versionId;
|
||||
}
|
||||
getVersion(): string {
|
||||
return this._version;
|
||||
}
|
||||
getVersionWithTag(): string {
|
||||
return this._versionTag ? `${this._version}-${this._versionTag}` : this._version;
|
||||
}
|
||||
|
||||
getUserDataPath(): string {
|
||||
return this._userDataPath;
|
||||
}
|
||||
getDocumentsPath(): string {
|
||||
return this._documentsPath;
|
||||
}
|
||||
getTempPath(): string {
|
||||
return this._tempPath;
|
||||
}
|
||||
getAppPath(): string {
|
||||
return this._appPath;
|
||||
}
|
||||
|
||||
openExternal(url: string): Promise<void> {
|
||||
return shell.openExternal(url);
|
||||
}
|
||||
|
||||
copyToClipboard(value: string): Promise<void> {
|
||||
clipboard.writeText(value);
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
4
packages/noodl-platform-electron/tsconfig.json
Normal file
4
packages/noodl-platform-electron/tsconfig.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"exclude": []
|
||||
}
|
||||
Reference in New Issue
Block a user