mirror of
https://github.com/jeffvli/feishin.git
synced 2024-11-20 06:27:09 +01:00
Add initial files
This commit is contained in:
commit
4d64a96f75
18
.editorconfig
Normal file
18
.editorconfig
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# EditorConfig is awesome: http://EditorConfig.org
|
||||||
|
|
||||||
|
# https://github.com/jokeyrhyme/standard-editorconfig
|
||||||
|
|
||||||
|
# top-most EditorConfig file
|
||||||
|
root = true
|
||||||
|
|
||||||
|
# defaults
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
indent_size = 2
|
||||||
|
indent_style = space
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
39
.electron-builder.config.js
Normal file
39
.electron-builder.config.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/**
|
||||||
|
* TODO: Rewrite this config to ESM
|
||||||
|
* But currently electron-builder doesn't support ESM configs
|
||||||
|
* @see https://github.com/develar/read-config-file/issues/10
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {() => import('electron-builder').Configuration}
|
||||||
|
* @see https://www.electron.build/configuration/configuration
|
||||||
|
*/
|
||||||
|
module.exports = async function () {
|
||||||
|
const {getVersion} = await import('./version/getVersion.mjs');
|
||||||
|
|
||||||
|
return {
|
||||||
|
directories: {
|
||||||
|
output: 'dist',
|
||||||
|
buildResources: 'buildResources',
|
||||||
|
},
|
||||||
|
files: ['packages/**/dist/**'],
|
||||||
|
extraMetadata: {
|
||||||
|
version: getVersion(),
|
||||||
|
},
|
||||||
|
productName: 'Feishin',
|
||||||
|
appId: 'org.jeffvli.feishin',
|
||||||
|
artifactName: '${productName}-${version}-${os}-${arch}.${ext}',
|
||||||
|
win: {
|
||||||
|
target: ['nsis', 'zip'],
|
||||||
|
},
|
||||||
|
publish: {
|
||||||
|
provider: 'github',
|
||||||
|
owner: 'jeffvli',
|
||||||
|
repo: 'feishin',
|
||||||
|
},
|
||||||
|
// Specify linux target just for disabling snap compilation
|
||||||
|
linux: {
|
||||||
|
target: 'deb',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
51
.eslintrc.json
Normal file
51
.eslintrc.json
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
{
|
||||||
|
"root": true,
|
||||||
|
"env": {
|
||||||
|
"es2021": true,
|
||||||
|
"node": true,
|
||||||
|
"browser": false
|
||||||
|
},
|
||||||
|
"extends": [
|
||||||
|
"eslint:recommended",
|
||||||
|
/** @see https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#recommended-configs */
|
||||||
|
"plugin:@typescript-eslint/recommended"
|
||||||
|
],
|
||||||
|
"parser": "@typescript-eslint/parser",
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 12,
|
||||||
|
"sourceType": "module"
|
||||||
|
},
|
||||||
|
"plugins": ["@typescript-eslint"],
|
||||||
|
"ignorePatterns": ["node_modules/**", "**/dist/**"],
|
||||||
|
"rules": {
|
||||||
|
"@typescript-eslint/no-unused-vars": [
|
||||||
|
"warn",
|
||||||
|
{
|
||||||
|
"argsIgnorePattern": "^_",
|
||||||
|
"varsIgnorePattern": "^_"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"@typescript-eslint/no-var-requires": "off",
|
||||||
|
"@typescript-eslint/consistent-type-imports": "error",
|
||||||
|
/**
|
||||||
|
* Having a semicolon helps the optimizer interpret your code correctly.
|
||||||
|
* This avoids rare errors in optimized code.
|
||||||
|
* @see https://twitter.com/alex_kozack/status/1364210394328408066
|
||||||
|
*/
|
||||||
|
"semi": ["error", "always"],
|
||||||
|
/**
|
||||||
|
* This will make the history of changes in the hit a little cleaner
|
||||||
|
*/
|
||||||
|
"comma-dangle": ["warn", "always-multiline"],
|
||||||
|
/**
|
||||||
|
* Just for beauty
|
||||||
|
*/
|
||||||
|
"quotes": [
|
||||||
|
"warn",
|
||||||
|
"single",
|
||||||
|
{
|
||||||
|
"avoidEscape": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
4
.gitattributes
vendored
Normal file
4
.gitattributes
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.github/actions/**/*.js linguist-detectable=false
|
||||||
|
scripts/*.js linguist-detectable=false
|
||||||
|
*.config.js linguist-detectable=false
|
||||||
|
* text=auto eol=lf
|
11
.github/FUNDING.yml
vendored
Normal file
11
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
patreon: # Replace with a single Patreon username
|
||||||
|
open_collective: # Replace with a single Open Collective username
|
||||||
|
ko_fi: jeffvli
|
||||||
|
liberapay: #
|
||||||
|
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||||
|
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||||
|
issuehunt: # Replace with a single IssueHunt username
|
||||||
|
otechie: # Replace with a single Otechie username
|
||||||
|
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
28
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
28
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: ''
|
||||||
|
labels: bug
|
||||||
|
assignees: cawa-93
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**To Reproduce**
|
||||||
|
Steps to reproduce the behavior:
|
||||||
|
|
||||||
|
1. Go to '...'
|
||||||
|
2. Click on '....'
|
||||||
|
3. Scroll down to '....'
|
||||||
|
4. See error
|
||||||
|
|
||||||
|
**Expected behavior**
|
||||||
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
**Screenshots**
|
||||||
|
If applicable, add screenshots to help explain your problem.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
5
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
5
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
blank_issues_enabled: false
|
||||||
|
contact_links:
|
||||||
|
- name: Questions & Discussions
|
||||||
|
url: https://github.com/cawa-93/vite-electron-builder/discussions/categories/q-a
|
||||||
|
about: Use GitHub discussions for message-board style questions and discussions.
|
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this project
|
||||||
|
title: ''
|
||||||
|
labels: enhancement
|
||||||
|
assignees: cawa-93
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context or screenshots about the feature request here.
|
18
.github/renovate.json
vendored
Normal file
18
.github/renovate.json
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"extends": [
|
||||||
|
"config:base",
|
||||||
|
":semanticCommits",
|
||||||
|
":semanticCommitTypeAll(deps)",
|
||||||
|
":semanticCommitScopeDisabled",
|
||||||
|
":automergeAll",
|
||||||
|
":automergeBranch",
|
||||||
|
":disableDependencyDashboard",
|
||||||
|
":pinVersions",
|
||||||
|
":onlyNpm",
|
||||||
|
":label(dependencies)"
|
||||||
|
],
|
||||||
|
"gitNoVerify": [
|
||||||
|
"commit",
|
||||||
|
"push"
|
||||||
|
]
|
||||||
|
}
|
47
.github/workflows/ci.yml
vendored
Normal file
47
.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# This workflow is the entry point for all CI processes.
|
||||||
|
# It is from here that all other workflows are launched.
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- 'renovate/**'
|
||||||
|
paths-ignore:
|
||||||
|
- '.github/**'
|
||||||
|
- '!.github/workflows/ci.yml'
|
||||||
|
- '!.github/workflows/typechecking.yml'
|
||||||
|
- '!.github/workflows/tests.yml'
|
||||||
|
- '!.github/workflows/release.yml'
|
||||||
|
- '**.md'
|
||||||
|
- .editorconfig
|
||||||
|
- .gitignore
|
||||||
|
- '.idea/**'
|
||||||
|
- '.vscode/**'
|
||||||
|
pull_request:
|
||||||
|
paths-ignore:
|
||||||
|
- '.github/**'
|
||||||
|
- '!.github/workflows/ci.yml'
|
||||||
|
- '!.github/workflows/typechecking.yml'
|
||||||
|
- '!.github/workflows/tests.yml'
|
||||||
|
- '!.github/workflows/release.yml'
|
||||||
|
- '**.md'
|
||||||
|
- .editorconfig
|
||||||
|
- .gitignore
|
||||||
|
- '.idea/**'
|
||||||
|
- '.vscode/**'
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ci-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
typechecking:
|
||||||
|
uses: ./.github/workflows/typechecking.yml
|
||||||
|
tests:
|
||||||
|
uses: ./.github/workflows/tests.yml
|
||||||
|
draft_release:
|
||||||
|
with:
|
||||||
|
dry-run: ${{ github.event_name != 'push' || github.ref_name != 'main' }}
|
||||||
|
needs: [ typechecking, tests ]
|
||||||
|
uses: ./.github/workflows/release.yml
|
||||||
|
|
65
.github/workflows/lint.yml
vendored
Normal file
65
.github/workflows/lint.yml
vendored
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- '**.js'
|
||||||
|
- '**.mjs'
|
||||||
|
- '**.cjs'
|
||||||
|
- '**.jsx'
|
||||||
|
- '**.ts'
|
||||||
|
- '**.mts'
|
||||||
|
- '**.cts'
|
||||||
|
- '**.tsx'
|
||||||
|
- '**.vue'
|
||||||
|
- '**.json'
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- '**.js'
|
||||||
|
- '**.mjs'
|
||||||
|
- '**.cjs'
|
||||||
|
- '**.jsx'
|
||||||
|
- '**.ts'
|
||||||
|
- '**.mts'
|
||||||
|
- '**.cts'
|
||||||
|
- '**.tsx'
|
||||||
|
- '**.vue'
|
||||||
|
- '**.json'
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: lint-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: 'bash'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
eslint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 16 # Need for npm >=7.7
|
||||||
|
cache: 'npm'
|
||||||
|
|
||||||
|
- run: npm ci
|
||||||
|
env:
|
||||||
|
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
|
||||||
|
|
||||||
|
- run: npm run lint --if-present
|
||||||
|
|
||||||
|
# This job just check code style for in-template contributions.
|
||||||
|
code-style:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 16 # Need for npm >=7.7
|
||||||
|
cache: 'npm'
|
||||||
|
|
||||||
|
- run: npm i prettier
|
||||||
|
- run: npx prettier --check "**/*.{js,mjs,cjs,jsx,ts,mts,cts,tsx,vue,json}"
|
60
.github/workflows/release.yml
vendored
Normal file
60
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
name: Release
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
dry-run:
|
||||||
|
description: 'Compiles the app but not upload artifacts to distribution server'
|
||||||
|
default: false
|
||||||
|
required: false
|
||||||
|
type: boolean
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: release-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: 'bash'
|
||||||
|
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
draft_release:
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: true
|
||||||
|
matrix:
|
||||||
|
os: [ macos-latest, ubuntu-latest, windows-latest ]
|
||||||
|
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 16 # Need for npm >=7.7
|
||||||
|
cache: 'npm'
|
||||||
|
|
||||||
|
- run: npm ci
|
||||||
|
env:
|
||||||
|
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
|
||||||
|
|
||||||
|
- run: npm run build
|
||||||
|
|
||||||
|
- name: Compile artifacts ${{ inputs.dry-run && '' || 'and upload them to github release' }}
|
||||||
|
# I use this action because it is capable of retrying multiple times if there are any issues with the distribution server
|
||||||
|
uses: nick-fields/retry@v2
|
||||||
|
with:
|
||||||
|
timeout_minutes: 15
|
||||||
|
max_attempts: 3
|
||||||
|
retry_on: error
|
||||||
|
shell: 'bash'
|
||||||
|
command: npx --no-install electron-builder --config .electron-builder.config.js --publish ${{ inputs.dry-run && 'never' || 'always' }}
|
||||||
|
env:
|
||||||
|
# Code Signing params
|
||||||
|
# See https://www.electron.build/code-signing
|
||||||
|
# CSC_LINK: ''
|
||||||
|
# CSC_KEY_PASSWORD: ''
|
||||||
|
# Publishing artifacts
|
||||||
|
GH_TOKEN: ${{ secrets.github_token }} # GitHub token, automatically provided (No need to define this secret in the repo settings)
|
53
.github/workflows/tests.yml
vendored
Normal file
53
.github/workflows/tests.yml
vendored
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
name: Tests
|
||||||
|
on: [ workflow_call ]
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: tests-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: 'bash'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
unit:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ windows-latest, ubuntu-latest, macos-latest ]
|
||||||
|
package: [ main, preload, renderer ]
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 16
|
||||||
|
cache: 'npm'
|
||||||
|
- run: npm ci
|
||||||
|
env:
|
||||||
|
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
|
||||||
|
- run: npm run test:${{ matrix.package }} --if-present
|
||||||
|
|
||||||
|
e2e:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ windows-latest, ubuntu-latest, macos-latest ]
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 16
|
||||||
|
cache: 'npm'
|
||||||
|
- run: npm ci
|
||||||
|
env:
|
||||||
|
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
|
||||||
|
|
||||||
|
# I ran into problems trying to run an electron window in ubuntu due to a missing graphics server.
|
||||||
|
# That's why this special command for Ubuntu is here
|
||||||
|
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test:e2e --if-present
|
||||||
|
if: matrix.os == 'ubuntu-latest'
|
||||||
|
|
||||||
|
- run: npm run test:e2e --if-present
|
||||||
|
if: matrix.os != 'ubuntu-latest'
|
27
.github/workflows/typechecking.yml
vendored
Normal file
27
.github/workflows/typechecking.yml
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
name: Typechecking
|
||||||
|
on: [ workflow_call ]
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: typechecking-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: 'bash'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
typescript:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 16 # Need for npm >=7.7
|
||||||
|
cache: 'npm'
|
||||||
|
|
||||||
|
- run: npm ci
|
||||||
|
env:
|
||||||
|
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
|
||||||
|
|
||||||
|
- run: npm run typecheck --if-present
|
58
.gitignore
vendored
Normal file
58
.gitignore
vendored
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
node_modules
|
||||||
|
.DS_Store
|
||||||
|
dist
|
||||||
|
*.local
|
||||||
|
thumbs.db
|
||||||
|
|
||||||
|
.eslintcache
|
||||||
|
.browserslistrc
|
||||||
|
.electron-vendors.cache.json
|
||||||
|
|
||||||
|
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||||
|
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||||
|
|
||||||
|
# User-specific stuff
|
||||||
|
.idea/**/workspace.xml
|
||||||
|
.idea/**/tasks.xml
|
||||||
|
.idea/**/usage.statistics.xml
|
||||||
|
.idea/**/dictionaries
|
||||||
|
.idea/**/shelf
|
||||||
|
|
||||||
|
# Generated files
|
||||||
|
.idea/**/contentModel.xml
|
||||||
|
|
||||||
|
# Sensitive or high-churn files
|
||||||
|
.idea/**/dataSources/
|
||||||
|
.idea/**/dataSources.ids
|
||||||
|
.idea/**/dataSources.local.xml
|
||||||
|
.idea/**/sqlDataSources.xml
|
||||||
|
.idea/**/dynamic.xml
|
||||||
|
.idea/**/uiDesigner.xml
|
||||||
|
.idea/**/dbnavigator.xml
|
||||||
|
|
||||||
|
# Gradle
|
||||||
|
.idea/**/gradle.xml
|
||||||
|
.idea/**/libraries
|
||||||
|
|
||||||
|
# Gradle and Maven with auto-import
|
||||||
|
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||||
|
# since they will be recreated, and may cause churn. Uncomment if using
|
||||||
|
# auto-import.
|
||||||
|
.idea/artifacts
|
||||||
|
.idea/compiler.xml
|
||||||
|
.idea/jarRepositories.xml
|
||||||
|
.idea/modules.xml
|
||||||
|
.idea/*.iml
|
||||||
|
.idea/modules
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
# Mongo Explorer plugin
|
||||||
|
.idea/**/mongoSettings.xml
|
||||||
|
|
||||||
|
# File-based project format
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# Editor-based Rest Client
|
||||||
|
.idea/httpRequests
|
||||||
|
/.idea/csv-plugin.xml
|
65
.idea/codeStyles/Project.xml
Normal file
65
.idea/codeStyles/Project.xml
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<code_scheme name="Project" version="173">
|
||||||
|
<option name="LINE_SEPARATOR" value=" " />
|
||||||
|
<HTMLCodeStyleSettings>
|
||||||
|
<option name="HTML_ATTRIBUTE_WRAP" value="4" />
|
||||||
|
<option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
|
||||||
|
<option name="HTML_ENFORCE_QUOTES" value="true" />
|
||||||
|
</HTMLCodeStyleSettings>
|
||||||
|
<JSCodeStyleSettings version="0">
|
||||||
|
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
||||||
|
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
||||||
|
<option name="USE_DOUBLE_QUOTES" value="false" />
|
||||||
|
<option name="FORCE_QUOTE_STYlE" value="true" />
|
||||||
|
<option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
|
||||||
|
<option name="SPACES_WITHIN_OBJECT_TYPE_BRACES" value="false" />
|
||||||
|
</JSCodeStyleSettings>
|
||||||
|
<JSON>
|
||||||
|
<option name="OBJECT_WRAPPING" value="5" />
|
||||||
|
<option name="ARRAY_WRAPPING" value="5" />
|
||||||
|
</JSON>
|
||||||
|
<TypeScriptCodeStyleSettings version="0">
|
||||||
|
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
||||||
|
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
||||||
|
<option name="USE_DOUBLE_QUOTES" value="false" />
|
||||||
|
<option name="FORCE_QUOTE_STYlE" value="true" />
|
||||||
|
<option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
|
||||||
|
<option name="SPACES_WITHIN_OBJECT_TYPE_BRACES" value="false" />
|
||||||
|
</TypeScriptCodeStyleSettings>
|
||||||
|
<VueCodeStyleSettings>
|
||||||
|
<option name="UNIFORM_INDENT" value="false" />
|
||||||
|
<option name="INTERPOLATION_NEW_LINE_AFTER_START_DELIMITER" value="false" />
|
||||||
|
<option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
|
||||||
|
</VueCodeStyleSettings>
|
||||||
|
<codeStyleSettings language="HTML">
|
||||||
|
<option name="SOFT_MARGINS" value="100" />
|
||||||
|
<indentOptions>
|
||||||
|
<option name="INDENT_SIZE" value="2" />
|
||||||
|
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
||||||
|
<option name="TAB_SIZE" value="2" />
|
||||||
|
</indentOptions>
|
||||||
|
</codeStyleSettings>
|
||||||
|
<codeStyleSettings language="JavaScript">
|
||||||
|
<option name="SOFT_MARGINS" value="100" />
|
||||||
|
<indentOptions>
|
||||||
|
<option name="INDENT_SIZE" value="2" />
|
||||||
|
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
||||||
|
<option name="TAB_SIZE" value="2" />
|
||||||
|
</indentOptions>
|
||||||
|
</codeStyleSettings>
|
||||||
|
<codeStyleSettings language="TypeScript">
|
||||||
|
<option name="SOFT_MARGINS" value="100" />
|
||||||
|
<indentOptions>
|
||||||
|
<option name="INDENT_SIZE" value="2" />
|
||||||
|
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
||||||
|
<option name="TAB_SIZE" value="2" />
|
||||||
|
</indentOptions>
|
||||||
|
</codeStyleSettings>
|
||||||
|
<codeStyleSettings language="Vue">
|
||||||
|
<option name="SOFT_MARGINS" value="120" />
|
||||||
|
<indentOptions>
|
||||||
|
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
||||||
|
</indentOptions>
|
||||||
|
</codeStyleSettings>
|
||||||
|
</code_scheme>
|
||||||
|
</component>
|
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<state>
|
||||||
|
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||||
|
</state>
|
||||||
|
</component>
|
28
.idea/deployment.xml
Normal file
28
.idea/deployment.xml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="PublishConfigData" remoteFilesAllowedToDisappearOnAutoupload="false">
|
||||||
|
<serverData>
|
||||||
|
<paths name="ihappymama-aliexpress">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
<paths name="iosico.com">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
<paths name="somespeed.com">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
</serverData>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/inspectionProfiles/Project_Default.xml
Normal file
6
.idea/inspectionProfiles/Project_Default.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
6
.idea/jsLibraryMappings.xml
Normal file
6
.idea/jsLibraryMappings.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="JavaScriptLibraryMappings">
|
||||||
|
<includedPredefinedLibrary name="Node.js Core" />
|
||||||
|
</component>
|
||||||
|
</project>
|
7
.idea/jsLinters/eslint.xml
Normal file
7
.idea/jsLinters/eslint.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="EslintConfiguration">
|
||||||
|
<work-dir-patterns value="src/**/*.{ts,vue} {bin,config}/**/*.js" />
|
||||||
|
<option name="fix-on-save" value="true" />
|
||||||
|
</component>
|
||||||
|
</project>
|
28
.idea/jsonSchemas.xml
Normal file
28
.idea/jsonSchemas.xml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="JsonSchemaMappingsProjectConfiguration">
|
||||||
|
<state>
|
||||||
|
<map>
|
||||||
|
<entry key="GitHub Workflow">
|
||||||
|
<value>
|
||||||
|
<SchemaInfo>
|
||||||
|
<option name="name" value="GitHub Workflow" />
|
||||||
|
<option name="relativePathToSchema" value="https://json.schemastore.org/github-workflow.json" />
|
||||||
|
<option name="applicationDefined" value="true" />
|
||||||
|
<option name="patterns">
|
||||||
|
<list>
|
||||||
|
<Item>
|
||||||
|
<option name="path" value=".github/workflows/release.yml" />
|
||||||
|
</Item>
|
||||||
|
<Item>
|
||||||
|
<option name="path" value=".github/workflows/ci.yml" />
|
||||||
|
</Item>
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</SchemaInfo>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</state>
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/vite-electron-builder.iml" filepath="$PROJECT_DIR$/.idea/vite-electron-builder.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/prettier.xml
Normal file
8
.idea/prettier.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="PrettierConfiguration">
|
||||||
|
<option name="myRunOnSave" value="true" />
|
||||||
|
<option name="myRunOnReformat" value="true" />
|
||||||
|
<option name="myFilesPattern" value="{**/*,*}.{js,mjs,cjs,ts,mts,cts,vue,json}" />
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
19
.idea/vite-electron-builder.iml
Normal file
19
.idea/vite-electron-builder.iml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/packages/main/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/packages/preload/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/packages/renderer/src" isTestSource="false" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/packages/renderer/dist" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/dist" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/packages/main/dist" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/packages/preload/dist" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/packages/preload/node_modules" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/packages/main/node_modules" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
14
.idea/webResources.xml
Normal file
14
.idea/webResources.xml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="WebResourcesPaths">
|
||||||
|
<contentEntries>
|
||||||
|
<entry url="file://$PROJECT_DIR$">
|
||||||
|
<entryData>
|
||||||
|
<resourceRoots>
|
||||||
|
<path value="file://$PROJECT_DIR$/packages/renderer/assets" />
|
||||||
|
</resourceRoots>
|
||||||
|
</entryData>
|
||||||
|
</entry>
|
||||||
|
</contentEntries>
|
||||||
|
</component>
|
||||||
|
</project>
|
24
.nano-staged.mjs
Normal file
24
.nano-staged.mjs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import {resolve, sep} from 'path';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
'*.{js,mjs,cjs,ts,mts,cts,vue}': 'eslint --cache --fix',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run typechecking if any type-sensitive files or project dependencies was changed
|
||||||
|
* @param {string[]} filenames
|
||||||
|
* @return {string[]}
|
||||||
|
*/
|
||||||
|
'{package-lock.json,packages/**/{*.ts,*.vue,tsconfig.json}}': ({filenames}) => {
|
||||||
|
// if dependencies was changed run type checking for all packages
|
||||||
|
if (filenames.some(f => f.endsWith('package-lock.json'))) {
|
||||||
|
return ['npm run typecheck --if-present'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// else run type checking for staged packages
|
||||||
|
const fileNameToPackageName = filename =>
|
||||||
|
filename.replace(resolve(process.cwd(), 'packages') + sep, '').split(sep)[0];
|
||||||
|
return [...new Set(filenames.map(fileNameToPackageName))].map(
|
||||||
|
p => `npm run typecheck:${p} --if-present`,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
10
.prettierignore
Normal file
10
.prettierignore
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
**/node_modules
|
||||||
|
**/dist
|
||||||
|
**/*.svg
|
||||||
|
|
||||||
|
package.json
|
||||||
|
package-lock.json
|
||||||
|
.electron-vendors.cache.json
|
||||||
|
|
||||||
|
.github
|
||||||
|
.idea
|
20
.prettierrc
Normal file
20
.prettierrc
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"printWidth": 100,
|
||||||
|
"semi": true,
|
||||||
|
"singleQuote": true,
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": ["**/*.css", "**/*.scss", "**/*.html"],
|
||||||
|
"options": {
|
||||||
|
"singleQuote": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"trailingComma": "all",
|
||||||
|
"bracketSpacing": true,
|
||||||
|
"arrowParens": "always",
|
||||||
|
"proseWrap": "never",
|
||||||
|
"htmlWhitespaceSensitivity": "strict",
|
||||||
|
"endOfLine": "lf",
|
||||||
|
"singleAttributePerLine": true
|
||||||
|
}
|
3
.simple-git-hooks.json
Normal file
3
.simple-git-hooks.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"pre-commit": "npx nano-staged"
|
||||||
|
}
|
28
.stylelintrc.json
Normal file
28
.stylelintrc.json
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"processors": ["stylelint-processor-styled-components"],
|
||||||
|
"customSyntax": "postcss-scss",
|
||||||
|
"extends": [
|
||||||
|
"stylelint-config-standard-scss",
|
||||||
|
"stylelint-config-styled-components",
|
||||||
|
"stylelint-config-rational-order"
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"color-function-notation": ["legacy"],
|
||||||
|
"declaration-empty-line-before": null,
|
||||||
|
"order/properties-order": [],
|
||||||
|
"plugin/rational-order": [
|
||||||
|
true,
|
||||||
|
{
|
||||||
|
"border-in-box-model": false,
|
||||||
|
"empty-line-between-groups": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"string-quotes": "single",
|
||||||
|
"declaration-block-no-redundant-longhand-properties": null,
|
||||||
|
"selector-class-pattern": null,
|
||||||
|
"selector-type-case": ["lower", { "ignoreTypes": ["/^\\$\\w+/"] }],
|
||||||
|
"selector-type-no-unknown": [true, { "ignoreTypes": ["/-styled-mixin/", "/^\\$\\w+/"] }],
|
||||||
|
"value-keyword-case": ["lower", { "ignoreKeywords": ["dummyValue"] }],
|
||||||
|
"declaration-colon-newline-after": null
|
||||||
|
}
|
||||||
|
}
|
8
.vscode/extensions.json
vendored
Normal file
8
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"recommendations": [
|
||||||
|
"dbaeumer.vscode-eslint",
|
||||||
|
"stylelint.vscode-stylelint",
|
||||||
|
"esbenp.prettier-vscode",
|
||||||
|
"ms-vscode.vscode-typescript-next"
|
||||||
|
]
|
||||||
|
}
|
13
.vscode/launch.json
vendored
Normal file
13
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug Main Process",
|
||||||
|
"skipFiles": ["<node_internals>/**"],
|
||||||
|
"program": "${workspaceFolder}\\scripts\\watch.mjs",
|
||||||
|
"autoAttachChildProcesses": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
637
LICENSE
Normal file
637
LICENSE
Normal file
@ -0,0 +1,637 @@
|
|||||||
|
Copyright (C) 2022 jeffvli
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
305
README.md
Normal file
305
README.md
Normal file
@ -0,0 +1,305 @@
|
|||||||
|
# Vite Electron Builder Boilerplate
|
||||||
|
|
||||||
|
|
||||||
|
[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct-single.svg)](https://stand-with-ukraine.pp.ua)
|
||||||
|
|
||||||
|
[![GitHub issues by-label](https://img.shields.io/github/issues/cawa-93/vite-electron-builder/help%20wanted?label=issues%20need%20help&logo=github)](https://github.com/cawa-93/vite-electron-builder/issues?q=label%3A%22help+wanted%22+is%3Aopen+is%3Aissue)
|
||||||
|
[![Required Node.JS >= v16.13](https://img.shields.io/static/v1?label=node&message=%3E=16.13&logo=node.js&color)](https://nodejs.org/about/releases/)
|
||||||
|
[![Required npm >= v8.1](https://img.shields.io/static/v1?label=npm&message=%3E=8.1&logo=npm&color)](https://github.com/npm/cli/releases)
|
||||||
|
|
||||||
|
> Vite+Electron = 🔥
|
||||||
|
|
||||||
|
This is a template for secure electron applications. Written following the latest safety requirements, recommendations
|
||||||
|
and best practices.
|
||||||
|
|
||||||
|
Under the hood is [Vite] — A next-generation blazing fast bundler, and [electron-builder] for packaging.
|
||||||
|
|
||||||
|
## Get started
|
||||||
|
|
||||||
|
Follow these steps to get started with the template:
|
||||||
|
|
||||||
|
1. Click the **[Use this template](https://github.com/cawa-93/vite-electron-builder/generate)** button (you must be
|
||||||
|
logged in) or just clone this repo.
|
||||||
|
2. If you want to use another package manager don't forget to edit [`.github/workflows`](/.github/workflows) -- it
|
||||||
|
uses `npm` by default.
|
||||||
|
|
||||||
|
That's all you need. 😉
|
||||||
|
|
||||||
|
**Note**: This template uses npm v7 feature — [**Installing Peer Dependencies
|
||||||
|
Automatically**](https://github.com/npm/rfcs/blob/latest/implemented/0025-install-peer-deps.md). If you are using a
|
||||||
|
different package manager, you may need to install some peerDependencies manually.
|
||||||
|
|
||||||
|
**Note**: Find more useful forks [here](https://github.com/cawa-93/vite-electron-builder/discussions/categories/forks).
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
### Electron [![Electron version](https://img.shields.io/github/package-json/dependency-version/cawa-93/vite-electron-builder/dev/electron?label=%20)][electron]
|
||||||
|
|
||||||
|
- This template uses the latest electron version with all the latest security patches.
|
||||||
|
- The architecture of the application is built according to the
|
||||||
|
security [guides](https://www.electronjs.org/docs/tutorial/security) and best practices.
|
||||||
|
- The latest version of the [electron-builder] is used to package the application.
|
||||||
|
|
||||||
|
### Vite [![Vite version](https://img.shields.io/github/package-json/dependency-version/cawa-93/vite-electron-builder/dev/vite?label=%20)][vite]
|
||||||
|
|
||||||
|
- [Vite] is used to bundle all source codes. It's an extremely fast bundler, that has a vast array of amazing features.
|
||||||
|
You can learn more about how it is arranged in [this](https://www.youtube.com/watch?v=xXrhg26VCSc) video.
|
||||||
|
- Vite [supports](https://vitejs.dev/guide/env-and-mode.html) reading `.env` files. You can also specify the types of
|
||||||
|
your environment variables in [`types/env.d.ts`](types/env.d.ts).
|
||||||
|
- Automatic hot-reloads for the `Main` and `Renderer` processes.
|
||||||
|
|
||||||
|
Vite provides many useful features, such as: `TypeScript`, `TSX/JSX`, `CSS/JSON Importing`, `CSS Modules`
|
||||||
|
, `Web Assembly` and much more.
|
||||||
|
|
||||||
|
[See all Vite features](https://vitejs.dev/guide/features.html).
|
||||||
|
|
||||||
|
### TypeScript [![TypeScript version](https://img.shields.io/github/package-json/dependency-version/cawa-93/vite-electron-builder/dev/typescript?label=%20)][typescript] (optional)
|
||||||
|
|
||||||
|
- The latest version of TypeScript is used for all the source code.
|
||||||
|
- **Vite** supports TypeScript out of the box. However, it does not support type checking.
|
||||||
|
- Code formatting rules follow the latest TypeScript recommendations and best practices thanks
|
||||||
|
to [@typescript-eslint/eslint-plugin](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin).
|
||||||
|
|
||||||
|
**[See this discussion](https://github.com/cawa-93/vite-electron-builder/discussions/339)** if you want completely
|
||||||
|
remove TypeScript.
|
||||||
|
|
||||||
|
### Vue [![Vue version](https://img.shields.io/github/package-json/dependency-version/cawa-93/vite-electron-builder/vue?label=%20&)][vue] (optional)
|
||||||
|
|
||||||
|
- By default, web pages are built using [Vue]. However, you can easily change that. Or not use additional frameworks at
|
||||||
|
all.
|
||||||
|
- Code formatting rules follow the latest Vue recommendations and best practices thanks to [eslint-plugin-vue].
|
||||||
|
|
||||||
|
See [examples of web pages for different frameworks](https://github.com/vitejs/vite/tree/main/packages/create-vite).
|
||||||
|
|
||||||
|
### Continuous Integration
|
||||||
|
|
||||||
|
- The configured workflow will check the types for each push and PR.
|
||||||
|
- The configured workflow will check the code style for each push and PR.
|
||||||
|
- **Automatic tests**
|
||||||
|
used [Vitest ![Vitest version](https://img.shields.io/github/package-json/dependency-version/cawa-93/vite-electron-builder/dev/vitest?label=%20&color=yellow)][vitest]
|
||||||
|
-- A blazing fast test framework powered by Vite.
|
||||||
|
- Unit tests are placed within each package and are ran separately.
|
||||||
|
- End-to-end tests are placed in the root [`tests`](tests) directory and use [playwright].
|
||||||
|
|
||||||
|
![зображення](https://user-images.githubusercontent.com/1662812/204089645-d0209ce2-7259-4b66-ac71-22a7f608be35.png)
|
||||||
|
|
||||||
|
|
||||||
|
### Publishing
|
||||||
|
|
||||||
|
- Each time you push changes to the `main` branch, the [`release`](.github/workflows/release.yml) workflow starts, which creates a new draft release. For each next commit will be created and replaced artifacts. That way you will always have draft with latest artifacts, and the release can be published once it is ready.
|
||||||
|
- Code signing supported. See [`release` workflow](.github/workflows/release.yml).
|
||||||
|
- **Auto-update is supported**. After the release is published, all client applications will download the new version
|
||||||
|
and install updates silently.
|
||||||
|
|
||||||
|
This template configured for GitHub, but electron-builder supports multiple auto-update servers. See [docs](https://www.electron.build/configuration/publish).
|
||||||
|
|
||||||
|
## How it works
|
||||||
|
|
||||||
|
The template requires a minimum amount [dependencies](package.json). Only **Vite** is used for building, nothing more.
|
||||||
|
|
||||||
|
### Project Structure
|
||||||
|
|
||||||
|
The structure of this template is very similar to the structure of a monorepo.
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
flowchart TB;
|
||||||
|
|
||||||
|
packages/preload <-. IPC Messages .-> packages/main
|
||||||
|
|
||||||
|
subgraph packages/main
|
||||||
|
M[index.ts] --> EM[Electron Main Process Modules]
|
||||||
|
M --> N2[Node.js API]
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
subgraph packages/preload
|
||||||
|
P[index.ts] --> N[Node.js API]
|
||||||
|
P --> ED[External dependencies]
|
||||||
|
P --> ER[Electron Renderer Process Modules]
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
subgraph packages/renderer
|
||||||
|
R[index.html] --> W[Web API]
|
||||||
|
R --> BD[Bundled dependencies]
|
||||||
|
R --> F[Web Frameforks]
|
||||||
|
end
|
||||||
|
|
||||||
|
packages/renderer -- Call Exposed API --> P
|
||||||
|
```
|
||||||
|
|
||||||
|
The entire source code of the project is divided into three modules (packages) that are each bundled independently:
|
||||||
|
|
||||||
|
- [`packages/renderer`](packages/renderer). Responsible for the contents of the application window. In fact, it is a
|
||||||
|
regular web application. In developer mode, you can even open it in a browser. The development and build process is
|
||||||
|
the same as for classic web applications. Access to low-level API electrons or Node.js is done through the _preload_
|
||||||
|
layer.
|
||||||
|
- [`packages/preload`](packages/preload). Acts as an intermediate bridge between the _renderer_ process and the API
|
||||||
|
exposed by electron and Node.js. Runs in an _isolated browser context_, but has direct access to the full Node.js
|
||||||
|
functionality.
|
||||||
|
See [Checklist: Security Recommendations](https://www.electronjs.org/docs/tutorial/security#2-do-not-enable-nodejs-integration-for-remote-content)
|
||||||
|
.
|
||||||
|
- [`packages/main`](packages/main)
|
||||||
|
Electron [**main script**](https://www.electronjs.org/docs/tutorial/quick-start#create-the-main-script-file). This is
|
||||||
|
the main process that powers the application. It manages creating and handling the spawned BrowserWindow, setting and
|
||||||
|
enforcing secure permissions and request handlers. You can also configure it to do much more as per your need, such
|
||||||
|
as: logging, reporting statistics and health status among others.
|
||||||
|
|
||||||
|
### Build web resources
|
||||||
|
|
||||||
|
The `main` and `preload` packages are built in [library mode](https://vitejs.dev/guide/build.html#library-mode) as it is
|
||||||
|
simple javascript.
|
||||||
|
The `renderer` package builds as a regular web app.
|
||||||
|
|
||||||
|
### Compile App
|
||||||
|
|
||||||
|
The next step is to package a ready to distribute Electron app for macOS, Windows and Linux with "auto update" support
|
||||||
|
out of the box.
|
||||||
|
|
||||||
|
To do this, use [electron-builder]:
|
||||||
|
|
||||||
|
- Using the npm script `compile`: This script is configured to compile the application as quickly as possible. It is not
|
||||||
|
ready for distribution, it is compiled only for the current platform and is used for debugging.
|
||||||
|
- Using GitHub Actions: The application is compiled for any platform and ready-to-distribute files are automatically
|
||||||
|
added as a draft to the GitHub releases page.
|
||||||
|
|
||||||
|
### Working with dependencies
|
||||||
|
|
||||||
|
Because the `renderer` works and builds like a _regular web application_, you can only use dependencies that support the
|
||||||
|
browser or compile to a browser-friendly format.
|
||||||
|
|
||||||
|
This means that in the `renderer` you are free to use any frontend dependencies such as Vue, React, lodash, axios and so
|
||||||
|
on.However, you _CANNOT_ use any native Node.js APIs, such as, `systeminformation`. These APIs are _only_ available in
|
||||||
|
a Node.js runtime environment and will cause your application to crash if used in the `renderer` layer. Instead, if you
|
||||||
|
need access to Node.js runtime APIs in your frontend, export a function form the `preload` package.
|
||||||
|
|
||||||
|
All dependencies that require Node.js api can be used in
|
||||||
|
the [`preload` script](https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts).
|
||||||
|
|
||||||
|
#### Expose in main world
|
||||||
|
Here is an example. Let's say you need to read some data from the file system or database in the renderer.
|
||||||
|
|
||||||
|
In the preload context, create a function that reads and returns data. To make the function announced in the preload
|
||||||
|
available in the render, you usually need to call
|
||||||
|
the [`electron.contextBridge.exposeInMainWorld`](https://www.electronjs.org/ru/docs/latest/api/context-bridge). However,
|
||||||
|
this template uses the [unplugin-auto-expose](https://github.com/cawa-93/unplugin-auto-expose) plugin, so you just need
|
||||||
|
to export the method from the preload. The `exposeInMainWorld` will be called automatically.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// preload/index.ts
|
||||||
|
import { readFile } from 'node:fs/promises';
|
||||||
|
|
||||||
|
// Encapsulate types if you use typescript
|
||||||
|
interface UserData {
|
||||||
|
prop: string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Encapsulate all node.js api
|
||||||
|
// Everything you exported from preload/index.ts may be called in renderer
|
||||||
|
export function getUserData(): Promise<UserData> {
|
||||||
|
return readFile('/path/to/file/in/user/filesystem.json', {encoding:'utf8'}).then(JSON.parse);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Now you can import and call the method in renderer
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// renderer/anywere/component.ts
|
||||||
|
import { getUserData } from '#preload'
|
||||||
|
const userData = await getUserData()
|
||||||
|
```
|
||||||
|
|
||||||
|
[Read more about Security Considerations](https://www.electronjs.org/docs/tutorial/context-isolation#security-considerations).
|
||||||
|
|
||||||
|
### Working with Electron API
|
||||||
|
|
||||||
|
Although the preload has access to all of Node.js's API, it **still runs in the BrowserWindow context**, so a limited
|
||||||
|
electron modules are available in it. Check the [electron docs](https://www.electronjs.org/ru/docs/latest/api/clipboard)
|
||||||
|
for full list of available methods.
|
||||||
|
|
||||||
|
All other electron methods can be invoked in the `main`.
|
||||||
|
|
||||||
|
As a result, the architecture of interaction between all modules is as follows:
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
renderer->>+preload: Read data from file system
|
||||||
|
preload->>-renderer: Data
|
||||||
|
renderer->>preload: Maximize window
|
||||||
|
activate preload
|
||||||
|
preload-->>main: Invoke IPC command
|
||||||
|
activate main
|
||||||
|
main-->>preload: IPC response
|
||||||
|
deactivate main
|
||||||
|
preload->>renderer: Window maximized
|
||||||
|
deactivate preload
|
||||||
|
```
|
||||||
|
|
||||||
|
[Read more about Inter-Process Communication](https://www.electronjs.org/docs/latest/tutorial/ipc)
|
||||||
|
|
||||||
|
### Modes and Environment Variables
|
||||||
|
|
||||||
|
All environment variables are set as part of the `import.meta`, so you can access them vie the following
|
||||||
|
way: `import.meta.env`.
|
||||||
|
|
||||||
|
If you are using TypeScript and want to get code completion you must add all the environment variables to
|
||||||
|
the [`ImportMetaEnv` in `types/env.d.ts`](types/env.d.ts).
|
||||||
|
|
||||||
|
The mode option is used to specify the value of `import.meta.env.MODE` and the corresponding environment variables files
|
||||||
|
that need to be loaded.
|
||||||
|
|
||||||
|
By default, there are two modes:
|
||||||
|
|
||||||
|
- `production` is used by default
|
||||||
|
- `development` is used by `npm run watch` script
|
||||||
|
|
||||||
|
When running the build script, the environment variables are loaded from the following files in your project root:
|
||||||
|
|
||||||
|
```
|
||||||
|
.env # loaded in all cases
|
||||||
|
.env.local # loaded in all cases, ignored by git
|
||||||
|
.env.[mode] # only loaded in specified env mode
|
||||||
|
.env.[mode].local # only loaded in specified env mode, ignored by git
|
||||||
|
```
|
||||||
|
|
||||||
|
To prevent accidentally leaking env variables to the client, only variables prefixed with `VITE_` are exposed to your
|
||||||
|
Vite-processed code.
|
||||||
|
|
||||||
|
For example let's take the following `.env` file:
|
||||||
|
|
||||||
|
```
|
||||||
|
DB_PASSWORD=foobar
|
||||||
|
VITE_SOME_KEY=123
|
||||||
|
```
|
||||||
|
|
||||||
|
Only `VITE_SOME_KEY` will be exposed as `import.meta.env.VITE_SOME_KEY` to your client source code, but `DB_PASSWORD`
|
||||||
|
will not.
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
See [Contributing Guide](contributing.md).
|
||||||
|
|
||||||
|
|
||||||
|
[vite]: https://github.com/vitejs/vite/
|
||||||
|
|
||||||
|
[electron]: https://github.com/electron/electron
|
||||||
|
|
||||||
|
[electron-builder]: https://github.com/electron-userland/electron-builder
|
||||||
|
|
||||||
|
[vue]: https://github.com/vuejs/vue-next
|
||||||
|
|
||||||
|
[vue-router]: https://github.com/vuejs/vue-router-next/
|
||||||
|
|
||||||
|
[typescript]: https://github.com/microsoft/TypeScript/
|
||||||
|
|
||||||
|
[playwright]: https://playwright.dev
|
||||||
|
|
||||||
|
[vitest]: https://vitest.dev
|
||||||
|
|
||||||
|
[vue-tsc]: https://github.com/johnsoncodehk/vue-tsc
|
||||||
|
|
||||||
|
[eslint-plugin-vue]: https://github.com/vuejs/eslint-plugin-vue
|
||||||
|
|
||||||
|
[cawa-93-github]: https://github.com/cawa-93/
|
||||||
|
|
||||||
|
[cawa-93-sponsor]: https://www.patreon.com/Kozack/
|
0
buildResources/.gitkeep
Normal file
0
buildResources/.gitkeep
Normal file
BIN
buildResources/icon.icns
Normal file
BIN
buildResources/icon.icns
Normal file
Binary file not shown.
BIN
buildResources/icon.png
Normal file
BIN
buildResources/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 84 KiB |
34
contributing.md
Normal file
34
contributing.md
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
First and foremost, thank you! We appreciate that you want to contribute to vite-electron-builder, your time is
|
||||||
|
valuable, and your contributions mean a lot to us.
|
||||||
|
|
||||||
|
## Issues
|
||||||
|
|
||||||
|
Do not create issues about bumping dependencies unless a bug has been identified, and you can demonstrate that it
|
||||||
|
effects this library.
|
||||||
|
|
||||||
|
**Help us to help you**
|
||||||
|
|
||||||
|
Remember that we’re here to help, but not to make guesses about what you need help with:
|
||||||
|
|
||||||
|
- Whatever bug or issue you're experiencing, assume that it will not be as obvious to the maintainers as it is to you.
|
||||||
|
- Spell it out completely. Keep in mind that maintainers need to think about _all potential use cases_ of a library.
|
||||||
|
It's important that you explain how you're using a library so that maintainers can make that connection and solve the
|
||||||
|
issue.
|
||||||
|
|
||||||
|
_It can't be understated how frustrating and draining it can be to maintainers to have to ask clarifying questions on
|
||||||
|
the most basic things, before it's even possible to start debugging. Please try to make the best use of everyone's time
|
||||||
|
involved, including yourself, by providing this information up front._
|
||||||
|
|
||||||
|
## Repo Setup
|
||||||
|
|
||||||
|
The package manager used to install and link dependencies must be npm v7 or later.
|
||||||
|
|
||||||
|
1. Clone repo
|
||||||
|
1. `npm run watch` start electron app in watch mode.
|
||||||
|
1. `npm run compile` build app but for local debugging only.
|
||||||
|
1. `npm run lint` lint your code.
|
||||||
|
1. `npm run typecheck` Run typescript check.
|
||||||
|
1. `npm run test` Run app test.
|
||||||
|
1. `npm run format` Reformat all codebase to project code style.
|
21
licenses/vite-electron-builder.LICENSE
Normal file
21
licenses/vite-electron-builder.LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2021 Alex Kozack
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
30248
package-lock.json
generated
Normal file
30248
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
126
package.json
Normal file
126
package.json
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
{
|
||||||
|
"name": "feishin",
|
||||||
|
"description": "A full featured Jellyfin/Subsonic/Navidrome music player.",
|
||||||
|
"version": "1.0.0-alpha1",
|
||||||
|
"author": {
|
||||||
|
"name": "jeffvli",
|
||||||
|
"email": "jeffvictorli@gmail.com",
|
||||||
|
"url": "https://github.com/jeffvli"
|
||||||
|
},
|
||||||
|
"main": "packages/main/dist/index.cjs",
|
||||||
|
"scripts": {
|
||||||
|
"build": "npm run build:main && npm run build:preload && npm run build:renderer",
|
||||||
|
"build:main": "cd ./packages/main && vite build",
|
||||||
|
"build:preload": "cd ./packages/preload && vite build",
|
||||||
|
"build:renderer": "cd ./packages/renderer && vite build",
|
||||||
|
"compile": "cross-env MODE=production npm run build && electron-builder build --config .electron-builder.config.js --dir",
|
||||||
|
"test": "npm run test:main && npm run test:preload && npm run test:renderer && npm run test:e2e",
|
||||||
|
"test:e2e": "npm run build && vitest run",
|
||||||
|
"test:main": "vitest run -r packages/main --passWithNoTests",
|
||||||
|
"test:preload": "vitest run -r packages/preload --passWithNoTests",
|
||||||
|
"test:renderer": "vitest run -r packages/renderer --passWithNoTests",
|
||||||
|
"watch": "node scripts/watch.mjs",
|
||||||
|
"lint": "eslint . --ext js,mjs,cjs,ts,mts,cts,tsx",
|
||||||
|
"typecheck:main": "tsc --noEmit -p packages/main/tsconfig.json",
|
||||||
|
"typecheck:preload": "tsc --noEmit -p packages/preload/tsconfig.json",
|
||||||
|
"typecheck:renderer": "tsc --noEmit -p packages/renderer/tsconfig.json",
|
||||||
|
"typecheck": "npm run typecheck:main && npm run typecheck:preload && npm run typecheck:renderer",
|
||||||
|
"postinstall": "cross-env ELECTRON_RUN_AS_NODE=1 electron scripts/update-electron-vendors.mjs",
|
||||||
|
"format": "npx prettier --write \"**/*.{js,mjs,cjs,ts,mts,cts,tsx,json}\""
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/electron-localshortcut": "^3.1.0",
|
||||||
|
"@types/loadable__component": "^5.13.4",
|
||||||
|
"@types/lodash": "^4.14.191",
|
||||||
|
"@types/md5": "^2.3.2",
|
||||||
|
"@types/node": "18.11.10",
|
||||||
|
"@types/react": "^18.0.26",
|
||||||
|
"@types/react-dom": "^18.0.9",
|
||||||
|
"@types/react-slider": "^1.3.1",
|
||||||
|
"@types/react-virtualized-auto-sizer": "^1.0.1",
|
||||||
|
"@types/react-window": "^1.8.5",
|
||||||
|
"@types/react-window-infinite-loader": "^1.0.6",
|
||||||
|
"@types/styled-components": "^5.1.26",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^5.45.1",
|
||||||
|
"@typescript-eslint/parser": "^5.45.1",
|
||||||
|
"cross-env": "7.0.3",
|
||||||
|
"electron": "22.0.0",
|
||||||
|
"electron-builder": "23.6.0",
|
||||||
|
"electron-devtools-installer": "^3.2.0",
|
||||||
|
"eslint": "8.29.0",
|
||||||
|
"eslint-config-airbnb-base": "^15.0.0",
|
||||||
|
"eslint-config-erb": "^4.0.3",
|
||||||
|
"eslint-import-resolver-typescript": "^2.7.1",
|
||||||
|
"eslint-import-resolver-webpack": "^0.13.2",
|
||||||
|
"eslint-plugin-compat": "^4.0.2",
|
||||||
|
"eslint-plugin-import": "^2.26.0",
|
||||||
|
"eslint-plugin-jest": "^26.1.3",
|
||||||
|
"eslint-plugin-jsx-a11y": "^6.6.1",
|
||||||
|
"eslint-plugin-promise": "^6.1.1",
|
||||||
|
"eslint-plugin-react": "^7.31.11",
|
||||||
|
"eslint-plugin-react-hooks": "^4.6.0",
|
||||||
|
"eslint-plugin-sort-keys-fix": "^1.1.2",
|
||||||
|
"eslint-plugin-typescript-sort-keys": "^2.1.0",
|
||||||
|
"happy-dom": "7.7.2",
|
||||||
|
"nano-staged": "0.8.0",
|
||||||
|
"playwright": "1.27.1",
|
||||||
|
"sass": "^1.56.1",
|
||||||
|
"simple-git-hooks": "2.8.1",
|
||||||
|
"stylelint": "^14.16.0",
|
||||||
|
"stylelint-config-rational-order": "^0.1.2",
|
||||||
|
"stylelint-config-standard-scss": "^6.1.0",
|
||||||
|
"stylelint-config-styled-components": "^0.1.1",
|
||||||
|
"stylelint-order": "^5.0.0",
|
||||||
|
"stylelint-processor-styled-components": "^1.10.0",
|
||||||
|
"typescript": "4.9.3",
|
||||||
|
"unplugin-auto-expose": "0.0.4",
|
||||||
|
"vite": "3.2.4",
|
||||||
|
"vitest": "0.25.3"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@loadable/component": "^5.15.2",
|
||||||
|
"@mantine/core": "^5.9.2",
|
||||||
|
"@mantine/dates": "^5.9.2",
|
||||||
|
"@mantine/dropzone": "^5.9.2",
|
||||||
|
"@mantine/form": "^5.9.2",
|
||||||
|
"@mantine/hooks": "^5.9.2",
|
||||||
|
"@mantine/modals": "^5.9.2",
|
||||||
|
"@mantine/notifications": "^5.9.2",
|
||||||
|
"@mantine/spotlight": "^5.9.2",
|
||||||
|
"@tanstack/react-query": "^4.19.1",
|
||||||
|
"@tanstack/react-query-devtools": "^4.19.1",
|
||||||
|
"@vitejs/plugin-react": "^2.2.0",
|
||||||
|
"ag-grid-community": "^28.2.1",
|
||||||
|
"ag-grid-react": "^28.2.1",
|
||||||
|
"axios": "^0.27.2",
|
||||||
|
"electron-localshortcut": "^3.2.1",
|
||||||
|
"electron-store": "^8.1.0",
|
||||||
|
"electron-updater": "5.3.0",
|
||||||
|
"format-duration": "^2.0.0",
|
||||||
|
"framer-motion": "^7.6.19",
|
||||||
|
"immer": "^9.0.16",
|
||||||
|
"is-electron": "^2.2.1",
|
||||||
|
"ky": "^0.32.2",
|
||||||
|
"ky-universal": "^0.11.0",
|
||||||
|
"lodash": "^4.17.21",
|
||||||
|
"md5": "^2.3.0",
|
||||||
|
"nanoid": "^4.0.0",
|
||||||
|
"node-mpv": "^2.0.0-beta.2",
|
||||||
|
"react": "^18.2.0",
|
||||||
|
"react-dom": "^18.2.0",
|
||||||
|
"react-error-boundary": "^3.1.4",
|
||||||
|
"react-i18next": "^11.16.7",
|
||||||
|
"react-icons": "^4.7.1",
|
||||||
|
"react-player": "^2.11.0",
|
||||||
|
"react-router": "^6.4.4",
|
||||||
|
"react-router-dom": "^6.4.4",
|
||||||
|
"react-simple-img": "^3.0.0",
|
||||||
|
"react-slider": "^2.0.4",
|
||||||
|
"react-virtualized-auto-sizer": "^1.0.7",
|
||||||
|
"react-window": "^1.8.8",
|
||||||
|
"react-window-infinite-loader": "^1.0.8",
|
||||||
|
"styled-components": "^5.3.6",
|
||||||
|
"zod": "^3.19.1",
|
||||||
|
"zustand": "^4.1.5"
|
||||||
|
}
|
||||||
|
}
|
3
packages/main/src/features/core/index.ts
Normal file
3
packages/main/src/features/core/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import './player';
|
||||||
|
import './media-keys';
|
||||||
|
import './settings';
|
27
packages/main/src/features/core/media-keys/index.ts
Normal file
27
packages/main/src/features/core/media-keys/index.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import type { BrowserWindow } from 'electron';
|
||||||
|
import { globalShortcut } from 'electron';
|
||||||
|
|
||||||
|
export const enableMediaKeys = (window: BrowserWindow | null) => {
|
||||||
|
globalShortcut.register('MediaStop', () => {
|
||||||
|
window?.webContents.send('renderer-player-stop');
|
||||||
|
});
|
||||||
|
|
||||||
|
globalShortcut.register('MediaPlayPause', () => {
|
||||||
|
window?.webContents.send('renderer-player-play-pause');
|
||||||
|
});
|
||||||
|
|
||||||
|
globalShortcut.register('MediaNextTrack', () => {
|
||||||
|
window?.webContents.send('renderer-player-next');
|
||||||
|
});
|
||||||
|
|
||||||
|
globalShortcut.register('MediaPreviousTrack', () => {
|
||||||
|
window?.webContents.send('renderer-player-previous');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const disableMediaKeys = () => {
|
||||||
|
globalShortcut.unregister('MediaStop');
|
||||||
|
globalShortcut.unregister('MediaPlayPause');
|
||||||
|
globalShortcut.unregister('MediaNextTrack');
|
||||||
|
globalShortcut.unregister('MediaPreviousTrack');
|
||||||
|
};
|
167
packages/main/src/features/core/player/index.ts
Normal file
167
packages/main/src/features/core/player/index.ts
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
import { ipcMain } from 'electron';
|
||||||
|
import MpvAPI from 'node-mpv';
|
||||||
|
import { store } from '../settings';
|
||||||
|
import uniq from 'lodash/uniq';
|
||||||
|
import type { PlayerData } from '../../../../../renderer/src/store/player.store';
|
||||||
|
import { getBrowserWindow } from '/@/mainWindow';
|
||||||
|
|
||||||
|
declare module 'node-mpv';
|
||||||
|
|
||||||
|
const BINARY_PATH = store.get('mpv_path') as string | undefined;
|
||||||
|
const MPV_PARAMETERS = store.get('mpv_parameters') as Array<string> | undefined;
|
||||||
|
const DEFAULT_MPV_PARAMETERS = () => {
|
||||||
|
const parameters = [];
|
||||||
|
if (
|
||||||
|
!MPV_PARAMETERS?.includes('--gapless-audio=weak') ||
|
||||||
|
!MPV_PARAMETERS?.includes('--gapless-audio=no') ||
|
||||||
|
!MPV_PARAMETERS?.includes('--gapless-audio=yes') ||
|
||||||
|
!MPV_PARAMETERS?.includes('--gapless-audio')
|
||||||
|
) {
|
||||||
|
parameters.push('--gapless-audio=yes');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
!MPV_PARAMETERS?.includes('--prefetch-playlist=no') ||
|
||||||
|
!MPV_PARAMETERS?.includes('--prefetch-playlist=yes') ||
|
||||||
|
!MPV_PARAMETERS?.includes('--prefetch-playlist')
|
||||||
|
) {
|
||||||
|
parameters.push('--prefetch-playlist=yes');
|
||||||
|
}
|
||||||
|
|
||||||
|
return parameters;
|
||||||
|
};
|
||||||
|
|
||||||
|
const mpv = new MpvAPI(
|
||||||
|
{
|
||||||
|
audio_only: true,
|
||||||
|
auto_restart: true,
|
||||||
|
binary: BINARY_PATH || '',
|
||||||
|
time_update: 1,
|
||||||
|
},
|
||||||
|
MPV_PARAMETERS
|
||||||
|
? uniq([...DEFAULT_MPV_PARAMETERS(), ...MPV_PARAMETERS])
|
||||||
|
: DEFAULT_MPV_PARAMETERS(),
|
||||||
|
);
|
||||||
|
|
||||||
|
mpv
|
||||||
|
.start()
|
||||||
|
.then(async () => {
|
||||||
|
// await mpv.load('https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3', 'replace');
|
||||||
|
// await mpv.play();
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log('error', error);
|
||||||
|
});
|
||||||
|
|
||||||
|
mpv.on('status', (status) => {
|
||||||
|
if (status.property === 'playlist-pos') {
|
||||||
|
if (status.value !== 0) {
|
||||||
|
getBrowserWindow()?.webContents.send('renderer-player-auto-next');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Automatically updates the play button when the player is playing
|
||||||
|
mpv.on('resumed', () => {
|
||||||
|
getBrowserWindow()?.webContents.send('renderer-player-play');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Automatically updates the play button when the player is stopped
|
||||||
|
mpv.on('stopped', () => {
|
||||||
|
getBrowserWindow()?.webContents.send('renderer-player-stop');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Automatically updates the play button when the player is paused
|
||||||
|
mpv.on('paused', () => {
|
||||||
|
getBrowserWindow()?.webContents.send('renderer-player-pause');
|
||||||
|
});
|
||||||
|
|
||||||
|
mpv.on('quit', () => {
|
||||||
|
console.log('mpv quit');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Event output every interval set by time_update, used to update the current time
|
||||||
|
mpv.on('timeposition', (time: number) => {
|
||||||
|
getBrowserWindow()?.webContents.send('renderer-player-current-time', time);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Starts the player
|
||||||
|
ipcMain.on('player-play', async () => {
|
||||||
|
await mpv.play();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Pauses the player
|
||||||
|
ipcMain.on('player-pause', async () => {
|
||||||
|
await mpv.pause();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Stops the player
|
||||||
|
ipcMain.on('player-stop', async () => {
|
||||||
|
await mpv.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Goes to the next track in the playlist
|
||||||
|
ipcMain.on('player-next', async () => {
|
||||||
|
await mpv.next();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Goes to the previous track in the playlist
|
||||||
|
ipcMain.on('player-previous', async () => {
|
||||||
|
await mpv.prev();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Seeks forward or backward by the given amount of seconds
|
||||||
|
ipcMain.on('player-seek', async (_event, time: number) => {
|
||||||
|
await mpv.seek(time);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Seeks to the given time in seconds
|
||||||
|
ipcMain.on('player-seek-to', async (_event, time: number) => {
|
||||||
|
await mpv.goToPosition(time);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Sets the queue in position 0 and 1 to the given data. Used when manually starting a song or using the next/prev buttons
|
||||||
|
ipcMain.on('player-set-queue', async (_event, data: PlayerData) => {
|
||||||
|
if (data.queue.current) {
|
||||||
|
await mpv.load(data.queue.current.streamUrl, 'replace');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.queue.next) {
|
||||||
|
await mpv.load(data.queue.next.streamUrl, 'append');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Replaces the queue in position 1 to the given data
|
||||||
|
ipcMain.on('player-set-queue-next', async (_event, data: PlayerData) => {
|
||||||
|
const size = await mpv.getPlaylistSize();
|
||||||
|
|
||||||
|
if (size > 1) {
|
||||||
|
await mpv.playlistRemove(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.queue.next) {
|
||||||
|
await mpv.load(data.queue.next.streamUrl, 'append');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Sets the next song in the queue when reaching the end of the queue
|
||||||
|
ipcMain.on('player-auto-next', async (_event, data: PlayerData) => {
|
||||||
|
// Always keep the current song as position 0 in the mpv queue
|
||||||
|
// This allows us to easily set update the next song in the queue without
|
||||||
|
// disturbing the currently playing song
|
||||||
|
await mpv.playlistRemove(0);
|
||||||
|
|
||||||
|
if (data.queue.next) {
|
||||||
|
await mpv.load(data.queue.next.streamUrl, 'append');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Sets the volume to the given value (0-100)
|
||||||
|
ipcMain.on('player-volume', async (_event, value: number) => {
|
||||||
|
mpv.volume(value);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Toggles the mute status
|
||||||
|
ipcMain.on('player-mute', async () => {
|
||||||
|
mpv.mute();
|
||||||
|
});
|
3
packages/main/src/features/core/settings/index.ts
Normal file
3
packages/main/src/features/core/settings/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import Store from 'electron-store';
|
||||||
|
|
||||||
|
export const store = new Store();
|
3
packages/main/src/features/index.ts
Normal file
3
packages/main/src/features/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import './core';
|
||||||
|
|
||||||
|
// require(`./${process.platform}`);
|
71
packages/main/src/index.ts
Normal file
71
packages/main/src/index.ts
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
import { app, ipcMain } from 'electron';
|
||||||
|
import './security-restrictions';
|
||||||
|
import { restoreOrCreateWindow } from '/@/mainWindow';
|
||||||
|
|
||||||
|
ipcMain.on('app-restart', () => {
|
||||||
|
app.relaunch();
|
||||||
|
app.exit(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prevent electron from running multiple instances.
|
||||||
|
*/
|
||||||
|
const isSingleInstance = app.requestSingleInstanceLock();
|
||||||
|
if (!isSingleInstance) {
|
||||||
|
app.quit();
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
app.on('second-instance', restoreOrCreateWindow);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable Hardware Acceleration to save more system resources.
|
||||||
|
*/
|
||||||
|
app.disableHardwareAcceleration();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shout down background process if all windows was closed
|
||||||
|
*/
|
||||||
|
app.on('window-all-closed', () => {
|
||||||
|
if (process.platform !== 'darwin') {
|
||||||
|
app.quit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see https://www.electronjs.org/docs/latest/api/app#event-activate-macos Event: 'activate'.
|
||||||
|
*/
|
||||||
|
app.on('activate', restoreOrCreateWindow);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the application window when the background process is ready.
|
||||||
|
*/
|
||||||
|
app
|
||||||
|
.whenReady()
|
||||||
|
.then(restoreOrCreateWindow)
|
||||||
|
.catch((e) => console.error('Failed create window:', e));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install Vue.js or any other extension in development mode only.
|
||||||
|
* Note: You must install `electron-devtools-installer` manually
|
||||||
|
*/
|
||||||
|
// if (import.meta.env.DEV) {
|
||||||
|
// app.whenReady()
|
||||||
|
// .then(() => import('electron-devtools-installer'))
|
||||||
|
// .then(({default: installExtension, VUEJS3_DEVTOOLS}) => installExtension(VUEJS3_DEVTOOLS, {
|
||||||
|
// loadExtensionOptions: {
|
||||||
|
// allowFileAccess: true,
|
||||||
|
// },
|
||||||
|
// }))
|
||||||
|
// .catch(e => console.error('Failed install extension:', e));
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for new version of the application - production mode only.
|
||||||
|
*/
|
||||||
|
if (import.meta.env.PROD) {
|
||||||
|
app
|
||||||
|
.whenReady()
|
||||||
|
.then(() => import('electron-updater'))
|
||||||
|
.then(({ autoUpdater }) => autoUpdater.checkForUpdatesAndNotify())
|
||||||
|
.catch((e) => console.error('Failed check updates:', e));
|
||||||
|
}
|
137
packages/main/src/mainWindow.ts
Normal file
137
packages/main/src/mainWindow.ts
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
import { app, BrowserWindow, ipcMain } from 'electron';
|
||||||
|
import { join } from 'path';
|
||||||
|
import { URL } from 'url';
|
||||||
|
import { disableMediaKeys, enableMediaKeys } from './features/core/media-keys';
|
||||||
|
import { store } from './features/core/settings';
|
||||||
|
import electronLocalShortcut from 'electron-localshortcut';
|
||||||
|
import './features';
|
||||||
|
|
||||||
|
const isDevelopment = process.env.NODE_ENV === 'development';
|
||||||
|
|
||||||
|
const installExtensions = async () => {
|
||||||
|
const installer = require('electron-devtools-installer');
|
||||||
|
const forceDownload = !!process.env.UPGRADE_EXTENSIONS;
|
||||||
|
const extensions = ['REACT_DEVELOPER_TOOLS', 'REDUX_DEVTOOLS'];
|
||||||
|
|
||||||
|
return installer
|
||||||
|
.default(
|
||||||
|
extensions.map((name) => installer[name]),
|
||||||
|
forceDownload,
|
||||||
|
)
|
||||||
|
.catch(console.log);
|
||||||
|
};
|
||||||
|
|
||||||
|
let browserWindow: BrowserWindow | null = null;
|
||||||
|
|
||||||
|
async function createWindow() {
|
||||||
|
if (isDevelopment) {
|
||||||
|
await installExtensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
browserWindow = new BrowserWindow({
|
||||||
|
show: false, // Use the 'ready-to-show' event to show the instantiated BrowserWindow.
|
||||||
|
frame: false,
|
||||||
|
minWidth: 640,
|
||||||
|
minHeight: 600,
|
||||||
|
height: 900,
|
||||||
|
width: 1440,
|
||||||
|
webPreferences: {
|
||||||
|
nodeIntegration: false,
|
||||||
|
contextIsolation: true,
|
||||||
|
sandbox: false, // Sandbox disabled because the demo of preload script depend on the Node.js api
|
||||||
|
webviewTag: false, // The webview tag is not recommended. Consider alternatives like an iframe or Electron's BrowserView. @see https://www.electronjs.org/docs/latest/api/webview-tag#warning
|
||||||
|
preload: join(app.getAppPath(), 'packages/preload/dist/index.cjs'),
|
||||||
|
backgroundThrottling: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the 'show' property of the BrowserWindow's constructor is omitted from the initialization options,
|
||||||
|
* it then defaults to 'true'. This can cause flickering as the window loads the html content,
|
||||||
|
* and it also has show problematic behaviour with the closing of the window.
|
||||||
|
* Use `show: false` and listen to the `ready-to-show` event to show the window.
|
||||||
|
*
|
||||||
|
* @see https://github.com/electron/electron/issues/25012 for the afford mentioned issue.
|
||||||
|
*/
|
||||||
|
browserWindow.on('ready-to-show', () => {
|
||||||
|
browserWindow?.show();
|
||||||
|
|
||||||
|
if (import.meta.env.DEV) {
|
||||||
|
browserWindow?.webContents.openDevTools();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.on('window-maximize', () => {
|
||||||
|
browserWindow?.maximize();
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.on('window-unmaximize', () => {
|
||||||
|
browserWindow?.unmaximize();
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.on('window-minimize', () => {
|
||||||
|
browserWindow?.minimize();
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.on('window-close', () => {
|
||||||
|
browserWindow?.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
electronLocalShortcut.register(browserWindow, 'Ctrl+Shift+I', () => {
|
||||||
|
browserWindow?.webContents.openDevTools();
|
||||||
|
});
|
||||||
|
|
||||||
|
const globalMediaKeysEnabled = store.get('global_media_hotkeys') as boolean;
|
||||||
|
|
||||||
|
if (globalMediaKeysEnabled) {
|
||||||
|
enableMediaKeys(browserWindow);
|
||||||
|
}
|
||||||
|
|
||||||
|
ipcMain.on('global-media-keys-enable', () => {
|
||||||
|
enableMediaKeys(browserWindow);
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.on('global-media-keys-disable', () => {
|
||||||
|
disableMediaKeys();
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL for main window.
|
||||||
|
* Vite dev server for development.
|
||||||
|
* `file://../renderer/index.html` for production and test.
|
||||||
|
*/
|
||||||
|
const pageUrl =
|
||||||
|
import.meta.env.DEV && import.meta.env.VITE_DEV_SERVER_URL !== undefined
|
||||||
|
? import.meta.env.VITE_DEV_SERVER_URL
|
||||||
|
: new URL('../renderer/dist/index.html', 'file://' + __dirname).toString();
|
||||||
|
|
||||||
|
await browserWindow.loadURL(pageUrl);
|
||||||
|
|
||||||
|
return browserWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore an existing BrowserWindow or Create a new BrowserWindow.
|
||||||
|
*/
|
||||||
|
export async function restoreOrCreateWindow() {
|
||||||
|
let window = BrowserWindow.getAllWindows().find((w) => !w.isDestroyed());
|
||||||
|
|
||||||
|
if (window === undefined) {
|
||||||
|
window = await createWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window.isMinimized()) {
|
||||||
|
window.restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
window.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
ipcMain.on('app-restart', () => {
|
||||||
|
app.relaunch();
|
||||||
|
app.exit(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
export const getBrowserWindow = () => {
|
||||||
|
return browserWindow;
|
||||||
|
};
|
135
packages/main/src/security-restrictions.ts
Normal file
135
packages/main/src/security-restrictions.ts
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
import {app, shell} from 'electron';
|
||||||
|
import {URL} from 'url';
|
||||||
|
|
||||||
|
type Permissions =
|
||||||
|
| 'clipboard-read'
|
||||||
|
| 'media'
|
||||||
|
| 'display-capture'
|
||||||
|
| 'mediaKeySystem'
|
||||||
|
| 'geolocation'
|
||||||
|
| 'notifications'
|
||||||
|
| 'midi'
|
||||||
|
| 'midiSysex'
|
||||||
|
| 'pointerLock'
|
||||||
|
| 'fullscreen'
|
||||||
|
| 'openExternal'
|
||||||
|
| 'unknown';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of origins that you allow open INSIDE the application and permissions for them.
|
||||||
|
*
|
||||||
|
* In development mode you need allow open `VITE_DEV_SERVER_URL`.
|
||||||
|
*/
|
||||||
|
const ALLOWED_ORIGINS_AND_PERMISSIONS = new Map<string, Set<Permissions>>(
|
||||||
|
import.meta.env.DEV && import.meta.env.VITE_DEV_SERVER_URL
|
||||||
|
? [[new URL(import.meta.env.VITE_DEV_SERVER_URL).origin, new Set()]]
|
||||||
|
: [],
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of origins that you allow open IN BROWSER.
|
||||||
|
* Navigation to the origins below is only possible if the link opens in a new window.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* <a
|
||||||
|
* target="_blank"
|
||||||
|
* href="https://github.com/"
|
||||||
|
* >
|
||||||
|
*/
|
||||||
|
const ALLOWED_EXTERNAL_ORIGINS = new Set<`https://${string}`>(['https://github.com']);
|
||||||
|
|
||||||
|
app.on('web-contents-created', (_, contents) => {
|
||||||
|
/**
|
||||||
|
* Block navigation to origins not on the allowlist.
|
||||||
|
*
|
||||||
|
* Navigation exploits are quite common. If an attacker can convince the app to navigate away from its current page,
|
||||||
|
* they can possibly force the app to open arbitrary web resources/websites on the web.
|
||||||
|
*
|
||||||
|
* @see https://www.electronjs.org/docs/latest/tutorial/security#13-disable-or-limit-navigation
|
||||||
|
*/
|
||||||
|
contents.on('will-navigate', (event, url) => {
|
||||||
|
const {origin} = new URL(url);
|
||||||
|
if (ALLOWED_ORIGINS_AND_PERMISSIONS.has(origin)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prevent navigation
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
if (import.meta.env.DEV) {
|
||||||
|
console.warn(`Blocked navigating to disallowed origin: ${origin}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Block requests for disallowed permissions.
|
||||||
|
* By default, Electron will automatically approve all permission requests.
|
||||||
|
*
|
||||||
|
* @see https://www.electronjs.org/docs/latest/tutorial/security#5-handle-session-permission-requests-from-remote-content
|
||||||
|
*/
|
||||||
|
contents.session.setPermissionRequestHandler((webContents, permission, callback) => {
|
||||||
|
const {origin} = new URL(webContents.getURL());
|
||||||
|
|
||||||
|
const permissionGranted = !!ALLOWED_ORIGINS_AND_PERMISSIONS.get(origin)?.has(permission);
|
||||||
|
callback(permissionGranted);
|
||||||
|
|
||||||
|
if (!permissionGranted && import.meta.env.DEV) {
|
||||||
|
console.warn(`${origin} requested permission for '${permission}', but was rejected.`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hyperlinks leading to allowed sites are opened in the default browser.
|
||||||
|
*
|
||||||
|
* The creation of new `webContents` is a common attack vector. Attackers attempt to convince the app to create new windows,
|
||||||
|
* frames, or other renderer processes with more privileges than they had before; or with pages opened that they couldn't open before.
|
||||||
|
* You should deny any unexpected window creation.
|
||||||
|
*
|
||||||
|
* @see https://www.electronjs.org/docs/latest/tutorial/security#14-disable-or-limit-creation-of-new-windows
|
||||||
|
* @see https://www.electronjs.org/docs/latest/tutorial/security#15-do-not-use-openexternal-with-untrusted-content
|
||||||
|
*/
|
||||||
|
contents.setWindowOpenHandler(({url}) => {
|
||||||
|
const {origin} = new URL(url);
|
||||||
|
|
||||||
|
// @ts-expect-error Type checking is performed in runtime.
|
||||||
|
if (ALLOWED_EXTERNAL_ORIGINS.has(origin)) {
|
||||||
|
// Open url in default browser.
|
||||||
|
shell.openExternal(url).catch(console.error);
|
||||||
|
} else if (import.meta.env.DEV) {
|
||||||
|
console.warn(`Blocked the opening of a disallowed origin: ${origin}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prevent creating a new window.
|
||||||
|
return {action: 'deny'};
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify webview options before creation.
|
||||||
|
*
|
||||||
|
* Strip away preload scripts, disable Node.js integration, and ensure origins are on the allowlist.
|
||||||
|
*
|
||||||
|
* @see https://www.electronjs.org/docs/latest/tutorial/security#12-verify-webview-options-before-creation
|
||||||
|
*/
|
||||||
|
contents.on('will-attach-webview', (event, webPreferences, params) => {
|
||||||
|
const {origin} = new URL(params.src);
|
||||||
|
if (!ALLOWED_ORIGINS_AND_PERMISSIONS.has(origin)) {
|
||||||
|
if (import.meta.env.DEV) {
|
||||||
|
console.warn(`A webview tried to attach ${params.src}, but was blocked.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strip away preload scripts if unused or verify their location is legitimate.
|
||||||
|
delete webPreferences.preload;
|
||||||
|
// @ts-expect-error `preloadURL` exists. - @see https://www.electronjs.org/docs/latest/api/web-contents#event-will-attach-webview
|
||||||
|
delete webPreferences.preloadURL;
|
||||||
|
|
||||||
|
// Disable Node.js integration
|
||||||
|
webPreferences.nodeIntegration = false;
|
||||||
|
|
||||||
|
// Enable contextIsolation
|
||||||
|
webPreferences.contextIsolation = true;
|
||||||
|
});
|
||||||
|
});
|
72
packages/main/tests/unit.spec.ts
Normal file
72
packages/main/tests/unit.spec.ts
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import type {MockedClass} from 'vitest';
|
||||||
|
import {beforeEach, expect, test, vi} from 'vitest';
|
||||||
|
import {restoreOrCreateWindow} from '../src/mainWindow';
|
||||||
|
|
||||||
|
import {BrowserWindow} from 'electron';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock real electron BrowserWindow API
|
||||||
|
*/
|
||||||
|
vi.mock('electron', () => {
|
||||||
|
// Use "as unknown as" because vi.fn() does not have static methods
|
||||||
|
const bw = vi.fn() as unknown as MockedClass<typeof BrowserWindow>;
|
||||||
|
bw.getAllWindows = vi.fn(() => bw.mock.instances);
|
||||||
|
bw.prototype.loadURL = vi.fn((_: string, __?: Electron.LoadURLOptions) => Promise.resolve());
|
||||||
|
// Use "any" because the on function is overloaded
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
bw.prototype.on = vi.fn<any>();
|
||||||
|
bw.prototype.destroy = vi.fn();
|
||||||
|
bw.prototype.isDestroyed = vi.fn();
|
||||||
|
bw.prototype.isMinimized = vi.fn();
|
||||||
|
bw.prototype.focus = vi.fn();
|
||||||
|
bw.prototype.restore = vi.fn();
|
||||||
|
|
||||||
|
const app: Pick<Electron.App, 'getAppPath'> = {
|
||||||
|
getAppPath(): string {
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return {BrowserWindow: bw, app};
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Should create a new window', async () => {
|
||||||
|
const {mock} = vi.mocked(BrowserWindow);
|
||||||
|
expect(mock.instances).toHaveLength(0);
|
||||||
|
|
||||||
|
await restoreOrCreateWindow();
|
||||||
|
expect(mock.instances).toHaveLength(1);
|
||||||
|
expect(mock.instances[0].loadURL).toHaveBeenCalledOnce();
|
||||||
|
expect(mock.instances[0].loadURL).toHaveBeenCalledWith(expect.stringMatching(/index\.html$/));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Should restore an existing window', async () => {
|
||||||
|
const {mock} = vi.mocked(BrowserWindow);
|
||||||
|
|
||||||
|
// Create a window and minimize it.
|
||||||
|
await restoreOrCreateWindow();
|
||||||
|
expect(mock.instances).toHaveLength(1);
|
||||||
|
const appWindow = vi.mocked(mock.instances[0]);
|
||||||
|
appWindow.isMinimized.mockReturnValueOnce(true);
|
||||||
|
|
||||||
|
await restoreOrCreateWindow();
|
||||||
|
expect(mock.instances).toHaveLength(1);
|
||||||
|
expect(appWindow.restore).toHaveBeenCalledOnce();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Should create a new window if the previous one was destroyed', async () => {
|
||||||
|
const {mock} = vi.mocked(BrowserWindow);
|
||||||
|
|
||||||
|
// Create a window and destroy it.
|
||||||
|
await restoreOrCreateWindow();
|
||||||
|
expect(mock.instances).toHaveLength(1);
|
||||||
|
const appWindow = vi.mocked(mock.instances[0]);
|
||||||
|
appWindow.isDestroyed.mockReturnValueOnce(true);
|
||||||
|
|
||||||
|
await restoreOrCreateWindow();
|
||||||
|
expect(mock.instances).toHaveLength(2);
|
||||||
|
});
|
19
packages/main/tsconfig.json
Normal file
19
packages/main/tsconfig.json
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "esnext",
|
||||||
|
"target": "esnext",
|
||||||
|
"sourceMap": false,
|
||||||
|
"moduleResolution": "Node",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"strict": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"types": ["node"],
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"/@/*": ["./src/*"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"include": ["src/**/*.ts", "../../types/**/*.d.ts"],
|
||||||
|
"exclude": ["**/*.spec.ts", "**/*.test.ts"]
|
||||||
|
}
|
43
packages/main/vite.config.js
Normal file
43
packages/main/vite.config.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import {node} from '../../.electron-vendors.cache.json';
|
||||||
|
import {join} from 'node:path';
|
||||||
|
import {injectAppVersion} from '../../version/inject-app-version-plugin.mjs';
|
||||||
|
|
||||||
|
const PACKAGE_ROOT = __dirname;
|
||||||
|
const PROJECT_ROOT = join(PACKAGE_ROOT, '../..');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {import('vite').UserConfig}
|
||||||
|
* @see https://vitejs.dev/config/
|
||||||
|
*/
|
||||||
|
const config = {
|
||||||
|
mode: process.env.MODE,
|
||||||
|
root: PACKAGE_ROOT,
|
||||||
|
envDir: PROJECT_ROOT,
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
'/@/': join(PACKAGE_ROOT, 'src') + '/',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
build: {
|
||||||
|
ssr: true,
|
||||||
|
sourcemap: 'inline',
|
||||||
|
target: `node${node}`,
|
||||||
|
outDir: 'dist',
|
||||||
|
assetsDir: '.',
|
||||||
|
minify: process.env.MODE !== 'development',
|
||||||
|
lib: {
|
||||||
|
entry: 'src/index.ts',
|
||||||
|
formats: ['cjs'],
|
||||||
|
},
|
||||||
|
rollupOptions: {
|
||||||
|
output: {
|
||||||
|
entryFileNames: '[name].cjs',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
emptyOutDir: true,
|
||||||
|
reportCompressedSize: false,
|
||||||
|
},
|
||||||
|
plugins: [injectAppVersion(PROJECT_ROOT)],
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
21
packages/preload/src/browser.ts
Normal file
21
packages/preload/src/browser.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { ipcRenderer } from 'electron';
|
||||||
|
|
||||||
|
const exit = () => {
|
||||||
|
ipcRenderer.send('window-close');
|
||||||
|
};
|
||||||
|
const maximize = () => {
|
||||||
|
ipcRenderer.send('window-maximize');
|
||||||
|
};
|
||||||
|
const minimize = () => {
|
||||||
|
ipcRenderer.send('window-minimize');
|
||||||
|
};
|
||||||
|
const unmaximize = () => {
|
||||||
|
ipcRenderer.send('window-unmaximize');
|
||||||
|
};
|
||||||
|
|
||||||
|
export const browser = {
|
||||||
|
minimize,
|
||||||
|
maximize,
|
||||||
|
unmaximize,
|
||||||
|
exit,
|
||||||
|
};
|
10
packages/preload/src/index.ts
Normal file
10
packages/preload/src/index.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* @module preload
|
||||||
|
*/
|
||||||
|
|
||||||
|
export { sha256sum } from './node-crypto';
|
||||||
|
export { versions } from './versions';
|
||||||
|
export { localSettings } from './local-settings';
|
||||||
|
export { browser } from './browser';
|
||||||
|
export { mpvPlayer, mpvPlayerListener } from './mpv-player';
|
||||||
|
export { ipc } from './ipc';
|
9
packages/preload/src/ipc.ts
Normal file
9
packages/preload/src/ipc.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { ipcRenderer } from 'electron';
|
||||||
|
|
||||||
|
const removeAllListeners = (channel: string) => {
|
||||||
|
ipcRenderer.removeAllListeners(channel);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ipc = {
|
||||||
|
removeAllListeners,
|
||||||
|
};
|
33
packages/preload/src/local-settings.ts
Normal file
33
packages/preload/src/local-settings.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import Store from 'electron-store';
|
||||||
|
import { app, ipcRenderer } from 'electron';
|
||||||
|
|
||||||
|
const store = new Store();
|
||||||
|
|
||||||
|
const set = (property: string, value: string | Record<string, unknown> | boolean) => {
|
||||||
|
store.set(`${property}`, value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const get = (property: string) => {
|
||||||
|
return store.get(`${property}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const restart = () => {
|
||||||
|
app.relaunch();
|
||||||
|
app.exit(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
const enableMediaKeys = () => {
|
||||||
|
ipcRenderer.send('global-media-keys-enable');
|
||||||
|
};
|
||||||
|
|
||||||
|
const disableMediaKeys = () => {
|
||||||
|
ipcRenderer.send('global-media-keys-disable');
|
||||||
|
};
|
||||||
|
|
||||||
|
export const localSettings = {
|
||||||
|
set,
|
||||||
|
get,
|
||||||
|
enableMediaKeys,
|
||||||
|
disableMediaKeys,
|
||||||
|
restart,
|
||||||
|
};
|
103
packages/preload/src/mpv-player.ts
Normal file
103
packages/preload/src/mpv-player.ts
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
import type { IpcRendererEvent } from 'electron';
|
||||||
|
import { ipcRenderer } from 'electron';
|
||||||
|
import type { PlayerData } from '../../renderer/src/store/player.store';
|
||||||
|
|
||||||
|
const autoNext = (data: PlayerData) => {
|
||||||
|
ipcRenderer.send('player-auto-next', data);
|
||||||
|
};
|
||||||
|
|
||||||
|
const currentTime = () => {
|
||||||
|
ipcRenderer.send('player-current-time');
|
||||||
|
};
|
||||||
|
const mute = () => {
|
||||||
|
ipcRenderer.send('player-mute');
|
||||||
|
};
|
||||||
|
const next = () => {
|
||||||
|
ipcRenderer.send('player-next');
|
||||||
|
};
|
||||||
|
const pause = () => {
|
||||||
|
ipcRenderer.send('player-pause');
|
||||||
|
};
|
||||||
|
const play = () => {
|
||||||
|
ipcRenderer.send('player-play');
|
||||||
|
};
|
||||||
|
const previous = () => {
|
||||||
|
ipcRenderer.send('player-previous');
|
||||||
|
};
|
||||||
|
const seek = (seconds: number) => {
|
||||||
|
ipcRenderer.send('player-seek', seconds);
|
||||||
|
};
|
||||||
|
const seekTo = (seconds: number) => {
|
||||||
|
ipcRenderer.send('player-seek-to', seconds);
|
||||||
|
};
|
||||||
|
const setQueue = (data: PlayerData) => {
|
||||||
|
ipcRenderer.send('player-set-queue', data);
|
||||||
|
};
|
||||||
|
const setQueueNext = (data: PlayerData) => {
|
||||||
|
ipcRenderer.send('player-set-queue-next', data);
|
||||||
|
};
|
||||||
|
const stop = () => {
|
||||||
|
ipcRenderer.send('player-stop');
|
||||||
|
};
|
||||||
|
const volume = (value: number) => {
|
||||||
|
ipcRenderer.send('player-volume', value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const rendererAutoNext = (cb: (event: IpcRendererEvent, data: PlayerData) => void) => {
|
||||||
|
ipcRenderer.on('renderer-player-auto-next', cb);
|
||||||
|
};
|
||||||
|
|
||||||
|
const rendererCurrentTime = (cb: (event: IpcRendererEvent, data: number) => void) => {
|
||||||
|
ipcRenderer.on('renderer-player-current-time', cb);
|
||||||
|
};
|
||||||
|
|
||||||
|
const rendererNext = (cb: (event: IpcRendererEvent, data: PlayerData) => void) => {
|
||||||
|
ipcRenderer.on('renderer-player-next', cb);
|
||||||
|
};
|
||||||
|
|
||||||
|
const rendererPause = (cb: (event: IpcRendererEvent, data: PlayerData) => void) => {
|
||||||
|
ipcRenderer.on('renderer-player-pause', cb);
|
||||||
|
};
|
||||||
|
|
||||||
|
const rendererPlay = (cb: (event: IpcRendererEvent, data: PlayerData) => void) => {
|
||||||
|
ipcRenderer.on('renderer-player-play', cb);
|
||||||
|
};
|
||||||
|
|
||||||
|
const rendererPlayPause = (cb: (event: IpcRendererEvent, data: PlayerData) => void) => {
|
||||||
|
ipcRenderer.on('renderer-player-play-pause', cb);
|
||||||
|
};
|
||||||
|
|
||||||
|
const rendererPrevious = (cb: (event: IpcRendererEvent, data: PlayerData) => void) => {
|
||||||
|
ipcRenderer.on('renderer-player-previous', cb);
|
||||||
|
};
|
||||||
|
|
||||||
|
const rendererStop = (cb: (event: IpcRendererEvent, data: PlayerData) => void) => {
|
||||||
|
ipcRenderer.on('renderer-player-stop', cb);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const mpvPlayer = {
|
||||||
|
autoNext,
|
||||||
|
mute,
|
||||||
|
next,
|
||||||
|
previous,
|
||||||
|
pause,
|
||||||
|
seek,
|
||||||
|
seekTo,
|
||||||
|
setQueue,
|
||||||
|
setQueueNext,
|
||||||
|
stop,
|
||||||
|
volume,
|
||||||
|
play,
|
||||||
|
currentTime,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const mpvPlayerListener = {
|
||||||
|
rendererAutoNext,
|
||||||
|
rendererCurrentTime,
|
||||||
|
rendererNext,
|
||||||
|
rendererPause,
|
||||||
|
rendererPlay,
|
||||||
|
rendererPlayPause,
|
||||||
|
rendererPrevious,
|
||||||
|
rendererStop,
|
||||||
|
};
|
5
packages/preload/src/node-crypto.ts
Normal file
5
packages/preload/src/node-crypto.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { type BinaryLike, createHash } from 'crypto';
|
||||||
|
|
||||||
|
export function sha256sum(data: BinaryLike) {
|
||||||
|
return createHash('sha256').update(data).digest('hex');
|
||||||
|
}
|
1
packages/preload/src/versions.ts
Normal file
1
packages/preload/src/versions.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export const versions = process.versions;
|
15
packages/preload/tests/unit.spec.ts
Normal file
15
packages/preload/tests/unit.spec.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import {createHash} from 'crypto';
|
||||||
|
import {expect, test} from 'vitest';
|
||||||
|
import {sha256sum, versions} from '../src';
|
||||||
|
|
||||||
|
test('versions', async () => {
|
||||||
|
expect(versions).toBe(process.versions);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('nodeCrypto', async () => {
|
||||||
|
// Test hashing a random string.
|
||||||
|
const testString = Math.random().toString(36).slice(2, 7);
|
||||||
|
const expectedHash = createHash('sha256').update(testString).digest('hex');
|
||||||
|
|
||||||
|
expect(sha256sum(testString)).toBe(expectedHash);
|
||||||
|
});
|
16
packages/preload/tsconfig.json
Normal file
16
packages/preload/tsconfig.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "esnext",
|
||||||
|
"target": "esnext",
|
||||||
|
"sourceMap": false,
|
||||||
|
"moduleResolution": "Node",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"strict": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"types": ["node"],
|
||||||
|
"baseUrl": "."
|
||||||
|
},
|
||||||
|
"include": ["src/**/*.ts", "../../types/**/*.d.ts"],
|
||||||
|
"exclude": ["**/*.spec.ts", "**/*.test.ts"]
|
||||||
|
}
|
39
packages/preload/vite.config.js
Normal file
39
packages/preload/vite.config.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import {chrome} from '../../.electron-vendors.cache.json';
|
||||||
|
import {preload} from 'unplugin-auto-expose';
|
||||||
|
import {join} from 'node:path';
|
||||||
|
import {injectAppVersion} from '../../version/inject-app-version-plugin.mjs';
|
||||||
|
|
||||||
|
const PACKAGE_ROOT = __dirname;
|
||||||
|
const PROJECT_ROOT = join(PACKAGE_ROOT, '../..');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {import('vite').UserConfig}
|
||||||
|
* @see https://vitejs.dev/config/
|
||||||
|
*/
|
||||||
|
const config = {
|
||||||
|
mode: process.env.MODE,
|
||||||
|
root: PACKAGE_ROOT,
|
||||||
|
envDir: PROJECT_ROOT,
|
||||||
|
build: {
|
||||||
|
ssr: true,
|
||||||
|
sourcemap: 'inline',
|
||||||
|
target: `chrome${chrome}`,
|
||||||
|
outDir: 'dist',
|
||||||
|
assetsDir: '.',
|
||||||
|
minify: process.env.MODE !== 'development',
|
||||||
|
lib: {
|
||||||
|
entry: 'src/index.ts',
|
||||||
|
formats: ['cjs'],
|
||||||
|
},
|
||||||
|
rollupOptions: {
|
||||||
|
output: {
|
||||||
|
entryFileNames: '[name].cjs',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
emptyOutDir: true,
|
||||||
|
reportCompressedSize: false,
|
||||||
|
},
|
||||||
|
plugins: [preload.vite(), injectAppVersion(PROJECT_ROOT)],
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
80
packages/renderer/.eslintrc.json
Normal file
80
packages/renderer/.eslintrc.json
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"browser": true,
|
||||||
|
"node": false
|
||||||
|
},
|
||||||
|
"extends": ["plugin:react-hooks/recommended", "plugin:typescript-sort-keys/recommended"],
|
||||||
|
"plugins": ["react", "@typescript-eslint", "import", "sort-keys-fix"],
|
||||||
|
"root": false,
|
||||||
|
"parserOptions": {
|
||||||
|
"createDefaultProgram": true,
|
||||||
|
"parser": "@typescript-eslint/parser",
|
||||||
|
"ecmaVersion": 12,
|
||||||
|
"sourceType": "module",
|
||||||
|
"project": "./packages/renderer/tsconfig.json",
|
||||||
|
"tsconfigRootDir": "./"
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"import/parsers": {
|
||||||
|
"@typescript-eslint/parser": [".ts", ".tsx"]
|
||||||
|
},
|
||||||
|
"import/resolver": {
|
||||||
|
// See https://github.com/benmosher/eslint-plugin-import/issues/1396#issuecomment-575727774 for line below
|
||||||
|
"typescript": {
|
||||||
|
"alwaysTryTypes": true,
|
||||||
|
"project": "./packages/renderer/tsconfig.json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"@typescript-eslint/naming-convention": "off",
|
||||||
|
"@typescript-eslint/no-explicit-any": "off",
|
||||||
|
"@typescript-eslint/no-non-null-assertion": "off",
|
||||||
|
"@typescript-eslint/no-shadow": ["off"],
|
||||||
|
"import/extensions": "off",
|
||||||
|
"import/no-extraneous-dependencies": "off",
|
||||||
|
"import/no-unresolved": "error",
|
||||||
|
"import/order": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"alphabetize": {
|
||||||
|
"caseInsensitive": true,
|
||||||
|
"order": "asc"
|
||||||
|
},
|
||||||
|
"groups": ["builtin", "external", "internal", ["parent", "sibling"]],
|
||||||
|
"newlines-between": "never",
|
||||||
|
"pathGroups": [
|
||||||
|
{
|
||||||
|
"group": "external",
|
||||||
|
"pattern": "react",
|
||||||
|
"position": "before"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"pathGroupsExcludedImportTypes": ["react"]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"import/prefer-default-export": "off",
|
||||||
|
"jsx-a11y/click-events-have-key-events": "off",
|
||||||
|
"jsx-a11y/interactive-supports-focus": "off",
|
||||||
|
"jsx-a11y/media-has-caption": "off",
|
||||||
|
"no-await-in-loop": "off",
|
||||||
|
"no-console": "off",
|
||||||
|
"no-nested-ternary": "off",
|
||||||
|
"no-restricted-syntax": "off",
|
||||||
|
"no-underscore-dangle": "off",
|
||||||
|
"react/jsx-props-no-spreading": "off",
|
||||||
|
"react/jsx-sort-props": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"callbacksLast": true,
|
||||||
|
"ignoreCase": false,
|
||||||
|
"noSortAlphabetically": false,
|
||||||
|
"reservedFirst": true,
|
||||||
|
"shorthandFirst": true,
|
||||||
|
"shorthandLast": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"react/react-in-jsx-scope": "off",
|
||||||
|
"sort-keys-fix/sort-keys-fix": "warn"
|
||||||
|
}
|
||||||
|
}
|
20
packages/renderer/assets/logo.svg
Normal file
20
packages/renderer/assets/logo.svg
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<svg width="410" height="404" viewBox="0 0 410 404" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path
|
||||||
|
d="M399.641 59.5246L215.643 388.545C211.844 395.338 202.084 395.378 198.228 388.618L10.5817 59.5563C6.38087 52.1896 12.6802 43.2665 21.0281 44.7586L205.223 77.6824C206.398 77.8924 207.601 77.8904 208.776 77.6763L389.119 44.8058C397.439 43.2894 403.768 52.1434 399.641 59.5246Z"
|
||||||
|
fill="url(#paint0_linear)"/>
|
||||||
|
<path
|
||||||
|
d="M292.965 1.5744L156.801 28.2552C154.563 28.6937 152.906 30.5903 152.771 32.8664L144.395 174.33C144.198 177.662 147.258 180.248 150.51 179.498L188.42 170.749C191.967 169.931 195.172 173.055 194.443 176.622L183.18 231.775C182.422 235.487 185.907 238.661 189.532 237.56L212.947 230.446C216.577 229.344 220.065 232.527 219.297 236.242L201.398 322.875C200.278 328.294 207.486 331.249 210.492 326.603L212.5 323.5L323.454 102.072C325.312 98.3645 322.108 94.137 318.036 94.9228L279.014 102.454C275.347 103.161 272.227 99.746 273.262 96.1583L298.731 7.86689C299.767 4.27314 296.636 0.855181 292.965 1.5744Z"
|
||||||
|
fill="url(#paint1_linear)"/>
|
||||||
|
<defs>
|
||||||
|
<linearGradient id="paint0_linear" x1="6.00017" y1="32.9999" x2="235" y2="344" gradientUnits="userSpaceOnUse">
|
||||||
|
<stop stop-color="#41D1FF"/>
|
||||||
|
<stop offset="1" stop-color="#BD34FE"/>
|
||||||
|
</linearGradient>
|
||||||
|
<linearGradient id="paint1_linear" x1="194.651" y1="8.81818" x2="236.076" y2="292.989"
|
||||||
|
gradientUnits="userSpaceOnUse">
|
||||||
|
<stop stop-color="#FFEA83"/>
|
||||||
|
<stop offset="0.0833333" stop-color="#FFDD35"/>
|
||||||
|
<stop offset="1" stop-color="#FFA800"/>
|
||||||
|
</linearGradient>
|
||||||
|
</defs>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.6 KiB |
16
packages/renderer/index.html
Normal file
16
packages/renderer/index.html
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta content="script-src 'self' blob:" http-equiv="Content-Security-Policy">
|
||||||
|
<meta content="width=device-width, initial-scale=1.0" name="viewport">
|
||||||
|
<title>Vite App</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
<script src="./src/index.tsx" type="module"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
63
packages/renderer/src/api/controller.ts
Normal file
63
packages/renderer/src/api/controller.ts
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import { useAuthStore } from '../store/auth.store';
|
||||||
|
import { navidromeApi } from './navidrome.api';
|
||||||
|
import type {
|
||||||
|
AlbumDetailQuery,
|
||||||
|
AlbumDetailResponse,
|
||||||
|
AlbumListParams,
|
||||||
|
AlbumListResponse,
|
||||||
|
} from './types';
|
||||||
|
|
||||||
|
export const getServerType = () => {
|
||||||
|
const server = useAuthStore.getState().currentServer;
|
||||||
|
|
||||||
|
if (!server) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return server.type;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getAlbumDetail = async (
|
||||||
|
query: AlbumDetailQuery,
|
||||||
|
signal?: AbortSignal,
|
||||||
|
): Promise<AlbumDetailResponse> => {
|
||||||
|
const serverType = getServerType();
|
||||||
|
if (!serverType) return null;
|
||||||
|
|
||||||
|
const functions = {
|
||||||
|
jellyfin: null,
|
||||||
|
navidrome: navidromeApi.getAlbumDetail,
|
||||||
|
subsonic: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (functions[serverType] === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return functions[serverType]?.(query, signal);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getAlbumList = async (
|
||||||
|
params: AlbumListParams,
|
||||||
|
signal?: AbortSignal,
|
||||||
|
): Promise<AlbumListResponse> => {
|
||||||
|
const serverType = getServerType();
|
||||||
|
if (!serverType) return null;
|
||||||
|
|
||||||
|
const functions = {
|
||||||
|
jellyfin: null,
|
||||||
|
navidrome: navidromeApi.getAlbumList,
|
||||||
|
subsonic: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (functions[serverType] === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return functions[serverType]?.(params, signal);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const apiController = {
|
||||||
|
getAlbumDetail,
|
||||||
|
getAlbumList,
|
||||||
|
};
|
0
packages/renderer/src/api/controller.types.ts
Normal file
0
packages/renderer/src/api/controller.types.ts
Normal file
7
packages/renderer/src/api/index.ts
Normal file
7
packages/renderer/src/api/index.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { apiController } from './controller';
|
||||||
|
import { navidromeApi } from './navidrome.api';
|
||||||
|
|
||||||
|
export const api = {
|
||||||
|
controller: apiController,
|
||||||
|
navidrome: navidromeApi,
|
||||||
|
};
|
270
packages/renderer/src/api/navidrome.api.ts
Normal file
270
packages/renderer/src/api/navidrome.api.ts
Normal file
@ -0,0 +1,270 @@
|
|||||||
|
import ky from 'ky';
|
||||||
|
import { nanoid } from 'nanoid/non-secure';
|
||||||
|
import type { ServerListItem } from '../store';
|
||||||
|
import { useAuthStore } from '../store';
|
||||||
|
import { ServerType } from '../types';
|
||||||
|
import type {
|
||||||
|
NDAlbumListResponse,
|
||||||
|
NDGenreListResponse,
|
||||||
|
NDAlbumListParams,
|
||||||
|
NDGenreListParams,
|
||||||
|
NDSongListParams,
|
||||||
|
NDArtistListResponse,
|
||||||
|
NDAuthenticate,
|
||||||
|
NDAlbum,
|
||||||
|
NDAlbumListSort,
|
||||||
|
NDAlbumDetailResponse,
|
||||||
|
NDSong,
|
||||||
|
NDSongListResponse,
|
||||||
|
} from './navidrome.types';
|
||||||
|
import { NDSortOrder } from './navidrome.types';
|
||||||
|
import type {
|
||||||
|
Album,
|
||||||
|
AlbumDetailQuery,
|
||||||
|
AlbumDetailResponse,
|
||||||
|
AlbumListParams,
|
||||||
|
AlbumListResponse,
|
||||||
|
Song,
|
||||||
|
} from './types';
|
||||||
|
import { SortOrder } from './types';
|
||||||
|
|
||||||
|
const api = ky.create({
|
||||||
|
hooks: {
|
||||||
|
afterResponse: [
|
||||||
|
(request, _options, response) => {
|
||||||
|
// const serverId = request.headers.get('--local-id');
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
],
|
||||||
|
beforeRequest: [
|
||||||
|
(request, options) => {
|
||||||
|
const { headers } = options;
|
||||||
|
|
||||||
|
console.log('headers', headers);
|
||||||
|
const { currentServer } = useAuthStore.getState();
|
||||||
|
const { ndCredential } = currentServer || {};
|
||||||
|
|
||||||
|
if (ndCredential) {
|
||||||
|
request.headers.set('x-nd-authorization', `Bearer ${ndCredential}`);
|
||||||
|
request.headers.set('--local-id', currentServer?.id || '');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const authenticate = async (options: { password: string; url: string; username: string }) => {
|
||||||
|
const { password, url, username } = options;
|
||||||
|
const cleanServerUrl = url.replace(/\/$/, '');
|
||||||
|
|
||||||
|
const data = await ky
|
||||||
|
.post(`${cleanServerUrl}/auth/login`, {
|
||||||
|
json: {
|
||||||
|
password,
|
||||||
|
username,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.json<NDAuthenticate>();
|
||||||
|
|
||||||
|
return {
|
||||||
|
credential: `u=${options.username}&s=${data.subsonicSalt}&t=${data.subsonicToken}`,
|
||||||
|
ndCredential: data.token,
|
||||||
|
username: data.username,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const getGenreList = async (params?: NDGenreListParams) => {
|
||||||
|
const data = await api
|
||||||
|
.get('api/genre', {
|
||||||
|
prefixUrl: useAuthStore.getState().currentServer?.url,
|
||||||
|
searchParams: params,
|
||||||
|
})
|
||||||
|
.json<NDGenreListResponse>();
|
||||||
|
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getArtistList = async (params?: NDGenreListParams) => {
|
||||||
|
const data = await api
|
||||||
|
.get('api/artist', {
|
||||||
|
prefixUrl: useAuthStore.getState().currentServer?.url,
|
||||||
|
searchParams: params,
|
||||||
|
})
|
||||||
|
.json<NDArtistListResponse>();
|
||||||
|
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getAlbumDetail = async (query: AlbumDetailQuery, signal?: AbortSignal) => {
|
||||||
|
const albumDetail = await api
|
||||||
|
.get(`api/album/${query.id}`, {
|
||||||
|
prefixUrl: useAuthStore.getState().currentServer?.url,
|
||||||
|
signal,
|
||||||
|
})
|
||||||
|
.json<NDAlbumDetailResponse>();
|
||||||
|
|
||||||
|
const albumSongs = await api
|
||||||
|
.get('api/song/', {
|
||||||
|
prefixUrl: useAuthStore.getState().currentServer?.url,
|
||||||
|
searchParams: {
|
||||||
|
_end: 0,
|
||||||
|
_order: NDSortOrder.ASC,
|
||||||
|
_sort: 'album',
|
||||||
|
_start: 0,
|
||||||
|
album_id: query.id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.json<NDSongListResponse>();
|
||||||
|
|
||||||
|
return { ...albumDetail, songs: albumSongs } as AlbumDetailResponse;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getAlbumList = async (params: AlbumListParams, signal?: AbortSignal) => {
|
||||||
|
const searchParams: NDAlbumListParams = {
|
||||||
|
_end: params._skip + (params._take || 0),
|
||||||
|
_order: params.sortOrder === SortOrder.ASC ? NDSortOrder.ASC : NDSortOrder.DESC,
|
||||||
|
_sort: params.sortBy as NDAlbumListSort,
|
||||||
|
_start: params._skip,
|
||||||
|
...params.nd,
|
||||||
|
};
|
||||||
|
|
||||||
|
const res = await api.get('api/album', {
|
||||||
|
prefixUrl: useAuthStore.getState().currentServer?.url,
|
||||||
|
searchParams,
|
||||||
|
signal,
|
||||||
|
});
|
||||||
|
|
||||||
|
const itemCount = res.headers.get('X-Total-Count');
|
||||||
|
const data = await res.json<NDAlbumListResponse>();
|
||||||
|
|
||||||
|
return {
|
||||||
|
items: data,
|
||||||
|
pagination: {
|
||||||
|
startIndex: params?._skip || 0,
|
||||||
|
totalEntries: Number(itemCount),
|
||||||
|
},
|
||||||
|
} as AlbumListResponse;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getSongList = async (params?: NDSongListParams) => {
|
||||||
|
const data = await api
|
||||||
|
.get('api/song', {
|
||||||
|
prefixUrl: useAuthStore.getState().currentServer?.url,
|
||||||
|
searchParams: params,
|
||||||
|
})
|
||||||
|
.json<NDSongListResponse>();
|
||||||
|
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const navidromeApi = {
|
||||||
|
authenticate,
|
||||||
|
getAlbumDetail,
|
||||||
|
getAlbumList,
|
||||||
|
getArtistList,
|
||||||
|
getGenreList,
|
||||||
|
getSongList,
|
||||||
|
};
|
||||||
|
|
||||||
|
const getCoverArtUrl = (args: {
|
||||||
|
baseUrl: string;
|
||||||
|
coverArtId: string;
|
||||||
|
credential: string;
|
||||||
|
size: number;
|
||||||
|
}) => {
|
||||||
|
const size = args.size ? args.size : 250;
|
||||||
|
|
||||||
|
if (!args.coverArtId || args.coverArtId.match('2a96cbd8b46e442fc41c2b86b821562f')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
`${args.baseUrl}/rest/getCoverArt.view` +
|
||||||
|
`?id=${args.coverArtId}` +
|
||||||
|
`&${args.credential}` +
|
||||||
|
'&v=1.13.0' +
|
||||||
|
'&c=feishin' +
|
||||||
|
`&size=${size}`
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const normalizeAlbum = (item: NDAlbum, server: ServerListItem, imageSize?: number) => {
|
||||||
|
const imageUrl = getCoverArtUrl({
|
||||||
|
baseUrl: server.url,
|
||||||
|
coverArtId: item.coverArtId,
|
||||||
|
credential: server.credential,
|
||||||
|
size: imageSize || 300,
|
||||||
|
});
|
||||||
|
|
||||||
|
const imagePlaceholderUrl = imageUrl?.replace(/size=\d+/, 'size=50');
|
||||||
|
|
||||||
|
return {
|
||||||
|
albumArtists: [{ id: item.albumArtistId, name: item.albumArtist }],
|
||||||
|
artists: [{ id: item.artistId, name: item.artist }],
|
||||||
|
backdropImageUrl: null,
|
||||||
|
createdAt: item.createdAt,
|
||||||
|
genres: item.genres,
|
||||||
|
id: item.id,
|
||||||
|
imagePlaceholderUrl,
|
||||||
|
imageUrl,
|
||||||
|
isCompilation: item.compilation,
|
||||||
|
isFavorite: item.starred,
|
||||||
|
name: item.name,
|
||||||
|
playCount: item.playCount,
|
||||||
|
rating: item.rating,
|
||||||
|
releaseDate: new Date(item.minYear, 0, 1).toISOString(),
|
||||||
|
releaseYear: item.minYear,
|
||||||
|
serverType: ServerType.NAVIDROME,
|
||||||
|
size: item.size,
|
||||||
|
songCount: item.songCount,
|
||||||
|
uniqueId: nanoid(),
|
||||||
|
updatedAt: item.updatedAt,
|
||||||
|
} as Album;
|
||||||
|
};
|
||||||
|
|
||||||
|
const normalizeSong = (
|
||||||
|
item: NDSong,
|
||||||
|
server: ServerListItem,
|
||||||
|
deviceId: string,
|
||||||
|
imageSize?: number,
|
||||||
|
) => {
|
||||||
|
const imageUrl = getCoverArtUrl({
|
||||||
|
baseUrl: server.url,
|
||||||
|
coverArtId: item.albumId,
|
||||||
|
credential: server.credential,
|
||||||
|
size: imageSize || 300,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
album: item.album,
|
||||||
|
albumArtists: [{ id: item.artistId, name: item.artist }],
|
||||||
|
albumId: item.albumId,
|
||||||
|
artistName: item.artist,
|
||||||
|
artists: [{ id: item.artistId, name: item.artist }],
|
||||||
|
bitRate: item.bitRate,
|
||||||
|
compilation: item.compilation,
|
||||||
|
container: item.suffix,
|
||||||
|
createdAt: item.createdAt,
|
||||||
|
discNumber: item.discNumber,
|
||||||
|
duration: item.duration,
|
||||||
|
genres: item.genres,
|
||||||
|
id: item.id,
|
||||||
|
imageUrl,
|
||||||
|
isFavorite: item.starred,
|
||||||
|
name: item.title,
|
||||||
|
releaseDate: new Date(item.year, 0, 1).toISOString(),
|
||||||
|
releaseYear: String(item.year),
|
||||||
|
serverId: server.id,
|
||||||
|
size: item.size,
|
||||||
|
streamUrl: `${server.url}/rest/stream.view?id=${item.id}&v=1.13.0&c=feishin_${deviceId}&${server.credential}`,
|
||||||
|
trackNumber: item.trackNumber,
|
||||||
|
type: ServerType.NAVIDROME,
|
||||||
|
uniqueId: nanoid(),
|
||||||
|
updatedAt: item.updatedAt,
|
||||||
|
} as Song;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ndNormalize = {
|
||||||
|
album: normalizeAlbum,
|
||||||
|
song: normalizeSong,
|
||||||
|
};
|
184
packages/renderer/src/api/navidrome.types.ts
Normal file
184
packages/renderer/src/api/navidrome.types.ts
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
export type NDAuthenticate = {
|
||||||
|
id: string;
|
||||||
|
isAdmin: boolean;
|
||||||
|
name: string;
|
||||||
|
subsonicSalt: string;
|
||||||
|
subsonicToken: string;
|
||||||
|
token: string;
|
||||||
|
username: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type NDGenre = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type NDAlbum = {
|
||||||
|
albumArtist: string;
|
||||||
|
albumArtistId: string;
|
||||||
|
allArtistIds: string;
|
||||||
|
artist: string;
|
||||||
|
artistId: string;
|
||||||
|
compilation: boolean;
|
||||||
|
coverArtId: string;
|
||||||
|
coverArtPath: string;
|
||||||
|
createdAt: string;
|
||||||
|
duration: number;
|
||||||
|
fullText: string;
|
||||||
|
genre: string;
|
||||||
|
genres: NDGenre[];
|
||||||
|
id: string;
|
||||||
|
maxYear: number;
|
||||||
|
mbzAlbumArtistId: string;
|
||||||
|
mbzAlbumId: string;
|
||||||
|
minYear: number;
|
||||||
|
name: string;
|
||||||
|
orderAlbumArtistName: string;
|
||||||
|
orderAlbumName: string;
|
||||||
|
playCount: number;
|
||||||
|
playDate: string;
|
||||||
|
rating: number;
|
||||||
|
size: number;
|
||||||
|
songCount: number;
|
||||||
|
sortAlbumArtistName: string;
|
||||||
|
sortArtistName: string;
|
||||||
|
starred: boolean;
|
||||||
|
starredAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
} & {
|
||||||
|
songs?: NDSong[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type NDSong = {
|
||||||
|
album: string;
|
||||||
|
albumArtist: string;
|
||||||
|
albumArtistId: string;
|
||||||
|
albumId: string;
|
||||||
|
artist: string;
|
||||||
|
artistId: string;
|
||||||
|
bitRate: number;
|
||||||
|
bookmarkPosition: number;
|
||||||
|
channels: number;
|
||||||
|
compilation: boolean;
|
||||||
|
createdAt: string;
|
||||||
|
discNumber: number;
|
||||||
|
duration: number;
|
||||||
|
fullText: string;
|
||||||
|
genre: string;
|
||||||
|
genres: NDGenre[];
|
||||||
|
hasCoverArt: boolean;
|
||||||
|
id: string;
|
||||||
|
mbzAlbumArtistId: string;
|
||||||
|
mbzAlbumId: string;
|
||||||
|
mbzArtistId: string;
|
||||||
|
mbzTrackId: string;
|
||||||
|
orderAlbumArtistName: string;
|
||||||
|
orderAlbumName: string;
|
||||||
|
orderArtistName: string;
|
||||||
|
orderTitle: string;
|
||||||
|
path: string;
|
||||||
|
playCount: number;
|
||||||
|
playDate: string;
|
||||||
|
rating: number;
|
||||||
|
size: number;
|
||||||
|
sortAlbumArtistName: string;
|
||||||
|
sortArtistName: string;
|
||||||
|
starred: boolean;
|
||||||
|
starredAt: string;
|
||||||
|
suffix: string;
|
||||||
|
title: string;
|
||||||
|
trackNumber: number;
|
||||||
|
updatedAt: string;
|
||||||
|
year: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type NDArtist = {
|
||||||
|
albumCount: number;
|
||||||
|
biography: string;
|
||||||
|
externalInfoUpdatedAt: string;
|
||||||
|
externalUrl: string;
|
||||||
|
fullText: string;
|
||||||
|
genres: NDGenre[];
|
||||||
|
id: string;
|
||||||
|
largeImageUrl: string;
|
||||||
|
mbzArtistId: string;
|
||||||
|
mediumImageUrl: string;
|
||||||
|
name: string;
|
||||||
|
orderArtistName: string;
|
||||||
|
playCount: number;
|
||||||
|
playDate: string;
|
||||||
|
rating: number;
|
||||||
|
size: number;
|
||||||
|
smallImageUrl: string;
|
||||||
|
songCount: number;
|
||||||
|
starred: boolean;
|
||||||
|
starredAt: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type NDGenreListResponse = NDGenre[];
|
||||||
|
|
||||||
|
export type NDAlbumDetailResponse = NDAlbum;
|
||||||
|
|
||||||
|
export type NDAlbumListResponse = NDAlbum[];
|
||||||
|
|
||||||
|
export type NDSongListResponse = NDSong[];
|
||||||
|
|
||||||
|
export type NDArtistListResponse = NDArtist[];
|
||||||
|
|
||||||
|
export type NDPagination = {
|
||||||
|
_end?: number;
|
||||||
|
_start?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export enum NDSortOrder {
|
||||||
|
ASC = 'ASC',
|
||||||
|
DESC = 'DESC',
|
||||||
|
}
|
||||||
|
|
||||||
|
export type NDOrder = {
|
||||||
|
_order?: NDSortOrder;
|
||||||
|
};
|
||||||
|
|
||||||
|
export enum NDGenreListSort {
|
||||||
|
NAME = 'name',
|
||||||
|
}
|
||||||
|
|
||||||
|
export type NDGenreListParams = {
|
||||||
|
_sort?: NDGenreListSort;
|
||||||
|
id?: string;
|
||||||
|
} & NDPagination &
|
||||||
|
NDOrder;
|
||||||
|
|
||||||
|
export enum NDAlbumListSort {
|
||||||
|
ALBUM_ARTIST = 'albumArtist',
|
||||||
|
ARTIST = 'artist',
|
||||||
|
DURATION = 'duration',
|
||||||
|
NAME = 'name',
|
||||||
|
PLAY_COUNT = 'playCount',
|
||||||
|
RANDOM = 'random',
|
||||||
|
RATING = 'rating',
|
||||||
|
RECENTLY_ADDED = 'recently_added',
|
||||||
|
SONG_COUNT = 'songCount',
|
||||||
|
STARRED = 'starred',
|
||||||
|
YEAR = 'max_year',
|
||||||
|
}
|
||||||
|
|
||||||
|
export type NDAlbumListParams = {
|
||||||
|
_sort?: NDAlbumListSort;
|
||||||
|
artist_id?: string;
|
||||||
|
compilation?: boolean;
|
||||||
|
genre_id?: string;
|
||||||
|
has_rating?: boolean;
|
||||||
|
id?: string;
|
||||||
|
name?: string;
|
||||||
|
recently_played?: boolean;
|
||||||
|
starred?: boolean;
|
||||||
|
year?: number;
|
||||||
|
} & NDPagination &
|
||||||
|
NDOrder;
|
||||||
|
|
||||||
|
export type NDSongListParams = {
|
||||||
|
genre_id?: string;
|
||||||
|
starred?: boolean;
|
||||||
|
} & NDPagination &
|
||||||
|
NDOrder;
|
33
packages/renderer/src/api/query-keys.ts
Normal file
33
packages/renderer/src/api/query-keys.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import type { AlbumListParams } from './types';
|
||||||
|
import type { AlbumDetailQuery } from './types';
|
||||||
|
|
||||||
|
export const queryKeys = {
|
||||||
|
albums: {
|
||||||
|
detail: (serverId: string, query: AlbumDetailQuery) => ['albums', serverId, query] as const,
|
||||||
|
list: (serverId: string, params: AlbumListParams) =>
|
||||||
|
[serverId, 'albums', 'list', serverId, params] as const,
|
||||||
|
root: ['albums'],
|
||||||
|
},
|
||||||
|
genres: {
|
||||||
|
list: (serverId: string) => [serverId, 'genres', 'list'] as const,
|
||||||
|
root: (serverId: string) => [serverId, 'genres'] as const,
|
||||||
|
},
|
||||||
|
ping: (url: string) => ['ping', url] as const,
|
||||||
|
server: {
|
||||||
|
root: (serverId: string) => [serverId] as const,
|
||||||
|
},
|
||||||
|
servers: {
|
||||||
|
list: (params?: any) => ['servers', 'list', params] as const,
|
||||||
|
map: () => ['servers', 'map'] as const,
|
||||||
|
root: ['servers'],
|
||||||
|
},
|
||||||
|
tasks: {
|
||||||
|
list: () => ['tasks', 'list'] as const,
|
||||||
|
root: ['tasks'],
|
||||||
|
},
|
||||||
|
users: {
|
||||||
|
detail: (userId: string) => ['users', userId] as const,
|
||||||
|
list: (params?: any) => ['users', 'list', params] as const,
|
||||||
|
root: ['users'],
|
||||||
|
},
|
||||||
|
};
|
155
packages/renderer/src/api/shared.api.ts
Normal file
155
packages/renderer/src/api/shared.api.ts
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
import md5 from 'md5';
|
||||||
|
import { ServerType } from '/@/types';
|
||||||
|
import { randomString } from '/@/utils';
|
||||||
|
|
||||||
|
type JFAuthenticate = {
|
||||||
|
AccessToken: string;
|
||||||
|
ServerId: string;
|
||||||
|
SessionInfo: any;
|
||||||
|
User: any;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const jfAuthenticate = async (options: {
|
||||||
|
password: string;
|
||||||
|
url: string;
|
||||||
|
username: string;
|
||||||
|
}) => {
|
||||||
|
const { password, url, username } = options;
|
||||||
|
const cleanServerUrl = url.replace(/\/$/, '');
|
||||||
|
|
||||||
|
const { data } = await axios.post<JFAuthenticate>(
|
||||||
|
`${cleanServerUrl}/users/authenticatebyname`,
|
||||||
|
{ pw: password, username },
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'X-Emby-Authorization':
|
||||||
|
'MediaBrowser Client="Feishin", Device="PC", DeviceId="Feishin", Version="0.0.1-alpha1"',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
type NDAuthenticate = {
|
||||||
|
id: string;
|
||||||
|
isAdmin: boolean;
|
||||||
|
name: string;
|
||||||
|
subsonicSalt: string;
|
||||||
|
subsonicToken: string;
|
||||||
|
token: string;
|
||||||
|
username: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const ndAuthenticate = async (options: { password: string; url: string; username: string }) => {
|
||||||
|
const { password, url, username } = options;
|
||||||
|
const cleanServerUrl = url.replace(/\/$/, '');
|
||||||
|
|
||||||
|
const { data } = await axios.post<NDAuthenticate>(`${cleanServerUrl}/auth/login`, {
|
||||||
|
password,
|
||||||
|
username,
|
||||||
|
});
|
||||||
|
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
const ssAuthenticate = async (options: {
|
||||||
|
legacy?: boolean;
|
||||||
|
password: string;
|
||||||
|
url: string;
|
||||||
|
username: string;
|
||||||
|
}) => {
|
||||||
|
let token;
|
||||||
|
|
||||||
|
const cleanServerUrl = options.url.replace(/\/$/, '');
|
||||||
|
|
||||||
|
if (options.legacy) {
|
||||||
|
token = `u=${options.username}&p=${options.password}`;
|
||||||
|
} else {
|
||||||
|
const salt = randomString();
|
||||||
|
const hash = md5(options.password + salt);
|
||||||
|
token = `u=${options.username}&s=${salt}&t=${hash}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data } = await axios.get(
|
||||||
|
`${cleanServerUrl}/rest/ping.view?v=1.13.0&c=Feishin&f=json&${token}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
return { token, ...data };
|
||||||
|
};
|
||||||
|
|
||||||
|
export const remoteServerLogin = async (options: {
|
||||||
|
legacy?: boolean;
|
||||||
|
password: string;
|
||||||
|
type: ServerType;
|
||||||
|
url: string;
|
||||||
|
username: string;
|
||||||
|
}) => {
|
||||||
|
if (options.type === ServerType.JELLYFIN) {
|
||||||
|
try {
|
||||||
|
const res = await jfAuthenticate({
|
||||||
|
password: options.password,
|
||||||
|
url: options.url,
|
||||||
|
username: options.username,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
remoteUserId: res.User.Id,
|
||||||
|
token: res.AccessToken,
|
||||||
|
type: ServerType.JELLYFIN,
|
||||||
|
url: options.url,
|
||||||
|
username: options.username,
|
||||||
|
};
|
||||||
|
} catch (err: any) {
|
||||||
|
return { message: err.message, type: 'error' };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.type === ServerType.SUBSONIC) {
|
||||||
|
const res = await ssAuthenticate({
|
||||||
|
legacy: options.legacy,
|
||||||
|
password: options.password,
|
||||||
|
url: options.url,
|
||||||
|
username: options.username,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.status === 'failed') {
|
||||||
|
return {
|
||||||
|
message: 'Could not validate username and password',
|
||||||
|
type: 'error',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
remoteUserId: '',
|
||||||
|
token: res.token,
|
||||||
|
type: ServerType.SUBSONIC,
|
||||||
|
url: options.url,
|
||||||
|
username: options.username,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.type === ServerType.NAVIDROME) {
|
||||||
|
try {
|
||||||
|
const res = await ndAuthenticate({
|
||||||
|
password: options.password,
|
||||||
|
url: options.url,
|
||||||
|
username: options.username,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
remoteUserId: res.id,
|
||||||
|
token: `u=${res.name}&s=${res.subsonicSalt}&t=${res.subsonicToken}`,
|
||||||
|
// token: res.token,
|
||||||
|
type: ServerType.NAVIDROME,
|
||||||
|
url: options.url,
|
||||||
|
username: options.username,
|
||||||
|
};
|
||||||
|
} catch (err: any) {
|
||||||
|
return { message: err.message, type: 'error' };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { message: 'Not found', type: 'error' };
|
||||||
|
};
|
170
packages/renderer/src/api/subsonic.api.ts
Normal file
170
packages/renderer/src/api/subsonic.api.ts
Normal file
@ -0,0 +1,170 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
import md5 from 'md5';
|
||||||
|
import { randomString } from '../utils/random-string';
|
||||||
|
import type {
|
||||||
|
SSAlbumListEntry,
|
||||||
|
SSAlbumListResponse,
|
||||||
|
SSAlbumResponse,
|
||||||
|
SSAlbumsParams,
|
||||||
|
SSArtistIndex,
|
||||||
|
SSArtistInfoResponse,
|
||||||
|
SSArtistsResponse,
|
||||||
|
SSGenresResponse,
|
||||||
|
SSMusicFoldersResponse,
|
||||||
|
} from './subsonic.types';
|
||||||
|
|
||||||
|
const getCoverArtUrl = (args: {
|
||||||
|
baseUrl: string;
|
||||||
|
coverArtId: string;
|
||||||
|
credential: string;
|
||||||
|
size: number;
|
||||||
|
}) => {
|
||||||
|
const size = args.size ? args.size : 150;
|
||||||
|
|
||||||
|
if (!args.coverArtId || args.coverArtId.match('2a96cbd8b46e442fc41c2b86b821562f')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
`${args.baseUrl}/getCoverArt.view` +
|
||||||
|
`?id=${args.coverArtId}` +
|
||||||
|
`&${args.credential}` +
|
||||||
|
'&v=1.13.0' +
|
||||||
|
'&c=feishin' +
|
||||||
|
`&size=${size}`
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const api = axios.create({
|
||||||
|
validateStatus: (status) => status >= 200,
|
||||||
|
});
|
||||||
|
|
||||||
|
api.interceptors.response.use(
|
||||||
|
(res: any) => {
|
||||||
|
res.data = res.data['subsonic-response'];
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
(err: any) => {
|
||||||
|
return Promise.reject(err);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const authenticate = async (options: {
|
||||||
|
legacy?: boolean;
|
||||||
|
password: string;
|
||||||
|
url: string;
|
||||||
|
username: string;
|
||||||
|
}) => {
|
||||||
|
let token;
|
||||||
|
|
||||||
|
const cleanServerUrl = options.url.replace(/\/$/, '');
|
||||||
|
|
||||||
|
if (options.legacy) {
|
||||||
|
token = `u=${options.username}&p=${options.password}`;
|
||||||
|
} else {
|
||||||
|
const salt = randomString(12);
|
||||||
|
const hash = md5(options.password + salt);
|
||||||
|
token = `u=${options.username}&s=${salt}&t=${hash}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data } = await api.get(
|
||||||
|
`${cleanServerUrl}/rest/ping.view?v=1.13.0&c=Feishin&f=json&${token}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
return { token, ...data };
|
||||||
|
};
|
||||||
|
|
||||||
|
const getMusicFolders = async (server: Partial<Server>) => {
|
||||||
|
const { data } = await api.get<SSMusicFoldersResponse>(
|
||||||
|
`${server.url}/rest/getMusicFolders.view?v=1.13.0&c=Feishin&f=json&${server.token}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
return data.musicFolders.musicFolder;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getArtists = async (server: Server, musicFolderId: string) => {
|
||||||
|
const { data } = await api.get<SSArtistsResponse>(
|
||||||
|
`${server.url}/rest/getArtists.view?v=1.13.0&c=Feishin&f=json&${server.token}`,
|
||||||
|
{ params: { musicFolderId } },
|
||||||
|
);
|
||||||
|
|
||||||
|
const artists = (data.artists?.index || []).flatMap((index: SSArtistIndex) => index.artist);
|
||||||
|
|
||||||
|
return artists;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getGenres = async (server: Server) => {
|
||||||
|
const { data: genres } = await api.get<SSGenresResponse>(
|
||||||
|
`${server.url}/rest/getGenres.view?v=1.13.0&c=Feishin&f=json&${server.token}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
return genres;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getAlbum = async (server: Server, id: string) => {
|
||||||
|
const { data: album } = await api.get<SSAlbumResponse>(
|
||||||
|
`${server.url}/rest/getAlbum.view?v=1.13.0&c=Feishin&f=json&${server.token}`,
|
||||||
|
{ params: { id } },
|
||||||
|
);
|
||||||
|
|
||||||
|
return album;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getAlbums = async (server: Server, params: SSAlbumsParams, recursiveData: any[] = []) => {
|
||||||
|
const albums: any = api
|
||||||
|
.get<SSAlbumListResponse>(
|
||||||
|
`${server.url}/rest/getAlbumList2.view?v=1.13.0&c=Feishin&f=json&${server.token}`,
|
||||||
|
{ params },
|
||||||
|
)
|
||||||
|
.then((res) => {
|
||||||
|
if (!res.data.albumList2?.album || res.data.albumList2?.album?.length === 0) {
|
||||||
|
// Flatten and return once there are no more albums left
|
||||||
|
return recursiveData.flatMap((album) => album);
|
||||||
|
}
|
||||||
|
|
||||||
|
// On every iteration, push the existing combined album array and increase the offset
|
||||||
|
recursiveData.push(res.data.albumList2.album);
|
||||||
|
return getAlbums(
|
||||||
|
server,
|
||||||
|
{
|
||||||
|
musicFolderId: params.musicFolderId,
|
||||||
|
offset: (params.offset || 0) + (params.size || 0),
|
||||||
|
size: params.size,
|
||||||
|
type: 'newest',
|
||||||
|
},
|
||||||
|
|
||||||
|
recursiveData,
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch((err) => console.log(err));
|
||||||
|
|
||||||
|
return albums as SSAlbumListEntry[];
|
||||||
|
};
|
||||||
|
|
||||||
|
const getArtistInfo = async (server: Server, id: string) => {
|
||||||
|
const { data: artistInfo } = await api.get<SSArtistInfoResponse>(
|
||||||
|
`${server.url}/rest/getArtistInfo2.view?v=1.13.0&c=Feishin&f=json&${server.token}`,
|
||||||
|
{ params: { id } },
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...artistInfo,
|
||||||
|
artistInfo2: {
|
||||||
|
...artistInfo.artistInfo2,
|
||||||
|
biography: artistInfo.artistInfo2.biography
|
||||||
|
.replaceAll(/<a target.*<\/a>/gm, '')
|
||||||
|
.replace('Biography not available', ''),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const subsonicApi = {
|
||||||
|
authenticate,
|
||||||
|
getAlbum,
|
||||||
|
getAlbums,
|
||||||
|
getArtistInfo,
|
||||||
|
getArtists,
|
||||||
|
getCoverArtUrl,
|
||||||
|
getGenres,
|
||||||
|
getMusicFolders,
|
||||||
|
};
|
139
packages/renderer/src/api/subsonic.types.ts
Normal file
139
packages/renderer/src/api/subsonic.types.ts
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
export interface SSBaseResponse {
|
||||||
|
serverVersion?: 'string';
|
||||||
|
status: 'string';
|
||||||
|
type?: 'string';
|
||||||
|
version: 'string';
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SSMusicFoldersResponse extends SSBaseResponse {
|
||||||
|
musicFolders: {
|
||||||
|
musicFolder: SSMusicFolder[];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SSGenresResponse extends SSBaseResponse {
|
||||||
|
genres: {
|
||||||
|
genre: SSGenre[];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SSArtistsResponse extends SSBaseResponse {
|
||||||
|
artists: {
|
||||||
|
ignoredArticles: string;
|
||||||
|
index: SSArtistIndex[];
|
||||||
|
lastModified: number;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SSAlbumListResponse extends SSBaseResponse {
|
||||||
|
albumList2: {
|
||||||
|
album: SSAlbumListEntry[];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SSAlbumResponse extends SSBaseResponse {
|
||||||
|
album: SSAlbum;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SSArtistInfoResponse extends SSBaseResponse {
|
||||||
|
artistInfo2: SSArtistInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SSArtistInfo {
|
||||||
|
biography: string;
|
||||||
|
largeImageUrl?: string;
|
||||||
|
lastFmUrl?: string;
|
||||||
|
mediumImageUrl?: string;
|
||||||
|
musicBrainzId?: string;
|
||||||
|
smallImageUrl?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SSMusicFolder {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SSGenre {
|
||||||
|
albumCount?: number;
|
||||||
|
songCount?: number;
|
||||||
|
value: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SSArtistIndex {
|
||||||
|
artist: SSArtistListEntry[];
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SSArtistListEntry {
|
||||||
|
albumCount: string;
|
||||||
|
artistImageUrl?: string;
|
||||||
|
coverArt?: string;
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SSAlbumListEntry {
|
||||||
|
album: string;
|
||||||
|
artist: string;
|
||||||
|
artistId: string;
|
||||||
|
coverArt: string;
|
||||||
|
created: string;
|
||||||
|
duration: number;
|
||||||
|
genre?: string;
|
||||||
|
id: string;
|
||||||
|
isDir: boolean;
|
||||||
|
isVideo: boolean;
|
||||||
|
name: string;
|
||||||
|
parent: string;
|
||||||
|
songCount: number;
|
||||||
|
starred?: boolean;
|
||||||
|
title: string;
|
||||||
|
userRating?: number;
|
||||||
|
year: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SSAlbum extends SSAlbumListEntry {
|
||||||
|
song: SSSong[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SSSong {
|
||||||
|
album: string;
|
||||||
|
albumId: string;
|
||||||
|
artist: string;
|
||||||
|
artistId?: string;
|
||||||
|
bitRate: number;
|
||||||
|
contentType: string;
|
||||||
|
coverArt: string;
|
||||||
|
created: string;
|
||||||
|
discNumber?: number;
|
||||||
|
duration: number;
|
||||||
|
genre: string;
|
||||||
|
id: string;
|
||||||
|
isDir: boolean;
|
||||||
|
isVideo: boolean;
|
||||||
|
parent: string;
|
||||||
|
path: string;
|
||||||
|
playCount: number;
|
||||||
|
size: number;
|
||||||
|
starred?: boolean;
|
||||||
|
suffix: string;
|
||||||
|
title: string;
|
||||||
|
track: number;
|
||||||
|
type: string;
|
||||||
|
userRating?: number;
|
||||||
|
year: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SSAlbumsParams {
|
||||||
|
fromYear?: number;
|
||||||
|
genre?: string;
|
||||||
|
musicFolderId?: string;
|
||||||
|
offset?: number;
|
||||||
|
size?: number;
|
||||||
|
toYear?: number;
|
||||||
|
type: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SSArtistsParams {
|
||||||
|
musicFolderId?: number;
|
||||||
|
}
|
261
packages/renderer/src/api/types.ts
Normal file
261
packages/renderer/src/api/types.ts
Normal file
@ -0,0 +1,261 @@
|
|||||||
|
import type { ServerListItem } from '../store';
|
||||||
|
import type { ServerType } from '../types';
|
||||||
|
import type { JFAlbum, JFAlbumListSort, JFSortOrder } from './jellyfin.types';
|
||||||
|
import type { NDAlbum, NDAlbumListSort, NDOrder } from './navidrome.types';
|
||||||
|
|
||||||
|
export enum SortOrder {
|
||||||
|
ASC = 'ASC',
|
||||||
|
DESC = 'DESC',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum ExternalSource {
|
||||||
|
LASTFM = 'LASTFM',
|
||||||
|
MUSICBRAINZ = 'MUSICBRAINZ',
|
||||||
|
SPOTIFY = 'SPOTIFY',
|
||||||
|
THEAUDIODB = 'THEAUDIODB',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum ExternalType {
|
||||||
|
ID = 'ID',
|
||||||
|
LINK = 'LINK',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum ImageType {
|
||||||
|
BACKDROP = 'BACKDROP',
|
||||||
|
LOGO = 'LOGO',
|
||||||
|
PRIMARY = 'PRIMARY',
|
||||||
|
SCREENSHOT = 'SCREENSHOT',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum TaskType {
|
||||||
|
FULL_SCAN = 'FULL_SCAN',
|
||||||
|
LASTFM = 'LASTFM',
|
||||||
|
MUSICBRAINZ = 'MUSICBRAINZ',
|
||||||
|
QUICK_SCAN = 'QUICK_SCAN',
|
||||||
|
REFRESH = 'REFRESH',
|
||||||
|
SPOTIFY = 'SPOTIFY',
|
||||||
|
}
|
||||||
|
|
||||||
|
export type EndpointDetails = {
|
||||||
|
server: ServerListItem;
|
||||||
|
};
|
||||||
|
|
||||||
|
// export interface BaseResponse<T> {
|
||||||
|
// error?: string | any;
|
||||||
|
// items: T;
|
||||||
|
// response: 'Success' | 'Error';
|
||||||
|
// statusCode: number;
|
||||||
|
// }
|
||||||
|
|
||||||
|
export interface BasePaginatedResponse<T> {
|
||||||
|
error?: string | any;
|
||||||
|
items: T;
|
||||||
|
pagination?: {
|
||||||
|
startIndex: number;
|
||||||
|
totalEntries: number;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ApiError = {
|
||||||
|
error: {
|
||||||
|
message: string;
|
||||||
|
path: string;
|
||||||
|
trace: string[];
|
||||||
|
};
|
||||||
|
response: string;
|
||||||
|
statusCode: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type AuthResponse = {
|
||||||
|
credential: string;
|
||||||
|
ndCredential?: string;
|
||||||
|
username: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
// export type NullResponse = BaseResponse<null>;
|
||||||
|
|
||||||
|
export type PaginationParams = {
|
||||||
|
skip: number;
|
||||||
|
take: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type RelatedServerFolder = {
|
||||||
|
enabled: boolean;
|
||||||
|
id: string;
|
||||||
|
lastScannedAt: string | null;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ServerFolder = {
|
||||||
|
createdAt: string;
|
||||||
|
enabled: boolean;
|
||||||
|
id: string;
|
||||||
|
lastScannedAt: string | null;
|
||||||
|
name: string;
|
||||||
|
serverId: string;
|
||||||
|
updatedAt: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Genre = {
|
||||||
|
albumArtistCount: number;
|
||||||
|
albumCount: number;
|
||||||
|
artistCount: number;
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
songCount: number;
|
||||||
|
totalCount: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type RelatedGenre = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Album = {
|
||||||
|
albumArtists: RelatedArtist[];
|
||||||
|
artists: RelatedArtist[];
|
||||||
|
backdropImageUrl: string | null;
|
||||||
|
createdAt: string;
|
||||||
|
genres: RelatedGenre[];
|
||||||
|
id: string;
|
||||||
|
imagePlaceholderUrl: string | null;
|
||||||
|
imageUrl: string | null;
|
||||||
|
isCompilation: boolean | null;
|
||||||
|
isFavorite: boolean;
|
||||||
|
name: string;
|
||||||
|
playCount: number | null;
|
||||||
|
rating: number | null;
|
||||||
|
releaseDate: string | null;
|
||||||
|
releaseYear: number | null;
|
||||||
|
serverType: ServerType;
|
||||||
|
size: number | null;
|
||||||
|
songCount: number | null;
|
||||||
|
songs?: Song[];
|
||||||
|
uniqueId: string;
|
||||||
|
updatedAt: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Song = {
|
||||||
|
album: string;
|
||||||
|
albumArtists: RelatedArtist[];
|
||||||
|
albumId: string;
|
||||||
|
artistName: string;
|
||||||
|
artists: RelatedArtist[];
|
||||||
|
bitRate: number;
|
||||||
|
compilation: boolean | null;
|
||||||
|
container: string;
|
||||||
|
createdAt: string;
|
||||||
|
discNumber: number;
|
||||||
|
duration: number;
|
||||||
|
genres: RelatedGenre[];
|
||||||
|
id: string;
|
||||||
|
imageUrl: string;
|
||||||
|
isFavorite: boolean;
|
||||||
|
name: string;
|
||||||
|
releaseDate: string;
|
||||||
|
releaseYear: string;
|
||||||
|
serverId: string;
|
||||||
|
size: number;
|
||||||
|
streamUrl: string;
|
||||||
|
trackNumber: number;
|
||||||
|
type: ServerType;
|
||||||
|
uniqueId: string;
|
||||||
|
updatedAt: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type AlbumArtist = {
|
||||||
|
biography: string | null;
|
||||||
|
createdAt: string;
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
remoteCreatedAt: string | null;
|
||||||
|
serverFolderId: string;
|
||||||
|
updatedAt: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type RelatedAlbumArtist = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Artist = {
|
||||||
|
biography: string | null;
|
||||||
|
createdAt: string;
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
remoteCreatedAt: string | null;
|
||||||
|
serverFolderId: string;
|
||||||
|
updatedAt: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type RelatedArtist = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type RelatedServer = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
type: ServerType;
|
||||||
|
url: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type RelatedUser = {
|
||||||
|
enabled: boolean;
|
||||||
|
id: string;
|
||||||
|
isAdmin: boolean;
|
||||||
|
username: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Task = {
|
||||||
|
createdAt: string;
|
||||||
|
id: string;
|
||||||
|
isCompleted: boolean;
|
||||||
|
isError: boolean;
|
||||||
|
message: string;
|
||||||
|
server: RelatedServer | null;
|
||||||
|
type: TaskType;
|
||||||
|
updatedAt: string;
|
||||||
|
user: RelatedUser | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type AlbumListSort = NDAlbumListSort | JFAlbumListSort;
|
||||||
|
|
||||||
|
export type ListSortOrder = NDOrder | JFSortOrder;
|
||||||
|
|
||||||
|
export type AlbumListParams = {
|
||||||
|
_skip: number;
|
||||||
|
_take?: number;
|
||||||
|
musicFolderId: string | null;
|
||||||
|
nd?: {
|
||||||
|
artist_id?: string;
|
||||||
|
compilation?: boolean;
|
||||||
|
genre_id?: string;
|
||||||
|
has_rating?: boolean;
|
||||||
|
starred?: boolean;
|
||||||
|
year?: number;
|
||||||
|
};
|
||||||
|
sortBy: NDAlbumListSort | JFAlbumListSort;
|
||||||
|
sortOrder: SortOrder;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type AlbumListResponse =
|
||||||
|
| BasePaginatedResponse<Album[] | NDAlbum[] | JFAlbum[]>
|
||||||
|
| null
|
||||||
|
| undefined;
|
||||||
|
|
||||||
|
export type AlbumDetailQuery = {
|
||||||
|
id: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type AlbumDetailResponse = Album | NDAlbum | JFAlbum | null | undefined;
|
||||||
|
|
||||||
|
export type Count = {
|
||||||
|
artists?: number;
|
||||||
|
externals?: number;
|
||||||
|
favorites?: number;
|
||||||
|
genres?: number;
|
||||||
|
images?: number;
|
||||||
|
ratings?: number;
|
||||||
|
songs?: number;
|
||||||
|
};
|
95
packages/renderer/src/app.tsx
Normal file
95
packages/renderer/src/app.tsx
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
|
import { MantineProvider } from '@mantine/core';
|
||||||
|
import { ModalsProvider } from '@mantine/modals';
|
||||||
|
import { NotificationsProvider } from '@mantine/notifications';
|
||||||
|
import { QueryClientProvider } from '@tanstack/react-query';
|
||||||
|
import { initSimpleImg } from 'react-simple-img';
|
||||||
|
import { BaseContextModal } from './components';
|
||||||
|
import { useTheme } from './hooks';
|
||||||
|
import { queryClient } from './lib/react-query';
|
||||||
|
import { AppRouter } from './router/app-router';
|
||||||
|
import { useSettingsStore } from './store/settings.store';
|
||||||
|
import './styles/global.scss';
|
||||||
|
import 'ag-grid-community/styles/ag-grid.css';
|
||||||
|
|
||||||
|
initSimpleImg({ threshold: 0.05 }, true);
|
||||||
|
|
||||||
|
export const App = () => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const contentFont = useSettingsStore((state) => state.general.fontContent);
|
||||||
|
const headerFont = useSettingsStore((state) => state.general.fontHeader);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const root = document.documentElement;
|
||||||
|
root.style.setProperty('--content-font-family', contentFont);
|
||||||
|
root.style.setProperty('--header-font-family', headerFont);
|
||||||
|
}, [contentFont, headerFont]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<QueryClientProvider client={queryClient}>
|
||||||
|
<MantineProvider
|
||||||
|
withGlobalStyles
|
||||||
|
withNormalizeCSS
|
||||||
|
theme={{
|
||||||
|
colorScheme: theme as 'light' | 'dark',
|
||||||
|
defaultRadius: 'xs',
|
||||||
|
dir: 'ltr',
|
||||||
|
focusRing: 'auto',
|
||||||
|
focusRingStyles: {
|
||||||
|
inputStyles: () => ({
|
||||||
|
border: '1px solid var(--primary-color)',
|
||||||
|
}),
|
||||||
|
resetStyles: () => ({ outline: 'none' }),
|
||||||
|
styles: () => ({
|
||||||
|
outline: '1px solid var(--primary-color)',
|
||||||
|
outlineOffset: '-1px',
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
fontFamily: 'var(--content-font-family)',
|
||||||
|
fontSizes: {
|
||||||
|
lg: 16,
|
||||||
|
md: 14,
|
||||||
|
sm: 13,
|
||||||
|
xl: 18,
|
||||||
|
xs: 12,
|
||||||
|
},
|
||||||
|
other: {},
|
||||||
|
spacing: {
|
||||||
|
lg: 12,
|
||||||
|
md: 8,
|
||||||
|
sm: 4,
|
||||||
|
xl: 16,
|
||||||
|
xs: 2,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<NotificationsProvider
|
||||||
|
autoClose={1500}
|
||||||
|
position="bottom-right"
|
||||||
|
style={{
|
||||||
|
marginBottom: '90px',
|
||||||
|
opacity: '.8',
|
||||||
|
userSelect: 'none',
|
||||||
|
width: '250px',
|
||||||
|
}}
|
||||||
|
transitionDuration={200}
|
||||||
|
>
|
||||||
|
<ModalsProvider
|
||||||
|
modalProps={{
|
||||||
|
centered: true,
|
||||||
|
exitTransitionDuration: 200,
|
||||||
|
overflow: 'inside',
|
||||||
|
// overlayBlur: 0,
|
||||||
|
overlayOpacity: 0.5,
|
||||||
|
transition: 'pop',
|
||||||
|
transitionDuration: 200,
|
||||||
|
}}
|
||||||
|
modals={{ base: BaseContextModal }}
|
||||||
|
>
|
||||||
|
<AppRouter />
|
||||||
|
</ModalsProvider>
|
||||||
|
</NotificationsProvider>
|
||||||
|
</MantineProvider>
|
||||||
|
</QueryClientProvider>
|
||||||
|
);
|
||||||
|
};
|
23
packages/renderer/src/components/accordion/index.tsx
Normal file
23
packages/renderer/src/components/accordion/index.tsx
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import type { AccordionProps as MantineAccordionProps } from '@mantine/core';
|
||||||
|
import { Accordion as MantineAccordion } from '@mantine/core';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
type AccordionProps = MantineAccordionProps;
|
||||||
|
|
||||||
|
const StyledAccordion = styled(MantineAccordion)`
|
||||||
|
& .mantine-Accordion-panel {
|
||||||
|
background: var(--paper-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.mantine-Accordion-control {
|
||||||
|
background: var(--paper-bg);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const Accordion = ({ children, ...props }: AccordionProps) => {
|
||||||
|
return <StyledAccordion {...props}>{children}</StyledAccordion>;
|
||||||
|
};
|
||||||
|
|
||||||
|
Accordion.Control = StyledAccordion.Control;
|
||||||
|
Accordion.Item = StyledAccordion.Item;
|
||||||
|
Accordion.Panel = StyledAccordion.Panel;
|
188
packages/renderer/src/components/audio-player/index.tsx
Normal file
188
packages/renderer/src/components/audio-player/index.tsx
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
import { useImperativeHandle, forwardRef, useRef, useState, useCallback, useEffect } from 'react';
|
||||||
|
import isElectron from 'is-electron';
|
||||||
|
import type { ReactPlayerProps } from 'react-player';
|
||||||
|
import ReactPlayer from 'react-player';
|
||||||
|
import type { Song } from '/@/api/types';
|
||||||
|
import { crossfadeHandler, gaplessHandler } from '/@/components/audio-player/utils/list-handlers';
|
||||||
|
import { useSettingsStore } from '/@/store/settings.store';
|
||||||
|
import type { CrossfadeStyle } from '/@/types';
|
||||||
|
import { PlaybackStyle, PlayerStatus } from '/@/types';
|
||||||
|
|
||||||
|
interface AudioPlayerProps extends ReactPlayerProps {
|
||||||
|
crossfadeDuration: number;
|
||||||
|
crossfadeStyle: CrossfadeStyle;
|
||||||
|
currentPlayer: 1 | 2;
|
||||||
|
playbackStyle: PlaybackStyle;
|
||||||
|
player1: Song;
|
||||||
|
player2: Song;
|
||||||
|
status: PlayerStatus;
|
||||||
|
volume: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AudioPlayerProgress = {
|
||||||
|
loaded: number;
|
||||||
|
loadedSeconds: number;
|
||||||
|
played: number;
|
||||||
|
playedSeconds: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getDuration = (ref: any) => {
|
||||||
|
return ref.current?.player?.player?.player?.duration;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const AudioPlayer = forwardRef(
|
||||||
|
(
|
||||||
|
{
|
||||||
|
status,
|
||||||
|
playbackStyle,
|
||||||
|
crossfadeStyle,
|
||||||
|
crossfadeDuration,
|
||||||
|
currentPlayer,
|
||||||
|
autoNext,
|
||||||
|
player1,
|
||||||
|
player2,
|
||||||
|
muted,
|
||||||
|
volume,
|
||||||
|
}: AudioPlayerProps,
|
||||||
|
ref: any,
|
||||||
|
) => {
|
||||||
|
const player1Ref = useRef<any>(null);
|
||||||
|
const player2Ref = useRef<any>(null);
|
||||||
|
const [isTransitioning, setIsTransitioning] = useState(false);
|
||||||
|
const audioDeviceId = useSettingsStore((state) => state.player.audioDeviceId);
|
||||||
|
|
||||||
|
useImperativeHandle(ref, () => ({
|
||||||
|
get player1() {
|
||||||
|
return player1Ref?.current;
|
||||||
|
},
|
||||||
|
get player2() {
|
||||||
|
return player2Ref?.current;
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
const handleOnEnded = () => {
|
||||||
|
autoNext();
|
||||||
|
setIsTransitioning(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (status === PlayerStatus.PLAYING) {
|
||||||
|
if (currentPlayer === 1) {
|
||||||
|
player1Ref.current?.getInternalPlayer()?.play();
|
||||||
|
} else {
|
||||||
|
player2Ref.current?.getInternalPlayer()?.play();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
player1Ref.current?.getInternalPlayer()?.pause();
|
||||||
|
player2Ref.current?.getInternalPlayer()?.pause();
|
||||||
|
}
|
||||||
|
}, [currentPlayer, status]);
|
||||||
|
|
||||||
|
const handleCrossfade1 = useCallback(
|
||||||
|
(e: AudioPlayerProgress) => {
|
||||||
|
return crossfadeHandler({
|
||||||
|
currentPlayer,
|
||||||
|
currentPlayerRef: player1Ref,
|
||||||
|
currentTime: e.playedSeconds,
|
||||||
|
duration: getDuration(player1Ref),
|
||||||
|
fadeDuration: crossfadeDuration,
|
||||||
|
fadeType: crossfadeStyle,
|
||||||
|
isTransitioning,
|
||||||
|
nextPlayerRef: player2Ref,
|
||||||
|
player: 1,
|
||||||
|
setIsTransitioning,
|
||||||
|
volume,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[crossfadeDuration, crossfadeStyle, currentPlayer, isTransitioning, volume],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleCrossfade2 = useCallback(
|
||||||
|
(e: AudioPlayerProgress) => {
|
||||||
|
return crossfadeHandler({
|
||||||
|
currentPlayer,
|
||||||
|
currentPlayerRef: player2Ref,
|
||||||
|
currentTime: e.playedSeconds,
|
||||||
|
duration: getDuration(player2Ref),
|
||||||
|
fadeDuration: crossfadeDuration,
|
||||||
|
fadeType: crossfadeStyle,
|
||||||
|
isTransitioning,
|
||||||
|
nextPlayerRef: player1Ref,
|
||||||
|
player: 2,
|
||||||
|
setIsTransitioning,
|
||||||
|
volume,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[crossfadeDuration, crossfadeStyle, currentPlayer, isTransitioning, volume],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleGapless1 = useCallback(
|
||||||
|
(e: AudioPlayerProgress) => {
|
||||||
|
return gaplessHandler({
|
||||||
|
currentTime: e.playedSeconds,
|
||||||
|
duration: getDuration(player1Ref),
|
||||||
|
isFlac: player1?.container === 'flac',
|
||||||
|
isTransitioning,
|
||||||
|
nextPlayerRef: player2Ref,
|
||||||
|
setIsTransitioning,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[isTransitioning, player1?.container],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleGapless2 = useCallback(
|
||||||
|
(e: AudioPlayerProgress) => {
|
||||||
|
return gaplessHandler({
|
||||||
|
currentTime: e.playedSeconds,
|
||||||
|
duration: getDuration(player2Ref),
|
||||||
|
isFlac: player2?.container === 'flac',
|
||||||
|
isTransitioning,
|
||||||
|
nextPlayerRef: player1Ref,
|
||||||
|
setIsTransitioning,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[isTransitioning, player2?.container],
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isElectron()) {
|
||||||
|
if (audioDeviceId) {
|
||||||
|
player1Ref.current?.getInternalPlayer()?.setSinkId(audioDeviceId);
|
||||||
|
player2Ref.current?.getInternalPlayer()?.setSinkId(audioDeviceId);
|
||||||
|
} else {
|
||||||
|
player1Ref.current?.getInternalPlayer()?.setSinkId('');
|
||||||
|
player2Ref.current?.getInternalPlayer()?.setSinkId('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [audioDeviceId]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ReactPlayer
|
||||||
|
ref={player1Ref}
|
||||||
|
height={0}
|
||||||
|
muted={muted}
|
||||||
|
playing={currentPlayer === 1 && status === PlayerStatus.PLAYING}
|
||||||
|
progressInterval={isTransitioning ? 10 : 250}
|
||||||
|
url={player1?.streamUrl}
|
||||||
|
volume={volume}
|
||||||
|
width={0}
|
||||||
|
onEnded={handleOnEnded}
|
||||||
|
onProgress={playbackStyle === PlaybackStyle.GAPLESS ? handleGapless1 : handleCrossfade1}
|
||||||
|
/>
|
||||||
|
<ReactPlayer
|
||||||
|
ref={player2Ref}
|
||||||
|
height={0}
|
||||||
|
muted={muted}
|
||||||
|
playing={currentPlayer === 2 && status === PlayerStatus.PLAYING}
|
||||||
|
progressInterval={isTransitioning ? 10 : 250}
|
||||||
|
url={player2?.streamUrl}
|
||||||
|
volume={volume}
|
||||||
|
width={0}
|
||||||
|
onEnded={handleOnEnded}
|
||||||
|
onProgress={playbackStyle === PlaybackStyle.GAPLESS ? handleGapless2 : handleCrossfade2}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
@ -0,0 +1,131 @@
|
|||||||
|
/* eslint-disable no-nested-ternary */
|
||||||
|
import type { Dispatch } from 'react';
|
||||||
|
import type { CrossfadeStyle } from '/@/types';
|
||||||
|
|
||||||
|
export const gaplessHandler = (args: {
|
||||||
|
currentTime: number;
|
||||||
|
duration: number;
|
||||||
|
isFlac: boolean;
|
||||||
|
isTransitioning: boolean;
|
||||||
|
nextPlayerRef: any;
|
||||||
|
setIsTransitioning: Dispatch<boolean>;
|
||||||
|
}) => {
|
||||||
|
const { nextPlayerRef, currentTime, duration, isTransitioning, setIsTransitioning, isFlac } =
|
||||||
|
args;
|
||||||
|
|
||||||
|
if (!isTransitioning) {
|
||||||
|
if (currentTime > duration - 2) {
|
||||||
|
return setIsTransitioning(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const durationPadding = isFlac ? 0.065 : 0.116;
|
||||||
|
if (currentTime + durationPadding >= duration) {
|
||||||
|
return nextPlayerRef.current.getInternalPlayer().play();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const crossfadeHandler = (args: {
|
||||||
|
currentPlayer: 1 | 2;
|
||||||
|
currentPlayerRef: any;
|
||||||
|
currentTime: number;
|
||||||
|
duration: number;
|
||||||
|
fadeDuration: number;
|
||||||
|
fadeType: CrossfadeStyle;
|
||||||
|
isTransitioning: boolean;
|
||||||
|
nextPlayerRef: any;
|
||||||
|
player: 1 | 2;
|
||||||
|
setIsTransitioning: Dispatch<boolean>;
|
||||||
|
volume: number;
|
||||||
|
}) => {
|
||||||
|
const {
|
||||||
|
currentTime,
|
||||||
|
player,
|
||||||
|
currentPlayer,
|
||||||
|
currentPlayerRef,
|
||||||
|
nextPlayerRef,
|
||||||
|
fadeDuration,
|
||||||
|
fadeType,
|
||||||
|
duration,
|
||||||
|
volume,
|
||||||
|
isTransitioning,
|
||||||
|
setIsTransitioning,
|
||||||
|
} = args;
|
||||||
|
|
||||||
|
if (!isTransitioning || currentPlayer !== player) {
|
||||||
|
const shouldBeginTransition = currentTime >= duration - fadeDuration;
|
||||||
|
|
||||||
|
if (shouldBeginTransition) {
|
||||||
|
setIsTransitioning(true);
|
||||||
|
return nextPlayerRef.current.getInternalPlayer().play();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const timeLeft = duration - currentTime;
|
||||||
|
let currentPlayerVolumeCalculation;
|
||||||
|
let nextPlayerVolumeCalculation;
|
||||||
|
let percentageOfFadeLeft;
|
||||||
|
let n;
|
||||||
|
switch (fadeType) {
|
||||||
|
case 'equalPower':
|
||||||
|
// https://dsp.stackexchange.com/a/14755
|
||||||
|
percentageOfFadeLeft = (timeLeft / fadeDuration) * 2;
|
||||||
|
currentPlayerVolumeCalculation = Math.sqrt(0.5 * percentageOfFadeLeft) * volume;
|
||||||
|
nextPlayerVolumeCalculation = Math.sqrt(0.5 * (2 - percentageOfFadeLeft)) * volume;
|
||||||
|
break;
|
||||||
|
case 'linear':
|
||||||
|
currentPlayerVolumeCalculation = (timeLeft / fadeDuration) * volume;
|
||||||
|
nextPlayerVolumeCalculation = ((fadeDuration - timeLeft) / fadeDuration) * volume;
|
||||||
|
break;
|
||||||
|
case 'dipped':
|
||||||
|
// https://math.stackexchange.com/a/4622
|
||||||
|
percentageOfFadeLeft = timeLeft / fadeDuration;
|
||||||
|
currentPlayerVolumeCalculation = percentageOfFadeLeft ** 2 * volume;
|
||||||
|
nextPlayerVolumeCalculation = (percentageOfFadeLeft - 1) ** 2 * volume;
|
||||||
|
break;
|
||||||
|
case fadeType.match(/constantPower.*/)?.input:
|
||||||
|
// https://math.stackexchange.com/a/26159
|
||||||
|
n =
|
||||||
|
fadeType === 'constantPower'
|
||||||
|
? 0
|
||||||
|
: fadeType === 'constantPowerSlowFade'
|
||||||
|
? 1
|
||||||
|
: fadeType === 'constantPowerSlowCut'
|
||||||
|
? 3
|
||||||
|
: 10;
|
||||||
|
|
||||||
|
percentageOfFadeLeft = timeLeft / fadeDuration;
|
||||||
|
currentPlayerVolumeCalculation =
|
||||||
|
Math.cos((Math.PI / 4) * ((2 * percentageOfFadeLeft - 1) ** (2 * n + 1) - 1)) * volume;
|
||||||
|
nextPlayerVolumeCalculation =
|
||||||
|
Math.cos((Math.PI / 4) * ((2 * percentageOfFadeLeft - 1) ** (2 * n + 1) + 1)) * volume;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
currentPlayerVolumeCalculation = (timeLeft / fadeDuration) * volume;
|
||||||
|
nextPlayerVolumeCalculation = ((fadeDuration - timeLeft) / fadeDuration) * volume;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentPlayerVolume =
|
||||||
|
currentPlayerVolumeCalculation >= 0 ? currentPlayerVolumeCalculation : 0;
|
||||||
|
|
||||||
|
const nextPlayerVolume =
|
||||||
|
nextPlayerVolumeCalculation <= volume ? nextPlayerVolumeCalculation : volume;
|
||||||
|
|
||||||
|
if (currentPlayer === 1) {
|
||||||
|
currentPlayerRef.current.getInternalPlayer().volume = currentPlayerVolume;
|
||||||
|
nextPlayerRef.current.getInternalPlayer().volume = nextPlayerVolume;
|
||||||
|
} else {
|
||||||
|
currentPlayerRef.current.getInternalPlayer().volume = currentPlayerVolume;
|
||||||
|
nextPlayerRef.current.getInternalPlayer().volume = nextPlayerVolume;
|
||||||
|
}
|
||||||
|
// }
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
287
packages/renderer/src/components/button/index.tsx
Normal file
287
packages/renderer/src/components/button/index.tsx
Normal file
@ -0,0 +1,287 @@
|
|||||||
|
import type { Ref } from 'react';
|
||||||
|
import { useRef } from 'react';
|
||||||
|
import { useCallback, useState } from 'react';
|
||||||
|
import React, { forwardRef } from 'react';
|
||||||
|
import type { ButtonProps as MantineButtonProps, TooltipProps } from '@mantine/core';
|
||||||
|
import { Button as MantineButton, createPolymorphicComponent } from '@mantine/core';
|
||||||
|
import { useTimeout } from '@mantine/hooks';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
import { Spinner } from '/@/components/spinner';
|
||||||
|
import { Tooltip } from '/@/components/tooltip';
|
||||||
|
|
||||||
|
export interface ButtonProps extends MantineButtonProps {
|
||||||
|
children: React.ReactNode;
|
||||||
|
loading?: boolean;
|
||||||
|
onClick?: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
||||||
|
onMouseDown?: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
||||||
|
tooltip?: Omit<TooltipProps, 'children'>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface StyledButtonProps extends ButtonProps {
|
||||||
|
ref: Ref<HTMLButtonElement>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const StyledButton = styled(MantineButton)<StyledButtonProps>`
|
||||||
|
color: ${(props) => {
|
||||||
|
switch (props.variant) {
|
||||||
|
case 'default':
|
||||||
|
return 'var(--btn-default-fg)';
|
||||||
|
case 'filled':
|
||||||
|
return 'var(--btn-primary-fg)';
|
||||||
|
case 'subtle':
|
||||||
|
return 'var(--btn-subtle-fg)';
|
||||||
|
default:
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
font-weight: normal;
|
||||||
|
background: ${(props) => {
|
||||||
|
switch (props.variant) {
|
||||||
|
case 'default':
|
||||||
|
return 'var(--btn-default-bg)';
|
||||||
|
case 'filled':
|
||||||
|
return 'var(--btn-primary-bg)';
|
||||||
|
case 'subtle':
|
||||||
|
return 'var(--btn-subtle-bg)';
|
||||||
|
default:
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
border: none;
|
||||||
|
transition: background 0.2s ease-in-out, color 0.2s ease-in-out;
|
||||||
|
|
||||||
|
svg {
|
||||||
|
transition: fill 0.2s ease-in-out;
|
||||||
|
fill: ${(props) => {
|
||||||
|
switch (props.variant) {
|
||||||
|
case 'default':
|
||||||
|
return 'var(--btn-default-fg)';
|
||||||
|
case 'filled':
|
||||||
|
return 'var(--btn-primary-fg)';
|
||||||
|
case 'subtle':
|
||||||
|
return 'var(--btn-subtle-fg)';
|
||||||
|
default:
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
color: ${(props) => {
|
||||||
|
switch (props.variant) {
|
||||||
|
case 'default':
|
||||||
|
return 'var(--btn-default-fg)';
|
||||||
|
case 'filled':
|
||||||
|
return 'var(--btn-primary-fg)';
|
||||||
|
case 'subtle':
|
||||||
|
return 'var(--btn-subtle-fg)';
|
||||||
|
default:
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
background: ${(props) => {
|
||||||
|
switch (props.variant) {
|
||||||
|
case 'default':
|
||||||
|
return 'var(--btn-default-bg)';
|
||||||
|
case 'filled':
|
||||||
|
return 'var(--btn-primary-bg)';
|
||||||
|
case 'subtle':
|
||||||
|
return 'var(--btn-subtle-bg)';
|
||||||
|
default:
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: ${(props) => {
|
||||||
|
switch (props.variant) {
|
||||||
|
case 'default':
|
||||||
|
return 'var(--btn-default-fg-hover)';
|
||||||
|
case 'filled':
|
||||||
|
return 'var(--btn-primary-fg-hover)';
|
||||||
|
case 'subtle':
|
||||||
|
return 'var(--btn-subtle-fg-hover)';
|
||||||
|
default:
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
background: ${(props) => {
|
||||||
|
switch (props.variant) {
|
||||||
|
case 'default':
|
||||||
|
return 'var(--btn-default-bg-hover)';
|
||||||
|
case 'filled':
|
||||||
|
return 'var(--btn-primary-bg-hover)';
|
||||||
|
case 'subtle':
|
||||||
|
return 'var(--btn-subtle-bg-hover)';
|
||||||
|
default:
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
|
||||||
|
svg {
|
||||||
|
fill: ${(props) => {
|
||||||
|
switch (props.variant) {
|
||||||
|
case 'default':
|
||||||
|
return 'var(--btn-default-fg-hover)';
|
||||||
|
case 'filled':
|
||||||
|
return 'var(--btn-primary-fg-hover)';
|
||||||
|
case 'subtle':
|
||||||
|
return 'var(--btn-subtle-fg-hover)';
|
||||||
|
default:
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&:focus-visible {
|
||||||
|
color: ${(props) => {
|
||||||
|
switch (props.variant) {
|
||||||
|
case 'default':
|
||||||
|
return 'var(--btn-default-fg-hover)';
|
||||||
|
case 'filled':
|
||||||
|
return 'var(--btn-primary-fg-hover)';
|
||||||
|
case 'subtle':
|
||||||
|
return 'var(--btn-subtle-fg-hover)';
|
||||||
|
default:
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
background: ${(props) => {
|
||||||
|
switch (props.variant) {
|
||||||
|
case 'default':
|
||||||
|
return 'var(--btn-default-bg-hover)';
|
||||||
|
case 'filled':
|
||||||
|
return 'var(--btn-primary-bg-hover)';
|
||||||
|
case 'subtle':
|
||||||
|
return 'var(--btn-subtle-bg-hover)';
|
||||||
|
default:
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
transform: scale(0.98);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-Button-centerLoader {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-Button-leftIcon {
|
||||||
|
margin-right: 0.5rem;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const ButtonChildWrapper = styled.span<{ $loading?: boolean }>`
|
||||||
|
color: ${(props) => props.$loading && 'transparent !important'};
|
||||||
|
`;
|
||||||
|
|
||||||
|
const SpinnerWrapper = styled.div`
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate3d(-50%, -50%, 0);
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const _Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
||||||
|
({ children, tooltip, ...props }: ButtonProps, ref) => {
|
||||||
|
if (tooltip) {
|
||||||
|
return (
|
||||||
|
<Tooltip
|
||||||
|
withinPortal
|
||||||
|
{...tooltip}
|
||||||
|
>
|
||||||
|
<StyledButton
|
||||||
|
ref={ref}
|
||||||
|
loaderPosition="center"
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<ButtonChildWrapper $loading={props.loading}>{children}</ButtonChildWrapper>
|
||||||
|
{props.loading && (
|
||||||
|
<SpinnerWrapper>
|
||||||
|
<Spinner />
|
||||||
|
</SpinnerWrapper>
|
||||||
|
)}
|
||||||
|
</StyledButton>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<StyledButton
|
||||||
|
ref={ref}
|
||||||
|
loaderPosition="center"
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<ButtonChildWrapper $loading={props.loading}>{children}</ButtonChildWrapper>
|
||||||
|
{props.loading && (
|
||||||
|
<SpinnerWrapper>
|
||||||
|
<Spinner />
|
||||||
|
</SpinnerWrapper>
|
||||||
|
)}
|
||||||
|
</StyledButton>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export const Button = createPolymorphicComponent<'button', ButtonProps>(_Button);
|
||||||
|
|
||||||
|
_Button.defaultProps = {
|
||||||
|
loading: undefined,
|
||||||
|
onClick: undefined,
|
||||||
|
tooltip: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
interface HoldButtonProps extends ButtonProps {
|
||||||
|
timeoutProps: {
|
||||||
|
callback: () => void;
|
||||||
|
duration: number;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TimeoutButton = ({ timeoutProps, ...props }: HoldButtonProps) => {
|
||||||
|
const [_timeoutRemaining, setTimeoutRemaining] = useState(timeoutProps.duration);
|
||||||
|
const [isRunning, setIsRunning] = useState(false);
|
||||||
|
const intervalRef = useRef(0);
|
||||||
|
|
||||||
|
const callback = () => {
|
||||||
|
timeoutProps.callback();
|
||||||
|
setTimeoutRemaining(timeoutProps.duration);
|
||||||
|
clearInterval(intervalRef.current);
|
||||||
|
setIsRunning(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const { start, clear } = useTimeout(callback, timeoutProps.duration);
|
||||||
|
|
||||||
|
const startTimeout = useCallback(() => {
|
||||||
|
if (isRunning) {
|
||||||
|
clearInterval(intervalRef.current);
|
||||||
|
setIsRunning(false);
|
||||||
|
clear();
|
||||||
|
} else {
|
||||||
|
setIsRunning(true);
|
||||||
|
start();
|
||||||
|
|
||||||
|
const intervalId = window.setInterval(() => {
|
||||||
|
setTimeoutRemaining((prev) => prev - 100);
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
intervalRef.current = intervalId;
|
||||||
|
}
|
||||||
|
}, [clear, isRunning, start]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<_Button
|
||||||
|
sx={{ color: 'var(--danger-color)' }}
|
||||||
|
onClick={startTimeout}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{isRunning ? 'Cancel' : props.children}
|
||||||
|
</_Button>
|
||||||
|
);
|
||||||
|
};
|
50
packages/renderer/src/components/date-picker/index.tsx
Normal file
50
packages/renderer/src/components/date-picker/index.tsx
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import type { DatePickerProps as MantineDatePickerProps } from '@mantine/dates';
|
||||||
|
import { DatePicker as MantineDatePicker } from '@mantine/dates';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
interface DatePickerProps extends MantineDatePickerProps {
|
||||||
|
maxWidth?: number | string;
|
||||||
|
width?: number | string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const StyledDatePicker = styled(MantineDatePicker)<DatePickerProps>`
|
||||||
|
& .mantine-DatePicker-input {
|
||||||
|
color: var(--input-fg);
|
||||||
|
background: var(--input-bg);
|
||||||
|
|
||||||
|
&::placeholder {
|
||||||
|
color: var(--input-placeholder-fg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-DatePicker-icon {
|
||||||
|
color: var(--input-placeholder-fg);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-DatePicker-required {
|
||||||
|
color: var(--secondary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-DatePicker-label {
|
||||||
|
font-family: var(--label-font-faimly);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-DateRangePicker-disabled {
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const DatePicker = ({ width, maxWidth, ...props }: DatePickerProps) => {
|
||||||
|
return (
|
||||||
|
<StyledDatePicker
|
||||||
|
withinPortal
|
||||||
|
{...props}
|
||||||
|
sx={{ maxWidth, width }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
DatePicker.defaultProps = {
|
||||||
|
maxWidth: undefined,
|
||||||
|
width: undefined,
|
||||||
|
};
|
114
packages/renderer/src/components/dropdown-menu/index.tsx
Normal file
114
packages/renderer/src/components/dropdown-menu/index.tsx
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
import type {
|
||||||
|
MenuProps as MantineMenuProps,
|
||||||
|
MenuItemProps as MantineMenuItemProps,
|
||||||
|
MenuLabelProps as MantineMenuLabelProps,
|
||||||
|
MenuDividerProps as MantineMenuDividerProps,
|
||||||
|
MenuDropdownProps as MantineMenuDropdownProps,
|
||||||
|
} from '@mantine/core';
|
||||||
|
import { Menu as MantineMenu, createPolymorphicComponent } from '@mantine/core';
|
||||||
|
import { RiArrowLeftLine } from 'react-icons/ri';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
type MenuProps = MantineMenuProps;
|
||||||
|
type MenuLabelProps = MantineMenuLabelProps;
|
||||||
|
interface MenuItemProps extends MantineMenuItemProps {
|
||||||
|
$isActive?: boolean;
|
||||||
|
children: React.ReactNode;
|
||||||
|
}
|
||||||
|
type MenuDividerProps = MantineMenuDividerProps;
|
||||||
|
type MenuDropdownProps = MantineMenuDropdownProps;
|
||||||
|
|
||||||
|
const StyledMenu = styled(MantineMenu)<MenuProps>``;
|
||||||
|
|
||||||
|
const StyledMenuLabel = styled(MantineMenu.Label)<MenuLabelProps>`
|
||||||
|
font-family: var(--content-font-family);
|
||||||
|
`;
|
||||||
|
|
||||||
|
const StyledMenuItem = styled(MantineMenu.Item)<MenuItemProps>`
|
||||||
|
padding: 0.8rem;
|
||||||
|
font-size: 0.9em;
|
||||||
|
font-family: var(--content-font-family);
|
||||||
|
background-color: var(--dropdown-menu-bg);
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: var(--dropdown-menu-bg-hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-Menu-itemIcon {
|
||||||
|
margin-right: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-Menu-itemLabel {
|
||||||
|
color: ${({ $isActive }) => ($isActive ? 'var(--primary-color)' : 'var(--dropdown-menu-fg)')};
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-Menu-itemRightSection {
|
||||||
|
margin-left: 2rem !important;
|
||||||
|
color: ${({ $isActive }) => ($isActive ? 'var(--primary-color)' : 'var(--dropdown-menu-fg)')};
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const StyledMenuDropdown = styled(MantineMenu.Dropdown)`
|
||||||
|
background: var(--dropdown-menu-bg);
|
||||||
|
border: var(--dropdown-menu-border);
|
||||||
|
border-radius: var(--dropdown-menu-border-radius);
|
||||||
|
filter: drop-shadow(0 0 5px rgb(0, 0, 0, 50%));
|
||||||
|
`;
|
||||||
|
|
||||||
|
const StyledMenuDivider = styled(MantineMenu.Divider)`
|
||||||
|
margin: 0.3rem 0;
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const DropdownMenu = ({ children, ...props }: MenuProps) => {
|
||||||
|
return (
|
||||||
|
<StyledMenu
|
||||||
|
withinPortal
|
||||||
|
radius="sm"
|
||||||
|
styles={{
|
||||||
|
dropdown: { filter: 'drop-shadow(0 0 5px rgb(0, 0, 0, 50%))' },
|
||||||
|
}}
|
||||||
|
transition="scale"
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</StyledMenu>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const MenuLabel = ({ children, ...props }: MenuLabelProps) => {
|
||||||
|
return <StyledMenuLabel {...props}>{children}</StyledMenuLabel>;
|
||||||
|
};
|
||||||
|
|
||||||
|
const pMenuItem = ({ $isActive, children, ...props }: MenuItemProps) => {
|
||||||
|
return (
|
||||||
|
<StyledMenuItem
|
||||||
|
$isActive={$isActive}
|
||||||
|
rightSection={$isActive && <RiArrowLeftLine />}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</StyledMenuItem>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const MenuDropdown = ({ children, ...props }: MenuDropdownProps) => {
|
||||||
|
return <StyledMenuDropdown {...props}>{children}</StyledMenuDropdown>;
|
||||||
|
};
|
||||||
|
|
||||||
|
const MenuItem = createPolymorphicComponent<'button', MenuItemProps>(pMenuItem);
|
||||||
|
|
||||||
|
const MenuDivider = ({ ...props }: MenuDividerProps) => {
|
||||||
|
return <StyledMenuDivider {...props} />;
|
||||||
|
};
|
||||||
|
|
||||||
|
DropdownMenu.Label = MenuLabel;
|
||||||
|
DropdownMenu.Item = MenuItem;
|
||||||
|
DropdownMenu.Target = MantineMenu.Target;
|
||||||
|
DropdownMenu.Dropdown = MenuDropdown;
|
||||||
|
DropdownMenu.Divider = MenuDivider;
|
33
packages/renderer/src/components/dropzone/index.tsx
Normal file
33
packages/renderer/src/components/dropzone/index.tsx
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import type { DropzoneProps as MantineDropzoneProps } from '@mantine/dropzone';
|
||||||
|
import { Dropzone as MantineDropzone } from '@mantine/dropzone';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
export type DropzoneProps = MantineDropzoneProps;
|
||||||
|
|
||||||
|
const StyledDropzone = styled(MantineDropzone)`
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background: var(--input-bg);
|
||||||
|
border-radius: 5px;
|
||||||
|
opacity: 0.8;
|
||||||
|
transition: opacity 0.2s ease;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: var(--input-bg);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-Dropzone-inner {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const Dropzone = ({ children, ...props }: DropzoneProps) => {
|
||||||
|
return <StyledDropzone {...props}>{children}</StyledDropzone>;
|
||||||
|
};
|
||||||
|
|
||||||
|
Dropzone.Accept = StyledDropzone.Accept;
|
||||||
|
Dropzone.Idle = StyledDropzone.Idle;
|
||||||
|
Dropzone.Reject = StyledDropzone.Reject;
|
23
packages/renderer/src/components/index.ts
Normal file
23
packages/renderer/src/components/index.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
export * from './tooltip';
|
||||||
|
export * from './audio-player';
|
||||||
|
export * from './text';
|
||||||
|
export * from './button';
|
||||||
|
export * from './virtual-grid';
|
||||||
|
export * from './modal';
|
||||||
|
export * from './input';
|
||||||
|
export * from './segmented-control';
|
||||||
|
export * from './dropdown-menu';
|
||||||
|
export * from './toast';
|
||||||
|
export * from './switch';
|
||||||
|
export * from './popover';
|
||||||
|
export * from './select';
|
||||||
|
export * from './date-picker';
|
||||||
|
export * from './scroll-area';
|
||||||
|
export * from './paper';
|
||||||
|
export * from './tabs';
|
||||||
|
export * from './slider';
|
||||||
|
export * from './accordion';
|
||||||
|
export * from './dropzone';
|
||||||
|
export * from './spinner';
|
||||||
|
export * from './virtual-table';
|
||||||
|
export * from './skeleton';
|
364
packages/renderer/src/components/input/index.tsx
Normal file
364
packages/renderer/src/components/input/index.tsx
Normal file
@ -0,0 +1,364 @@
|
|||||||
|
import React, { forwardRef } from 'react';
|
||||||
|
import type {
|
||||||
|
TextInputProps as MantineTextInputProps,
|
||||||
|
NumberInputProps as MantineNumberInputProps,
|
||||||
|
PasswordInputProps as MantinePasswordInputProps,
|
||||||
|
FileInputProps as MantineFileInputProps,
|
||||||
|
JsonInputProps as MantineJsonInputProps,
|
||||||
|
TextareaProps as MantineTextareaProps,
|
||||||
|
} from '@mantine/core';
|
||||||
|
import {
|
||||||
|
TextInput as MantineTextInput,
|
||||||
|
NumberInput as MantineNumberInput,
|
||||||
|
PasswordInput as MantinePasswordInput,
|
||||||
|
FileInput as MantineFileInput,
|
||||||
|
JsonInput as MantineJsonInput,
|
||||||
|
Textarea as MantineTextarea,
|
||||||
|
} from '@mantine/core';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
interface TextInputProps extends MantineTextInputProps {
|
||||||
|
children?: React.ReactNode;
|
||||||
|
maxWidth?: number | string;
|
||||||
|
width?: number | string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface NumberInputProps extends MantineNumberInputProps {
|
||||||
|
children?: React.ReactNode;
|
||||||
|
maxWidth?: number | string;
|
||||||
|
width?: number | string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PasswordInputProps extends MantinePasswordInputProps {
|
||||||
|
children?: React.ReactNode;
|
||||||
|
maxWidth?: number | string;
|
||||||
|
width?: number | string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FileInputProps extends MantineFileInputProps {
|
||||||
|
children?: React.ReactNode;
|
||||||
|
maxWidth?: number | string;
|
||||||
|
width?: number | string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface JsonInputProps extends MantineJsonInputProps {
|
||||||
|
children?: React.ReactNode;
|
||||||
|
maxWidth?: number | string;
|
||||||
|
width?: number | string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TextareaProps extends MantineTextareaProps {
|
||||||
|
children?: React.ReactNode;
|
||||||
|
maxWidth?: number | string;
|
||||||
|
width?: number | string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const StyledTextInput = styled(MantineTextInput)<TextInputProps>`
|
||||||
|
& .mantine-TextInput-wrapper {
|
||||||
|
border-color: var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-TextInput-input {
|
||||||
|
color: var(--input-fg);
|
||||||
|
background: var(--input-bg);
|
||||||
|
|
||||||
|
&::placeholder {
|
||||||
|
color: var(--input-placeholder-fg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-Input-icon {
|
||||||
|
color: var(--input-placeholder-fg);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-TextInput-required {
|
||||||
|
color: var(--secondary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-TextInput-label {
|
||||||
|
font-family: var(--label-font-faimly);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-TextInput-disabled {
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const StyledNumberInput = styled(MantineNumberInput)<NumberInputProps>`
|
||||||
|
& .mantine-NumberInput-wrapper {
|
||||||
|
border-color: var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-NumberInput-input {
|
||||||
|
color: var(--input-fg);
|
||||||
|
background: var(--input-bg);
|
||||||
|
|
||||||
|
&::placeholder {
|
||||||
|
color: var(--input-placeholder-fg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* & .mantine-NumberInput-rightSection {
|
||||||
|
color: var(--input-placeholder-fg);
|
||||||
|
background: var(--input-bg);
|
||||||
|
} */
|
||||||
|
|
||||||
|
& .mantine-NumberInput-controlUp {
|
||||||
|
svg {
|
||||||
|
color: white;
|
||||||
|
fill: white;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-Input-icon {
|
||||||
|
color: var(--input-placeholder-fg);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-NumberInput-required {
|
||||||
|
color: var(--secondary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-NumberInput-label {
|
||||||
|
font-family: var(--label-font-faimly);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-NumberInput-disabled {
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const StyledPasswordInput = styled(MantinePasswordInput)<PasswordInputProps>`
|
||||||
|
& .mantine-PasswordInput-input {
|
||||||
|
color: var(--input-fg);
|
||||||
|
background: var(--input-bg);
|
||||||
|
|
||||||
|
&::placeholder {
|
||||||
|
color: var(--input-placeholder-fg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-PasswordInput-icon {
|
||||||
|
color: var(--input-placeholder-fg);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-PasswordInput-required {
|
||||||
|
color: var(--secondary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-PasswordInput-label {
|
||||||
|
font-family: var(--label-font-faimly);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-PasswordInput-disabled {
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const StyledFileInput = styled(MantineFileInput)<FileInputProps>`
|
||||||
|
& .mantine-FileInput-input {
|
||||||
|
color: var(--input-fg);
|
||||||
|
background: var(--input-bg);
|
||||||
|
|
||||||
|
&::placeholder {
|
||||||
|
color: var(--input-placeholder-fg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-FileInput-icon {
|
||||||
|
color: var(--input-placeholder-fg);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-FileInput-required {
|
||||||
|
color: var(--secondary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-FileInput-label {
|
||||||
|
font-family: var(--label-font-faimly);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-FileInput-disabled {
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const StyledJsonInput = styled(MantineJsonInput)<JsonInputProps>`
|
||||||
|
& .mantine-JsonInput-input {
|
||||||
|
color: var(--input-fg);
|
||||||
|
background: var(--input-bg);
|
||||||
|
|
||||||
|
&::placeholder {
|
||||||
|
color: var(--input-placeholder-fg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-JsonInput-icon {
|
||||||
|
color: var(--input-placeholder-fg);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-JsonInput-required {
|
||||||
|
color: var(--secondary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-JsonInput-label {
|
||||||
|
font-family: var(--label-font-faimly);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-JsonInput-disabled {
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const StyledTextarea = styled(MantineTextarea)<TextareaProps>`
|
||||||
|
& .mantine-Textarea-input {
|
||||||
|
color: var(--input-fg);
|
||||||
|
background: var(--input-bg);
|
||||||
|
|
||||||
|
&::placeholder {
|
||||||
|
color: var(--input-placeholder-fg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-Textarea-icon {
|
||||||
|
color: var(--input-placeholder-fg);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-Textarea-required {
|
||||||
|
color: var(--secondary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-Textarea-label {
|
||||||
|
font-family: var(--label-font-faimly);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-Textarea-disabled {
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const TextInput = forwardRef<HTMLInputElement, TextInputProps>(
|
||||||
|
({ children, width, maxWidth, ...props }: TextInputProps, ref) => {
|
||||||
|
return (
|
||||||
|
<StyledTextInput
|
||||||
|
ref={ref}
|
||||||
|
spellCheck={false}
|
||||||
|
{...props}
|
||||||
|
sx={{ maxWidth, width }}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</StyledTextInput>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export const NumberInput = forwardRef<HTMLInputElement, NumberInputProps>(
|
||||||
|
({ children, width, maxWidth, ...props }: NumberInputProps, ref) => {
|
||||||
|
return (
|
||||||
|
<StyledNumberInput
|
||||||
|
ref={ref}
|
||||||
|
hideControls
|
||||||
|
spellCheck={false}
|
||||||
|
{...props}
|
||||||
|
sx={{ maxWidth, width }}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</StyledNumberInput>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export const PasswordInput = forwardRef<HTMLInputElement, PasswordInputProps>(
|
||||||
|
({ children, width, maxWidth, ...props }: PasswordInputProps, ref) => {
|
||||||
|
return (
|
||||||
|
<StyledPasswordInput
|
||||||
|
ref={ref}
|
||||||
|
{...props}
|
||||||
|
sx={{ maxWidth, width }}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</StyledPasswordInput>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export const FileInput = forwardRef<HTMLButtonElement, FileInputProps>(
|
||||||
|
({ children, width, maxWidth, ...props }: FileInputProps, ref) => {
|
||||||
|
return (
|
||||||
|
<StyledFileInput
|
||||||
|
ref={ref}
|
||||||
|
{...props}
|
||||||
|
styles={{
|
||||||
|
placeholder: {
|
||||||
|
color: 'var(--input-placeholder-fg)',
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
sx={{ maxWidth, width }}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</StyledFileInput>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export const JsonInput = forwardRef<HTMLTextAreaElement, JsonInputProps>(
|
||||||
|
({ children, width, maxWidth, ...props }: JsonInputProps, ref) => {
|
||||||
|
return (
|
||||||
|
<StyledJsonInput
|
||||||
|
ref={ref}
|
||||||
|
{...props}
|
||||||
|
sx={{ maxWidth, width }}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</StyledJsonInput>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
|
||||||
|
({ children, width, maxWidth, ...props }: TextareaProps, ref) => {
|
||||||
|
return (
|
||||||
|
<StyledTextarea
|
||||||
|
ref={ref}
|
||||||
|
{...props}
|
||||||
|
sx={{ maxWidth, width }}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</StyledTextarea>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
TextInput.defaultProps = {
|
||||||
|
children: undefined,
|
||||||
|
maxWidth: undefined,
|
||||||
|
width: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
NumberInput.defaultProps = {
|
||||||
|
children: undefined,
|
||||||
|
maxWidth: undefined,
|
||||||
|
width: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
PasswordInput.defaultProps = {
|
||||||
|
children: undefined,
|
||||||
|
maxWidth: undefined,
|
||||||
|
width: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
FileInput.defaultProps = {
|
||||||
|
children: undefined,
|
||||||
|
maxWidth: undefined,
|
||||||
|
width: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
JsonInput.defaultProps = {
|
||||||
|
children: undefined,
|
||||||
|
maxWidth: undefined,
|
||||||
|
width: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
Textarea.defaultProps = {
|
||||||
|
children: undefined,
|
||||||
|
maxWidth: undefined,
|
||||||
|
width: undefined,
|
||||||
|
};
|
43
packages/renderer/src/components/modal/index.tsx
Normal file
43
packages/renderer/src/components/modal/index.tsx
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import type { ModalProps as MantineModalProps } from '@mantine/core';
|
||||||
|
import { Modal as MantineModal } from '@mantine/core';
|
||||||
|
import type { ContextModalProps } from '@mantine/modals';
|
||||||
|
|
||||||
|
export interface ModalProps extends Omit<MantineModalProps, 'onClose'> {
|
||||||
|
children?: React.ReactNode;
|
||||||
|
handlers: {
|
||||||
|
close: () => void;
|
||||||
|
open: () => void;
|
||||||
|
toggle: () => void;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Modal = ({ children, handlers, ...rest }: ModalProps) => {
|
||||||
|
return (
|
||||||
|
<MantineModal
|
||||||
|
overlayBlur={2}
|
||||||
|
overlayOpacity={0.2}
|
||||||
|
{...rest}
|
||||||
|
onClose={handlers.close}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</MantineModal>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ContextModalVars = {
|
||||||
|
context: ContextModalProps['context'];
|
||||||
|
id: ContextModalProps['id'];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const BaseContextModal = ({
|
||||||
|
context,
|
||||||
|
id,
|
||||||
|
innerProps,
|
||||||
|
}: ContextModalProps<{
|
||||||
|
modalBody: (vars: ContextModalVars) => React.ReactNode;
|
||||||
|
}>) => <>{innerProps.modalBody({ context, id })}</>;
|
||||||
|
|
||||||
|
Modal.defaultProps = {
|
||||||
|
children: undefined,
|
||||||
|
};
|
15
packages/renderer/src/components/paper/index.tsx
Normal file
15
packages/renderer/src/components/paper/index.tsx
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import type { PaperProps as MantinePaperProps } from '@mantine/core';
|
||||||
|
import { Paper as MantinePaper } from '@mantine/core';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
export interface PaperProps extends MantinePaperProps {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
const StyledPaper = styled(MantinePaper)<PaperProps>`
|
||||||
|
background: var(--paper-bg);
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const Paper = ({ children, ...props }: PaperProps) => {
|
||||||
|
return <StyledPaper {...props}>{children}</StyledPaper>;
|
||||||
|
};
|
38
packages/renderer/src/components/popover/index.tsx
Normal file
38
packages/renderer/src/components/popover/index.tsx
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import type {
|
||||||
|
PopoverProps as MantinePopoverProps,
|
||||||
|
PopoverDropdownProps as MantinePopoverDropdownProps,
|
||||||
|
} from '@mantine/core';
|
||||||
|
import { Popover as MantinePopover } from '@mantine/core';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
type PopoverProps = MantinePopoverProps;
|
||||||
|
type PopoverDropdownProps = MantinePopoverDropdownProps;
|
||||||
|
|
||||||
|
const StyledPopover = styled(MantinePopover)``;
|
||||||
|
|
||||||
|
const StyledDropdown = styled(MantinePopover.Dropdown)<PopoverDropdownProps>`
|
||||||
|
padding: 0.5rem;
|
||||||
|
font-size: 0.9em;
|
||||||
|
font-family: var(--content-font-family);
|
||||||
|
background-color: var(--dropdown-menu-bg);
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const Popover = ({ children, ...props }: PopoverProps) => {
|
||||||
|
return (
|
||||||
|
<StyledPopover
|
||||||
|
withArrow
|
||||||
|
withinPortal
|
||||||
|
styles={{
|
||||||
|
dropdown: {
|
||||||
|
filter: 'drop-shadow(0 0 5px rgb(0, 0, 0, 50%))',
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</StyledPopover>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
Popover.Target = MantinePopover.Target;
|
||||||
|
Popover.Dropdown = StyledDropdown;
|
31
packages/renderer/src/components/scroll-area/index.tsx
Normal file
31
packages/renderer/src/components/scroll-area/index.tsx
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import type { ScrollAreaProps as MantineScrollAreaProps } from '@mantine/core';
|
||||||
|
import { ScrollArea as MantineScrollArea } from '@mantine/core';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
interface ScrollAreaProps extends MantineScrollAreaProps {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
const StyledScrollArea = styled(MantineScrollArea)`
|
||||||
|
& .mantine-ScrollArea-thumb {
|
||||||
|
background: var(--scrollbar-thumb-bg);
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-ScrollArea-scrollbar {
|
||||||
|
width: 8px;
|
||||||
|
padding: 0;
|
||||||
|
background: var(--scrollbar-track-bg);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const ScrollArea = ({ children, ...props }: ScrollAreaProps) => {
|
||||||
|
return (
|
||||||
|
<StyledScrollArea
|
||||||
|
offsetScrollbars
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</StyledScrollArea>
|
||||||
|
);
|
||||||
|
};
|
38
packages/renderer/src/components/segmented-control/index.tsx
Normal file
38
packages/renderer/src/components/segmented-control/index.tsx
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import { forwardRef } from 'react';
|
||||||
|
import type { SegmentedControlProps as MantineSegmentedControlProps } from '@mantine/core';
|
||||||
|
import { SegmentedControl as MantineSegmentedControl } from '@mantine/core';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
type SegmentedControlProps = MantineSegmentedControlProps;
|
||||||
|
|
||||||
|
const StyledSegmentedControl = styled(MantineSegmentedControl)<MantineSegmentedControlProps>`
|
||||||
|
& .mantine-SegmentedControl-label {
|
||||||
|
color: var(--input-fg);
|
||||||
|
font-family: var(--content-font-family);
|
||||||
|
}
|
||||||
|
|
||||||
|
background-color: var(--input-bg);
|
||||||
|
|
||||||
|
& .mantine-SegmentedControl-disabled {
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-SegmentedControl-active {
|
||||||
|
color: var(--input-active-fg);
|
||||||
|
background-color: var(--input-active-bg);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const SegmentedControl = forwardRef<HTMLDivElement, SegmentedControlProps>(
|
||||||
|
({ ...props }: SegmentedControlProps, ref) => {
|
||||||
|
return (
|
||||||
|
<StyledSegmentedControl
|
||||||
|
ref={ref}
|
||||||
|
styles={{}}
|
||||||
|
transitionDuration={250}
|
||||||
|
transitionTimingFunction="linear"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
147
packages/renderer/src/components/select/index.tsx
Normal file
147
packages/renderer/src/components/select/index.tsx
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
import type {
|
||||||
|
SelectProps as MantineSelectProps,
|
||||||
|
MultiSelectProps as MantineMultiSelectProps,
|
||||||
|
} from '@mantine/core';
|
||||||
|
import { Select as MantineSelect, MultiSelect as MantineMultiSelect } from '@mantine/core';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
interface SelectProps extends MantineSelectProps {
|
||||||
|
maxWidth?: number | string;
|
||||||
|
width?: number | string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MultiSelectProps extends MantineMultiSelectProps {
|
||||||
|
maxWidth?: number | string;
|
||||||
|
width?: number | string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const StyledSelect = styled(MantineSelect)`
|
||||||
|
& [data-selected='true'] {
|
||||||
|
background: var(--input-select-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-Select-disabled {
|
||||||
|
background: var(--input-select-bg);
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-Select-itemsWrapper {
|
||||||
|
& .mantine-Select-item {
|
||||||
|
padding: 40px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const Select = ({ width, maxWidth, ...props }: SelectProps) => {
|
||||||
|
return (
|
||||||
|
<StyledSelect
|
||||||
|
withinPortal
|
||||||
|
styles={{
|
||||||
|
dropdown: {
|
||||||
|
background: 'var(--dropdown-menu-bg)',
|
||||||
|
filter: 'drop-shadow(0 0 5px rgb(0, 0, 0, 20%))',
|
||||||
|
},
|
||||||
|
input: {
|
||||||
|
background: 'var(--input-bg)',
|
||||||
|
color: 'var(--input-fg)',
|
||||||
|
},
|
||||||
|
item: {
|
||||||
|
'&:hover': {
|
||||||
|
background: 'var(--dropdown-menu-bg-hover)',
|
||||||
|
},
|
||||||
|
'&[data-hovered]': {
|
||||||
|
background: 'var(--dropdown-menu-bg-hover)',
|
||||||
|
},
|
||||||
|
'&[data-selected="true"]': {
|
||||||
|
'&:hover': {
|
||||||
|
background: 'var(--dropdown-menu-bg-hover)',
|
||||||
|
},
|
||||||
|
background: 'none',
|
||||||
|
color: 'var(--primary-color)',
|
||||||
|
},
|
||||||
|
color: 'var(--dropdown-menu-fg)',
|
||||||
|
padding: '.3rem',
|
||||||
|
},
|
||||||
|
itemsWrapper: {
|
||||||
|
background: 'var(--dropdown-menu-bg)',
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
sx={{ maxWidth, width }}
|
||||||
|
transition="pop"
|
||||||
|
transitionDuration={100}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const StyledMultiSelect = styled(MantineMultiSelect)`
|
||||||
|
& [data-selected='true'] {
|
||||||
|
background: var(--input-select-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-MultiSelect-disabled {
|
||||||
|
background: var(--input-select-bg);
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-MultiSelect-itemsWrapper {
|
||||||
|
& .mantine-Select-item {
|
||||||
|
padding: 40px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const MultiSelect = ({ width, maxWidth, ...props }: MultiSelectProps) => {
|
||||||
|
return (
|
||||||
|
<StyledMultiSelect
|
||||||
|
withinPortal
|
||||||
|
styles={{
|
||||||
|
dropdown: {
|
||||||
|
background: 'var(--dropdown-menu-bg)',
|
||||||
|
filter: 'drop-shadow(0 0 5px rgb(0, 0, 0, 20%))',
|
||||||
|
},
|
||||||
|
input: {
|
||||||
|
background: 'var(--input-bg)',
|
||||||
|
color: 'var(--input-fg)',
|
||||||
|
},
|
||||||
|
item: {
|
||||||
|
'&:hover': {
|
||||||
|
background: 'var(--dropdown-menu-bg-hover)',
|
||||||
|
},
|
||||||
|
'&[data-hovered]': {
|
||||||
|
background: 'var(--dropdown-menu-bg-hover)',
|
||||||
|
},
|
||||||
|
'&[data-selected="true"]': {
|
||||||
|
'&:hover': {
|
||||||
|
background: 'var(--dropdown-menu-bg-hover)',
|
||||||
|
},
|
||||||
|
background: 'none',
|
||||||
|
color: 'var(--primary-color)',
|
||||||
|
},
|
||||||
|
color: 'var(--dropdown-menu-fg)',
|
||||||
|
padding: '.5rem .1rem',
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
margin: '.2rem',
|
||||||
|
paddingBottom: '1rem',
|
||||||
|
paddingLeft: '1rem',
|
||||||
|
paddingTop: '1rem',
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
sx={{ maxWidth, width }}
|
||||||
|
transition="pop"
|
||||||
|
transitionDuration={100}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
Select.defaultProps = {
|
||||||
|
maxWidth: undefined,
|
||||||
|
width: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
MultiSelect.defaultProps = {
|
||||||
|
maxWidth: undefined,
|
||||||
|
width: undefined,
|
||||||
|
};
|
39
packages/renderer/src/components/skeleton/index.tsx
Normal file
39
packages/renderer/src/components/skeleton/index.tsx
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import type { SkeletonProps as MantineSkeletonProps } from '@mantine/core';
|
||||||
|
import { Skeleton as MantineSkeleton } from '@mantine/core';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
const StyledSkeleton = styled(MantineSkeleton)`
|
||||||
|
@keyframes run {
|
||||||
|
0% {
|
||||||
|
left: 0;
|
||||||
|
transform: translateX(-100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
80% {
|
||||||
|
transform: translateX(100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
transform: translateX(100%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
background: var(--skeleton-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
position: absolute;
|
||||||
|
background: linear-gradient(90deg, transparent, var(--skeleton-bg), transparent);
|
||||||
|
transform: translateX(-100%);
|
||||||
|
animation-name: run;
|
||||||
|
animation-duration: 1.5s;
|
||||||
|
animation-timing-function: linear;
|
||||||
|
content: '';
|
||||||
|
inset: 0;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const Skeleton = ({ ...props }: MantineSkeletonProps) => {
|
||||||
|
return <StyledSkeleton {...props} />;
|
||||||
|
};
|
30
packages/renderer/src/components/slider/index.tsx
Normal file
30
packages/renderer/src/components/slider/index.tsx
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import type { SliderProps as MantineSliderProps } from '@mantine/core';
|
||||||
|
import { Slider as MantineSlider } from '@mantine/core';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
type SliderProps = MantineSliderProps;
|
||||||
|
|
||||||
|
const StyledSlider = styled(MantineSlider)`
|
||||||
|
& .mantine-Slider-track {
|
||||||
|
height: 0.5rem;
|
||||||
|
background-color: var(--slider-track-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-Slider-thumb {
|
||||||
|
width: 1rem;
|
||||||
|
height: 1rem;
|
||||||
|
background: var(--slider-thumb-bg);
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-Slider-label {
|
||||||
|
padding: 0 1rem;
|
||||||
|
color: var(--tooltip-fg);
|
||||||
|
font-size: 1em;
|
||||||
|
background: var(--tooltip-bg);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const Slider = ({ ...props }: SliderProps) => {
|
||||||
|
return <StyledSlider {...props} />;
|
||||||
|
};
|
23
packages/renderer/src/components/spinner/index.tsx
Normal file
23
packages/renderer/src/components/spinner/index.tsx
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import type { IconType } from 'react-icons';
|
||||||
|
import { RiLoader5Fill } from 'react-icons/ri';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
import { rotating } from '/@/styles';
|
||||||
|
|
||||||
|
interface SpinnerProps extends IconType {
|
||||||
|
color?: string;
|
||||||
|
size?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SpinnerIcon = styled(RiLoader5Fill)`
|
||||||
|
${rotating}
|
||||||
|
animation: rotating 1s ease-in-out infinite;
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const Spinner = ({ ...props }: SpinnerProps) => {
|
||||||
|
return <SpinnerIcon {...props} />;
|
||||||
|
};
|
||||||
|
|
||||||
|
Spinner.defaultProps = {
|
||||||
|
color: undefined,
|
||||||
|
size: 15,
|
||||||
|
};
|
27
packages/renderer/src/components/switch/index.tsx
Normal file
27
packages/renderer/src/components/switch/index.tsx
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import type { SwitchProps as MantineSwitchProps } from '@mantine/core';
|
||||||
|
import { Switch as MantineSwitch } from '@mantine/core';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
type SwitchProps = MantineSwitchProps;
|
||||||
|
|
||||||
|
const StyledSwitch = styled(MantineSwitch)`
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
& .mantine-Switch-track {
|
||||||
|
background-color: var(--switch-track-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-Switch-input {
|
||||||
|
&:checked + .mantine-Switch-track {
|
||||||
|
background-color: var(--switch-track-enabled-bg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-Switch-thumb {
|
||||||
|
background-color: var(--switch-thumb-bg);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const Switch = ({ ...props }: SwitchProps) => {
|
||||||
|
return <StyledSwitch {...props} />;
|
||||||
|
};
|
52
packages/renderer/src/components/tabs/index.tsx
Normal file
52
packages/renderer/src/components/tabs/index.tsx
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import type { TabsProps as MantineTabsProps } from '@mantine/core';
|
||||||
|
import { Tabs as MantineTabs } from '@mantine/core';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
type TabsProps = MantineTabsProps;
|
||||||
|
|
||||||
|
const StyledTabs = styled(MantineTabs)`
|
||||||
|
height: 100%;
|
||||||
|
|
||||||
|
& .mantine-Tabs-tabsList {
|
||||||
|
padding-right: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.mantine-Tabs-tab {
|
||||||
|
background-color: var(--main-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .mantine-Tabs-panel {
|
||||||
|
padding: 0 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
padding: 1rem;
|
||||||
|
color: var(--btn-subtle-fg);
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: var(--btn-subtle-fg-hover);
|
||||||
|
background: var(--btn-subtle-bg-hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
transition: background 0.2s ease-in-out, color 0.2s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
button[data-active] {
|
||||||
|
color: var(--btn-primary-fg);
|
||||||
|
background: var(--primary-color);
|
||||||
|
border-color: var(--primary-color);
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: var(--btn-primary-bg-hover);
|
||||||
|
border-color: var(--primary-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const Tabs = ({ children, ...props }: TabsProps) => {
|
||||||
|
return <StyledTabs {...props}>{children}</StyledTabs>;
|
||||||
|
};
|
||||||
|
|
||||||
|
Tabs.List = StyledTabs.List;
|
||||||
|
Tabs.Panel = StyledTabs.Panel;
|
||||||
|
Tabs.Tab = StyledTabs.Tab;
|
59
packages/renderer/src/components/text/index.tsx
Normal file
59
packages/renderer/src/components/text/index.tsx
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import type { ComponentPropsWithoutRef, ReactNode } from 'react';
|
||||||
|
import type { TextProps as MantineTextProps } from '@mantine/core';
|
||||||
|
import { createPolymorphicComponent, Text as MantineText } from '@mantine/core';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
import type { Font } from '/@/styles';
|
||||||
|
import { textEllipsis } from '/@/styles';
|
||||||
|
|
||||||
|
type MantineTextDivProps = MantineTextProps & ComponentPropsWithoutRef<'div'>;
|
||||||
|
|
||||||
|
interface TextProps extends MantineTextDivProps {
|
||||||
|
$link?: boolean;
|
||||||
|
$noSelect?: boolean;
|
||||||
|
$secondary?: boolean;
|
||||||
|
children: ReactNode;
|
||||||
|
font?: Font;
|
||||||
|
overflow?: 'hidden' | 'visible';
|
||||||
|
to?: string;
|
||||||
|
weight?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const StyledText = styled(MantineText)<TextProps>`
|
||||||
|
color: ${(props) => (props.$secondary ? 'var(--main-fg-secondary)' : 'var(--main-fg)')};
|
||||||
|
font-family: ${(props) => props.font};
|
||||||
|
cursor: ${(props) => (props.$link ? 'cursor' : 'default')};
|
||||||
|
transition: color 0.2s ease-in-out;
|
||||||
|
user-select: ${(props) => (props.$noSelect ? 'none' : 'auto')};
|
||||||
|
${(props) => props.overflow === 'hidden' && textEllipsis}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: ${(props) => props.$link && 'var(--main-fg)'};
|
||||||
|
text-decoration: ${(props) => (props.$link ? 'underline' : 'none')};
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const _Text = ({ children, $secondary, overflow, font, $noSelect, ...rest }: TextProps) => {
|
||||||
|
return (
|
||||||
|
<StyledText
|
||||||
|
$noSelect={$noSelect}
|
||||||
|
$secondary={$secondary}
|
||||||
|
font={font}
|
||||||
|
overflow={overflow}
|
||||||
|
{...rest}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</StyledText>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Text = createPolymorphicComponent<'div', TextProps>(_Text);
|
||||||
|
|
||||||
|
_Text.defaultProps = {
|
||||||
|
$link: false,
|
||||||
|
$noSelect: false,
|
||||||
|
$secondary: false,
|
||||||
|
font: undefined,
|
||||||
|
overflow: 'visible',
|
||||||
|
to: '',
|
||||||
|
weight: 400,
|
||||||
|
};
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user