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:
Michael Cartner
2024-01-26 11:52:55 +01:00
commit b9c60b07dc
2789 changed files with 868795 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
export enum PlatformOS {
Web = "web",
Windows = "windows",
MacOS = "macOS",
Linux = "linux",
Unknown = "unknown"
}
export interface IPlatform {
get name(): string;
get os(): PlatformOS;
/**
* @example '1'
*/
getBuildNumber(): string | undefined;
/**
* @example '2.6.3-1'
*/
getFullVersion(): string;
/**
* @example '2.6.3'
*/
getVersion(): string;
/**
* @example '2.6.3' or '2.6.3-AI'
*/
getVersionWithTag(): string;
/**
* @example Windows: 'C:/Users/Eric/AppData/Roaming/Noodl'
* @example OSX: '/Users/eric/Library/Preferences/Noodl'
*/
getUserDataPath(): string;
/**
* @example Windows: 'C:/Users/Eric/OneDrive/Dokument'
*/
getDocumentsPath(): string;
/**
* @example Windows: 'C:/Users/Eric/AppData/Local/Temp/'
* @example OSX: '/var/folders/8w/29mdvxz11f13l68p4xg_m_vc0000gn/T/'
*/
getTempPath(): string;
/**
* @example Windows: 'C:/GitHub/noodl-editor/'
* @example OSX: '/Users/eric/Documents/GitHub/noodl-editor/'
*/
getAppPath(): string;
/**
* Open the given external protocol URL in the desktop's default manner.
* (For example, mailto: URLs in the user's default mail agent).
*
* @param url
*/
openExternal(url: string): Promise<void>;
/**
* Write the specified text string to the system clipboard.
*
* @param value
*/
copyToClipboard(value: string): Promise<void>;
}
// OSX and Windows add trailing slashes to the temp folder, Linux doesn't
export function addTrailingSlash(path: string): string {
return path[path.length - 1] !== "/" ? path + "/" : path;
}

View File

@@ -0,0 +1,3 @@
export * from "./common";
export * from "./support";
export * from "./platform-web";

View File

@@ -0,0 +1,53 @@
import { IPlatform } from '@noodl/platform';
import { PlatformOS } from './common';
export class PlatformWeb implements IPlatform {
get name(): string {
return 'Web';
}
get os(): PlatformOS {
return PlatformOS.Web;
}
constructor(
private readonly _version: string,
private readonly _versionTag: string,
private readonly _buildNumber: string
) {}
getBuildNumber(): string | undefined {
return this._buildNumber;
}
getFullVersion(): string {
return this._version + '-' + this._buildNumber;
}
getVersion(): string {
return this._version;
}
getVersionWithTag(): string {
return this._versionTag ? `${this._version}-${this._versionTag}` : this._version;
}
getUserDataPath(): string {
return '/user';
}
getDocumentsPath(): string {
return '/documents';
}
getTempPath(): string {
return '/tmp';
}
getAppPath(): string {
return '/app';
}
async openExternal(url: string): Promise<void> {
window.open(url, '_blank').focus();
}
async copyToClipboard(value: string): Promise<void> {
await navigator.clipboard.writeText(value);
}
}

View File

@@ -0,0 +1,43 @@
/**
* https://stackoverflow.com/a/61725416/3211243
*/
export function isElectron(): boolean {
// Renderer process
// @ts-ignore window
if (
typeof window !== "undefined" &&
typeof window.process === "object" &&
// @ts-ignore
window.process.type === "renderer"
) {
return true;
}
// Main process
if (
typeof process !== "undefined" &&
typeof process.versions === "object" &&
!!process.versions.electron
) {
return true;
}
// Detect the user agent when the `nodeIntegration` option is set to true
// @ts-ignore navigator
if (
typeof navigator === "object" &&
typeof navigator.userAgent === "string" &&
navigator.userAgent.indexOf("Electron") >= 0
) {
return true;
}
return false;
}
export function isNode(): boolean {
return (
typeof process !== "undefined" &&
process.release.name.search(/node|io.js/) !== -1
);
}