Browse Source

init

master
nitowa 1 year ago
commit
42acdc01a7
30 changed files with 20022 additions and 0 deletions
  1. 16
    0
      .eslintrc.json
  2. 92
    0
      .gitignore
  3. 5
    0
      downloads/147033AB8C2087A747FE46AEEC0DC130C41798084D5249C9CE8C94D59809CDB0.html
  4. 5
    0
      downloads/14954822BE076F477FAF83A56A1B45A60A9FC39CEFB57C1528162448231D440C.html
  5. 5
    0
      downloads/17A23DDA821CF4F2E8D2D759BE85BBDCDA70B3F0FD324086C4C5B109C3EEC814.html
  6. 5
    0
      downloads/45E61ED034C0D227274D8A2D211F592A8765407EAF82AB18E65792EBF20CD3AA.html
  7. 5
    0
      downloads/49EF37A5E750A40532CBBD4A0D961301E3DE237FBCCCFB1169DA328D967AB1DC.html
  8. 5
    0
      downloads/6B75B80D4DD0E81334061CB02BA6973D78CC85A0838A3DD5FC858314BFB933DE.html
  9. 5
    0
      downloads/7E482378FBD039B5B5DC1BB5EF945BD4908ABF6DBF2C859C9B1D0DE78888843B.html
  10. 5
    0
      downloads/9C0F205A956F4D7EE6AB6D918E7E4D596CE05F08DBB5C4D16758BEF46F3FFC2D.html
  11. 5
    0
      downloads/C2A3B05B12FF62DF4E1B72D2C69C92472F4C5E42246EE51D6F236CA8438979CB.html
  12. 5
    0
      downloads/C818A5559E97C3D409E4A3491621316BDBACB51CE3006430E9A1757F07AA8F7D.html
  13. 5
    0
      downloads/D7D30B778433972D2DDC12C7D8D0F4D5E244FC30E182A0A7734AC3C486F1D401.html
  14. 1
    0
      downloads/F03640FB68CD5FE62F8958271A378F5C474C0F695876600CE42E972E5B0C2A70.html
  15. 5
    0
      downloads/F3ECFCDE08634A30D34132E400C77FD5786CD585A00651913F520A9F7E8FAD4C.html
  16. 37
    0
      forge.config.ts
  17. 19467
    0
      package-lock.json
  18. 48
    0
      package.json
  19. 48
    0
      src/RJSVMs/tns.ts
  20. 4
    0
      src/index.css
  21. 9
    0
      src/index.html
  22. 87
    0
      src/index.ts
  23. 8
    0
      src/preload.ts
  24. 34
    0
      src/renderer.ts
  25. 3
    0
      src/types/util.ts
  26. 19
    0
      tsconfig.json
  27. 18
    0
      webpack.main.config.ts
  28. 21
    0
      webpack.plugins.ts
  29. 19
    0
      webpack.renderer.config.ts
  30. 31
    0
      webpack.rules.ts

+ 16
- 0
.eslintrc.json View File

1
+{
2
+  "env": {
3
+    "browser": true,
4
+    "es6": true,
5
+    "node": true
6
+  },
7
+  "extends": [
8
+    "eslint:recommended",
9
+    "plugin:@typescript-eslint/eslint-recommended",
10
+    "plugin:@typescript-eslint/recommended",
11
+    "plugin:import/recommended",
12
+    "plugin:import/electron",
13
+    "plugin:import/typescript"
14
+  ],
15
+  "parser": "@typescript-eslint/parser"
16
+}

+ 92
- 0
.gitignore View File

1
+# Logs
2
+logs
3
+*.log
4
+npm-debug.log*
5
+yarn-debug.log*
6
+yarn-error.log*
7
+lerna-debug.log*
8
+
9
+# Diagnostic reports (https://nodejs.org/api/report.html)
10
+report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11
+
12
+# Runtime data
13
+pids
14
+*.pid
15
+*.seed
16
+*.pid.lock
17
+.DS_Store
18
+
19
+# Directory for instrumented libs generated by jscoverage/JSCover
20
+lib-cov
21
+
22
+# Coverage directory used by tools like istanbul
23
+coverage
24
+*.lcov
25
+
26
+# nyc test coverage
27
+.nyc_output
28
+
29
+# node-waf configuration
30
+.lock-wscript
31
+
32
+# Compiled binary addons (https://nodejs.org/api/addons.html)
33
+build/Release
34
+
35
+# Dependency directories
36
+node_modules/
37
+jspm_packages/
38
+
39
+# TypeScript v1 declaration files
40
+typings/
41
+
42
+# TypeScript cache
43
+*.tsbuildinfo
44
+
45
+# Optional npm cache directory
46
+.npm
47
+
48
+# Optional eslint cache
49
+.eslintcache
50
+
51
+# Optional REPL history
52
+.node_repl_history
53
+
54
+# Output of 'npm pack'
55
+*.tgz
56
+
57
+# Yarn Integrity file
58
+.yarn-integrity
59
+
60
+# dotenv environment variables file
61
+.env
62
+.env.test
63
+
64
+# parcel-bundler cache (https://parceljs.org/)
65
+.cache
66
+
67
+# next.js build output
68
+.next
69
+
70
+# nuxt.js build output
71
+.nuxt
72
+
73
+# vuepress build output
74
+.vuepress/dist
75
+
76
+# Serverless directories
77
+.serverless/
78
+
79
+# FuseBox cache
80
+.fusebox/
81
+
82
+# DynamoDB Local files
83
+.dynamodb/
84
+
85
+# Webpack
86
+.webpack/
87
+
88
+# Vite
89
+.vite/
90
+
91
+# Electron-Forge
92
+out/

+ 5
- 0
downloads/147033AB8C2087A747FE46AEEC0DC130C41798084D5249C9CE8C94D59809CDB0.html
File diff suppressed because it is too large
View File


+ 5
- 0
downloads/14954822BE076F477FAF83A56A1B45A60A9FC39CEFB57C1528162448231D440C.html
File diff suppressed because it is too large
View File


+ 5
- 0
downloads/17A23DDA821CF4F2E8D2D759BE85BBDCDA70B3F0FD324086C4C5B109C3EEC814.html
File diff suppressed because it is too large
View File


+ 5
- 0
downloads/45E61ED034C0D227274D8A2D211F592A8765407EAF82AB18E65792EBF20CD3AA.html
File diff suppressed because it is too large
View File


+ 5
- 0
downloads/49EF37A5E750A40532CBBD4A0D961301E3DE237FBCCCFB1169DA328D967AB1DC.html
File diff suppressed because it is too large
View File


+ 5
- 0
downloads/6B75B80D4DD0E81334061CB02BA6973D78CC85A0838A3DD5FC858314BFB933DE.html
File diff suppressed because it is too large
View File


+ 5
- 0
downloads/7E482378FBD039B5B5DC1BB5EF945BD4908ABF6DBF2C859C9B1D0DE78888843B.html
File diff suppressed because it is too large
View File


+ 5
- 0
downloads/9C0F205A956F4D7EE6AB6D918E7E4D596CE05F08DBB5C4D16758BEF46F3FFC2D.html
File diff suppressed because it is too large
View File


+ 5
- 0
downloads/C2A3B05B12FF62DF4E1B72D2C69C92472F4C5E42246EE51D6F236CA8438979CB.html
File diff suppressed because it is too large
View File


+ 5
- 0
downloads/C818A5559E97C3D409E4A3491621316BDBACB51CE3006430E9A1757F07AA8F7D.html
File diff suppressed because it is too large
View File


+ 5
- 0
downloads/D7D30B778433972D2DDC12C7D8D0F4D5E244FC30E182A0A7734AC3C486F1D401.html
File diff suppressed because it is too large
View File


+ 1
- 0
downloads/F03640FB68CD5FE62F8958271A378F5C474C0F695876600CE42E972E5B0C2A70.html View File

1
+<a href="javascript: window.parent.postMessage('YO', '*')">test</a>

+ 5
- 0
downloads/F3ECFCDE08634A30D34132E400C77FD5786CD585A00651913F520A9F7E8FAD4C.html
File diff suppressed because it is too large
View File


+ 37
- 0
forge.config.ts View File

1
+import type { ForgeConfig } from '@electron-forge/shared-types';
2
+import { MakerSquirrel } from '@electron-forge/maker-squirrel';
3
+import { MakerZIP } from '@electron-forge/maker-zip';
4
+import { MakerDeb } from '@electron-forge/maker-deb';
5
+import { MakerRpm } from '@electron-forge/maker-rpm';
6
+import { WebpackPlugin } from '@electron-forge/plugin-webpack';
7
+
8
+import { mainConfig } from './webpack.main.config';
9
+import { rendererConfig } from './webpack.renderer.config';
10
+
11
+const config: ForgeConfig = {
12
+  packagerConfig: {},
13
+  rebuildConfig: {},
14
+  makers: [new MakerSquirrel({}), new MakerZIP({}, ['darwin']), new MakerRpm({}), new MakerDeb({})],
15
+  plugins: [
16
+    new WebpackPlugin({
17
+      mainConfig,
18
+      devContentSecurityPolicy: `default-src * 'unsafe-inline' 'unsafe-eval' file:`,
19
+      renderer: {
20
+        config: rendererConfig,
21
+        entryPoints: [
22
+          {
23
+            html: './src/index.html',
24
+            js: './src/renderer.ts',
25
+            name: 'main_window',
26
+            preload: {
27
+              js: './src/preload.ts',
28
+
29
+            },
30
+          }
31
+        ],
32
+      },
33
+    }),
34
+  ],
35
+};
36
+
37
+export default config;

+ 19467
- 0
package-lock.json
File diff suppressed because it is too large
View File


+ 48
- 0
package.json View File

1
+{
2
+  "name": "tür-browser",
3
+  "productName": "tür-browser",
4
+  "version": "1.0.0",
5
+  "description": "My Electron application description",
6
+  "main": ".webpack/main",
7
+  "scripts": {
8
+    "start": "electron-forge start",
9
+    "package": "electron-forge package",
10
+    "make": "electron-forge make",
11
+    "publish": "electron-forge publish",
12
+    "lint": "eslint --ext .ts,.tsx ."
13
+  },
14
+  "keywords": [],
15
+  "author": {
16
+    "name": "nitowa",
17
+    "email": "frontblock.me@gmail.com"
18
+  },
19
+  "license": "MIT",
20
+  "devDependencies": {
21
+    "@electron-forge/cli": "^6.1.1",
22
+    "@electron-forge/maker-deb": "^6.1.1",
23
+    "@electron-forge/maker-rpm": "^6.1.1",
24
+    "@electron-forge/maker-squirrel": "^6.1.1",
25
+    "@electron-forge/maker-zip": "^6.1.1",
26
+    "@electron-forge/plugin-webpack": "^6.1.1",
27
+    "@typescript-eslint/eslint-plugin": "^5.59.1",
28
+    "@typescript-eslint/parser": "^5.59.1",
29
+    "@vercel/webpack-asset-relocator-loader": "^1.7.3",
30
+    "copy-webpack-plugin": "^11.0.0",
31
+    "css-loader": "^6.7.3",
32
+    "electron": "24.1.3",
33
+    "eslint": "^8.39.0",
34
+    "eslint-plugin-import": "^2.27.5",
35
+    "fork-ts-checker-webpack-plugin": "^7.3.0",
36
+    "node-loader": "^2.0.0",
37
+    "style-loader": "^3.3.2",
38
+    "ts-loader": "^9.4.2",
39
+    "ts-node": "^10.9.1",
40
+    "typescript": "~4.5.4"
41
+  },
42
+  "dependencies": {
43
+    "electron-squirrel-startup": "^1.0.0",
44
+    "rjsvm": "^0.1.2",
45
+    "tur-toolkit": "^0.0.9",
46
+    "xrpio": "^0.2.0"
47
+  }
48
+}

+ 48
- 0
src/RJSVMs/tns.ts View File

1
+import { z } from "zod";
2
+import { RJSVM_Implementations, RJSVM_Interface, RJSVM, RJSVM_Config, RJSVM_Builder } from "rjsvm"
3
+
4
+const shoutSchema = z.object({
5
+    title: z.string(),
6
+    body: z.string(),
7
+    from: z.string(),
8
+    id: z.optional(z.string())
9
+})
10
+
11
+type Shout = z.infer<typeof shoutSchema>
12
+
13
+type State_T = {
14
+    shouts: Shout[]
15
+}
16
+
17
+type RJSVM_Endpoints = {
18
+    submit: (data: Shout) => void
19
+}
20
+
21
+abstract class RJSVM_Base
22
+extends RJSVM<State_T, RJSVM_Endpoints>
23
+implements RJSVM_Interface<RJSVM_Base> {
24
+    state: State_T = {
25
+        shouts: []
26
+    }
27
+}
28
+
29
+const RJSVM_Contract: RJSVM_Implementations<RJSVM_Base> = {
30
+    submit: {
31
+        implementation: function (env, shout) {
32
+            this.state.shouts.unshift(shout)
33
+            console.log(shout)
34
+        },
35
+        visibility: 'public',
36
+        fee: 10,
37
+        parameterSchema: shoutSchema
38
+    }
39
+}
40
+
41
+const conf: RJSVM_Config = {
42
+    listeningAddress: "rBGqUNVzrNJ6CNpTriBts8QCTNi5VqUMnZ",
43
+    rippleNode: "wss://s.altnet.rippletest.net:51233"
44
+}
45
+const Rjsvm = RJSVM_Builder.from(RJSVM_Base, RJSVM_Contract);
46
+
47
+export const tns_rjsvm = new Rjsvm(conf)
48
+tns_rjsvm.state.shouts

+ 4
- 0
src/index.css View File

1
+body {
2
+  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
3
+    Arial, sans-serif;
4
+}

+ 9
- 0
src/index.html View File

1
+<html>
2
+<body>
3
+  <div style="width:100%">
4
+    <input style="width: 70%;" value="9C0F205A956F4D7EE6AB6D918E7E4D596CE05F08DBB5C4D16758BEF46F3FFC2D" type="text"
5
+      placeholder="Resource hash" id="searchBar" /><input type="button" value="GO" id="searchButton" />
6
+    <iframe id="contentFrame" frameBorder="0" style="width: 100%; height: 100%;"></iframe>
7
+  </div>
8
+</body>
9
+</html>

+ 87
- 0
src/index.ts View File

1
+import { app, BrowserWindow, ipcMain } from 'electron';
2
+import { xrpIO } from 'xrpio';
3
+import { writeFileSync, existsSync, mkdirSync } from 'fs';
4
+import { tns_rjsvm } from './RJSVMs/tns';
5
+
6
+// This allows TypeScript to pick up the magic constants that's auto-generated by Forge's Webpack
7
+// plugin that tells the Electron app where to look for the Webpack-bundled app code (depending on
8
+// whether you're running in development or production).
9
+
10
+declare const MAIN_WINDOW_WEBPACK_ENTRY: string;
11
+declare const MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY: string;
12
+
13
+const tur_conf = {
14
+  downloadsPath: '/home/caligvla/tur/tur-browser/downloads/',
15
+  rippleNode: 'wss://s.altnet.rippletest.net:51233'
16
+}
17
+
18
+const xrpio = new xrpIO(tur_conf.rippleNode)
19
+xrpio.connect()
20
+
21
+// Handle creating/removing shortcuts on Windows when installing/uninstalling.
22
+if (require('electron-squirrel-startup')) {
23
+  app.quit();
24
+}
25
+
26
+const createWindow = (): void => {
27
+  // Create the browser window.
28
+  const mainWindow = new BrowserWindow({
29
+    
30
+    height: 600,
31
+    width: 800,
32
+    webPreferences: {
33
+      preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
34
+      webSecurity: false,
35
+    },
36
+  });
37
+
38
+  // and load the index.html of the app.
39
+  mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);
40
+
41
+  // Open the DevTools.
42
+  mainWindow.webContents.openDevTools();
43
+};
44
+
45
+
46
+// This method will be called when Electron has finished
47
+// initialization and is ready to create browser windows.
48
+// Some APIs can only be used after this event occurs.
49
+app.on('ready', () => {
50
+  ipcMain.handle('xrpioDownload', async (event, args) => {
51
+    const path = `${tur_conf.downloadsPath}${args}.html`
52
+    if(existsSync(path)){
53
+      return path
54
+    }
55
+    const html = await xrpio.treeRead([args]);
56
+    mkdirSync(tur_conf.downloadsPath, { recursive: true });
57
+    writeFileSync(path, html);
58
+
59
+    return path
60
+  })
61
+
62
+  createWindow()
63
+});
64
+
65
+// Quit when all windows are closed, except on macOS. There, it's common
66
+// for applications and their menu bar to stay active until the user quits
67
+// explicitly with Cmd + Q.
68
+app.on('window-all-closed', () => {
69
+  if (process.platform !== 'darwin') {
70
+    app.quit();
71
+  }
72
+});
73
+
74
+app.on('activate', () => {
75
+  // On OS X it's common to re-create a window in the app when the
76
+  // dock icon is clicked and there are no other windows open.
77
+  if (BrowserWindow.getAllWindows().length === 0) {
78
+    createWindow();
79
+  }
80
+});
81
+
82
+
83
+
84
+// In this file you can include the rest of your app's specific main process
85
+// code. You can also put them in separate files and import them here.
86
+
87
+tns_rjsvm.connect()

+ 8
- 0
src/preload.ts View File

1
+// See the Electron documentation for details on how to use preload scripts:
2
+// https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts
3
+
4
+import { contextBridge, ipcRenderer } from "electron";
5
+
6
+contextBridge.exposeInMainWorld('electronAPI', {
7
+    xrpioDownload: (hash: string) => ipcRenderer.invoke('xrpioDownload', hash),
8
+})

+ 34
- 0
src/renderer.ts View File

1
+import './index.css';
2
+import { handleIpc } from 'tur-toolkit'
3
+declare const window: any
4
+
5
+//window.document.getElementById('contentFrame').addEventListener('ipc-message', console.log)
6
+
7
+handleIpc((event, source) => {
8
+    console.log(event, source)
9
+    switch(event.data.type){
10
+        case "Navigation":
11
+        httxrpNavigate(event.data.data)
12
+        break;
13
+
14
+        case "Transaction":
15
+        break;
16
+
17
+        default:
18
+        return;
19
+    }
20
+})
21
+
22
+const httxrpNavigate = async (resourceHash: string) => {
23
+    try{
24
+        const path = await window.electronAPI.xrpioDownload(resourceHash)
25
+        window.document.getElementById('contentFrame').setAttribute("src", `file://${path}`);
26
+    }catch(err){
27
+        console.log(err)
28
+    }
29
+}
30
+window.httxrpNavigate = httxrpNavigate
31
+
32
+window.document.getElementById('searchButton').addEventListener('click', async () => {
33
+    await window.httxrpNavigate(window.document.getElementById('searchBar').value)
34
+})

+ 3
- 0
src/types/util.ts View File

1
+export type AnyOf<T> = {
2
+    [key in keyof T]?: T[key] 
3
+}

+ 19
- 0
tsconfig.json View File

1
+{
2
+  "compilerOptions": {
3
+    "target": "ES6",
4
+    "allowJs": true,
5
+    "module": "commonjs",
6
+    "skipLibCheck": true,
7
+    "esModuleInterop": true,
8
+    "noImplicitAny": true,
9
+    "sourceMap": true,
10
+    "baseUrl": ".",
11
+    "outDir": "dist",
12
+    "moduleResolution": "node",
13
+    "resolveJsonModule": true,
14
+    "paths": {
15
+      "*": ["node_modules/*"]
16
+    }
17
+  },
18
+  "include": ["src/**/*"]
19
+}

+ 18
- 0
webpack.main.config.ts View File

1
+import type { Configuration } from 'webpack';
2
+
3
+import { rules } from './webpack.rules';
4
+
5
+export const mainConfig: Configuration = {
6
+  /**
7
+   * This is the main entry point for your application, it's the first file
8
+   * that runs in the main process.
9
+   */
10
+  entry: './src/index.ts',
11
+  // Put your normal webpack config below here
12
+  module: {
13
+    rules,
14
+  },
15
+  resolve: {
16
+    extensions: ['.js', '.ts', '.jsx', '.tsx', '.css', '.json'],
17
+  },
18
+};

+ 21
- 0
webpack.plugins.ts View File

1
+import type IForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
2
+const CopyPlugin = require('copy-webpack-plugin')
3
+
4
+// eslint-disable-next-line @typescript-eslint/no-var-requires
5
+const ForkTsCheckerWebpackPlugin: typeof IForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
6
+
7
+export const plugins = [
8
+  new ForkTsCheckerWebpackPlugin({
9
+    logger: 'webpack-infrastructure',
10
+  }),
11
+  /*
12
+  new CopyPlugin({
13
+    patterns: [
14
+      {
15
+        from: './src/webview-preload.js',
16
+        to: 'assets'
17
+      }
18
+    ]
19
+  }) 
20
+  */
21
+];

+ 19
- 0
webpack.renderer.config.ts View File

1
+import type { Configuration } from 'webpack';
2
+
3
+import { rules } from './webpack.rules';
4
+import { plugins } from './webpack.plugins';
5
+
6
+rules.push({
7
+  test: /\.css$/,
8
+  use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
9
+});
10
+
11
+export const rendererConfig: Configuration = {
12
+  module: {
13
+    rules,
14
+  },
15
+  plugins,
16
+  resolve: {
17
+    extensions: ['.js', '.ts', '.jsx', '.tsx', '.css'],
18
+  },
19
+};

+ 31
- 0
webpack.rules.ts View File

1
+import type { ModuleOptions } from 'webpack';
2
+
3
+export const rules: Required<ModuleOptions>['rules'] = [
4
+  // Add support for native node modules
5
+  {
6
+    // We're specifying native_modules in the test because the asset relocator loader generates a
7
+    // "fake" .node file which is really a cjs file.
8
+    test: /native_modules[/\\].+\.node$/,
9
+    use: 'node-loader',
10
+  },
11
+  {
12
+    test: /[/\\]node_modules[/\\].+\.(m?js|node)$/,
13
+    parser: { amd: false },
14
+    use: {
15
+      loader: '@vercel/webpack-asset-relocator-loader',
16
+      options: {
17
+        outputAssetBase: 'native_modules',
18
+      },
19
+    },
20
+  },
21
+  {
22
+    test: /\.tsx?$/,
23
+    exclude: /(node_modules|\.webpack)/,
24
+    use: {
25
+      loader: 'ts-loader',
26
+      options: {
27
+        transpileOnly: true,
28
+      },
29
+    },
30
+  },
31
+];

Loading…
Cancel
Save