Skip to content

Commit

Permalink
FIX-2194 Witsml Explorer Desktop (#2357)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan-Marius Vatle (Omega AS) <[email protected]>
  • Loading branch information
eliasbruvik and janmarius authored Apr 19, 2024
1 parent fa8d13f commit 43a2bae
Show file tree
Hide file tree
Showing 22 changed files with 2,265 additions and 419 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Tests/Witsml.Tests/config.json
config.json
**/mysettings.*

# Database files
*.db

# Common node modules locations
/node_modules
/wwwroot/node_modules
Expand Down Expand Up @@ -123,3 +126,6 @@ coverage*[.json, .xml, .info]
/Tests/WitsmlExplorer.IntegrationTests/Properties/launchSettings.json

.fake

# TGZ files
*.tgz
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Witsml Explorer is a data management tool used for browsing and editing data dir
## Witsml as a Nuget package
Please see [nuget_witsml.md](/Docs/nuget_witsml.md)

## Witsml Explorer Desktop Edition
Please see [desktop edition readme](/Src/WitsmlExplorer.Desktop/README.md)

## Contributing
Please see our [contributing.md](/CONTRIBUTING.md).

Expand Down
1 change: 1 addition & 0 deletions Src/WitsmlExplorer.Api/Configuration/ConfigConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public static class ConfigConstants
public static readonly string OAuth2Enabled = "OAuth2Enabled";
public static readonly string LogQueries = "LogQueries";
public static readonly string NotificationsKey = "NotificationsKey";
public static readonly string IsDesktopApp = "IsDesktopApp";
}
}
4 changes: 2 additions & 2 deletions Src/WitsmlExplorer.Api/Extensions/HttpContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace WitsmlExplorer.Api.Extensions
{
public static class HttpContextExtensions
{
public static string CreateWitsmlExplorerCookie(this HttpContext httpContext)
public static string CreateWitsmlExplorerCookie(this HttpContext httpContext, bool isDesktopApp)
{
CookieOptions cookieOptions = new()
{
SameSite = SameSiteMode.Strict,
SameSite = isDesktopApp ? SameSiteMode.None : SameSiteMode.Strict,
Secure = true,
HttpOnly = true
};
Expand Down
21 changes: 16 additions & 5 deletions Src/WitsmlExplorer.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,23 @@

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

builder.Configuration.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", false, true)
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", true, true)
.AddJsonFile("mysettings.json", true, true)
.AddJsonFile("config.json", true, true)
var configPath = builder.Configuration["CONFIG_PATH"];

if (configPath != null)
{
builder.Configuration.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(configPath, false, true)
.AddEnvironmentVariables();
}
else
{
builder.Configuration.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", false, true)
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", true, true)
.AddJsonFile("mysettings.json", true, true)
.AddJsonFile("config.json", true, true)
.AddEnvironmentVariables();
}

if (builder.Environment.IsDevelopment())
{
Expand Down
4 changes: 3 additions & 1 deletion Src/WitsmlExplorer.Api/Services/CredentialsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class CredentialsService : ICredentialsService
private readonly ICredentialsCache _credentialsCache;
private static readonly string SUBJECT = "sub";
private readonly bool _useOAuth2;
private readonly bool _isDesktopApp;

public CredentialsService(
IDataProtectionProvider dataProtectionProvider,
Expand All @@ -54,6 +55,7 @@ public CredentialsService(
_witsmlServerRepository = witsmlServerRepository ?? throw new ArgumentException("Missing WitsmlServerRepository");
_credentialsCache = credentialsCache ?? throw new ArgumentException("CredentialsService missing");
_useOAuth2 = StringHelpers.ToBoolean(configuration[ConfigConstants.OAuth2Enabled]);
_isDesktopApp = StringHelpers.ToBoolean(configuration[ConfigConstants.IsDesktopApp]);
}

public async Task VerifyCredentials(ServerCredentials creds)
Expand All @@ -77,7 +79,7 @@ public async Task<bool> VerifyAndCacheCredentials(IEssentialHeaders eh, bool kee
string cacheId = GetCacheId(eh);
if (!_useOAuth2 && (string.IsNullOrEmpty(cacheId) || _credentialsCache.GetItem(cacheId) == null))
{
cacheId = httpContext.CreateWitsmlExplorerCookie();
cacheId = httpContext.CreateWitsmlExplorerCookie(_isDesktopApp);
}

await VerifyCredentials(creds);
Expand Down
5 changes: 5 additions & 0 deletions Src/WitsmlExplorer.Api/WitsmlExplorer.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@
<DependentUpon>appsettings.json</DependentUpon>
</Content>
</ItemGroup>
<ItemGroup Condition="'$(IncludeApiConfig)' == 'true'">
<Content Include="$(CONFIG_PATH)">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
21 changes: 21 additions & 0 deletions Src/WitsmlExplorer.Desktop/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# production
/build
/out

# misc
.DS_Store
.env*.local

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

.ignore*
51 changes: 51 additions & 0 deletions Src/WitsmlExplorer.Desktop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Witsml Explorer Desktop Edition

Witsml Explorer Desktop Edition is an easy-to-install version of Witsml Explorer. However, this edition does not support all features as the web application.

## Supported operating systems

- Windows 64-bit

<!-- ## Installation guide
The installer can be downloaded from our [GitHub releases page](https://github.com/equinor/witsml-explorer/releases). Download and run the installer. -->

## Configuration

A configuration file is created in '%AppData%\Roaming\WEx-Desktop\config.json'. It can be edited to change the API port and the path of logging and database files.

## For developers

Install dependencies:

```sh
cd Src/WitsmlExplorer.Desktop/
# Download dependencies
yarn
```

Run in developer mode:

```sh
# From Src/WitsmlExplorer.Desktop/ run:
yarn dev
```

Run production preview:

```sh
# From Src/WitsmlExplorer.Desktop/ run:
yarn preview
```

Build an installer and install it on your computer:

```sh
# From Src/WitsmlExplorer.Desktop/ run:
yarn electron:dist
```

The installer can be found in `Src/WitsmlExplorer.Desktop/dist/WEx-Desktop Setup <version>.exe`. Run it and follow the instructions.

### API log files for debugging

Check the [Configuration](#configuration) file to see where the logging files are placed.
42 changes: 42 additions & 0 deletions Src/WitsmlExplorer.Desktop/api.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"LogQueries": false,
"AllowedHosts": "localhost",
"AllowedOrigin": "http://localhost:3000",
"Witsml": {
"ClientCapabilities": {
"Name": "Witsml Explorer Desktop",
"Description": "Desktop interface for Witsml servers"
}
},
"OAuth2Enabled": false,
"IsDesktopApp": true,
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"System": "Warning",
"Microsoft": "Information"
}
},
"WriteTo": [
{
"Name": "Console",
"Args": {
"theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console"
}
},
{
"Name": "File",
"Args": {
"path": "api-.log",
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message}{NewLine}{Exception}",
"rollOnFileSizeLimit": true,
"fileSizeLimitBytes": 20971520,
"retainedFileCountLimit": 100,
"rollingInterval": "Day"
}
}
],
"Enrich": ["FromLogContext"]
}
}
21 changes: 21 additions & 0 deletions Src/WitsmlExplorer.Desktop/electron-builder.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"appId": "WEx-Desktop-App",
"productName": "Witsml Explorer Desktop",
"directories": {
"output": "dist"
},
"files": ["dist/**/*"],
"asar": true,
"asarUnpack": ["dist/api/**/*"],
"win": {
"target": ["nsis"]
},
"nsis": {
"artifactName": "WExDesktop.x64.${version}.${ext}",
"oneClick": false,
"perMachine": false,
"allowToChangeInstallationDirectory": true,
"deleteAppDataOnUninstall": false,
"createStartMenuShortcut": true
}
}
36 changes: 36 additions & 0 deletions Src/WitsmlExplorer.Desktop/electron.vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import react from "@vitejs/plugin-react";
import { defineConfig } from "electron-vite";
import { dirname, resolve } from "path";
import { fileURLToPath } from "url";
import tsconfigPaths from "vite-tsconfig-paths";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

export default defineConfig({
main: {
build: {
outDir: "dist/main"
}
},
preload: {
build: {
outDir: "dist/preload"
}
},
renderer: {
root: resolve(__dirname, "../WitsmlExplorer.Frontend"),
plugins: [react(), tsconfigPaths()],
build: {
rollupOptions: {
input: {
index: resolve(__dirname, "../WitsmlExplorer.Frontend/index.html")
}
},
outDir: "dist/renderer"
},
server: {
port: 3000
}
}
});
38 changes: 38 additions & 0 deletions Src/WitsmlExplorer.Desktop/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "WEx-Desktop",
"description": "Witsml Explorer Desktop Edition",
"version": "1.0.0",
"private": true,
"author": "Witsml Explorer Team",
"scripts": {
"dev": "electron-vite dev -w",
"build:api": "dotnet publish -o ./dist/api --os win --arch x64 --self-contained true /p:IncludeApiConfig=true /p:CONFIG_PATH=../WitsmlExplorer.Desktop/api.config.json ../WitsmlExplorer.Api/WitsmlExplorer.Api.csproj",
"build:frontend": "electron-vite build",
"build": "yarn build:api && yarn build:frontend",
"preview": "yarn build:api && electron-vite preview",
"electron:pack": "yarn build && electron-builder --dir -c electron-builder.json",
"electron:dist": "yarn build && electron-builder -c electron-builder.json"
},
"main": "./dist/main/main.js",
"lint-staged": {
"**/*.{js,ts,tsx}": [
"eslint --fix",
"prettier -w"
]
},
"eslintIgnore": [
"node_modules/",
"dist/",
"out/"
],
"devDependencies": {
"@types/cross-spawn": "^6.0.6",
"cross-spawn": "^7.0.3",
"electron": "^29.3.0",
"electron-builder": "^24.13.3",
"electron-vite": "^2.1.0",
"vite-tsconfig-paths": "^4.3.2",
"@vitejs/plugin-react": "^4.2.1",
"lint-staged": "^13.0.3"
}
}
Loading

0 comments on commit 43a2bae

Please sign in to comment.