Skip to content

Commit

Permalink
0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMindCkm committed Mar 6, 2024
1 parent 0a0f56e commit da93faa
Show file tree
Hide file tree
Showing 696 changed files with 252,740 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
93 changes: 93 additions & 0 deletions .github/workflows/mian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Workflow's name
name: Build Electron App For Win/Mac

# Workflow's trigger
on:
push:
tags:
- "v*.*.*"

# Workflow's jobs
jobs:
# job's id
release:
# job's name
name: build and release electron app

# the type of machine to run the job on
runs-on: ${{ matrix.os }}

# create a build matrix for jobs
strategy:
fail-fast: false
matrix:
os: [windows-2019, macos-10.15,ubuntu-16.04]

# create steps
steps:
# step1: check out repository
- name: Check out git repository
uses: actions/checkout@v2

# step2: install node env
- name: Install Node.js
uses: actions/setup-node@v2-beta

# step3: npm install
- name: yarn install
run: |
yarn install
# step4: build app for mac/win
- name: build windows app
if: matrix.os == 'windows-2019'
run: |
npm run build
env:
GH_TOKEN: ${{ secrets.ACCESS_TOKEN }}

- name: build mac app
if: matrix.os == 'macos-10.15'
run: |
npm run build
env:
GH_TOKEN: ${{ secrets.ACCESS_TOKEN }}

- name: build linux app
if: matrix.os == 'ubuntu-16.04'
run: |
npm run build
env:
GH_TOKEN: ${{ secrets.ACCESS_TOKEN }}

# step5: cleanup artifacts in dist_electron
- name: cleanup artifacts for windows
if: matrix.os == 'windows-2019'
run: |
npx rimraf "build/!(*.exe)"
- name: cleanup artifacts for macosZ
if: matrix.os == 'macos-10.15'
run: |
npx rimraf "build/!(*.dmg)"
- name: cleanup artifacts for ubuntu
if: matrix.os == 'ubuntu-16.04'
run: |
npx rimraf "build/!(*.AppImage)"
# step6: upload artifacts
- name: upload artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.os }}
path: build

# step7: create release
- name: release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: "build/**"
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
dist-electron
release
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
Binary file added build/icons/icon.icns
Binary file not shown.
Binary file added build/icons/icon.ico
Binary file not shown.
Binary file added build/icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions electron-builder.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @see https://www.electron.build/configuration/configuration
*/
{
"$schema": "https://raw.githubusercontent.com/electron-userland/electron-builder/master/packages/app-builder-lib/scheme.json",
"appId": "YourAppID",
"asar": true,
"productName": "YourAppName",
"directories": {
"output": "release/${version}"
},
"files": [
"dist",
"dist-electron"
],
"mac": {
"target": [
"dmg"
],
"artifactName": "${productName}-Mac-${version}-Installer.${ext}"
},
"win": {
"target": [
{
"target": "nsis",
"arch": [
"x64"
]
}
],
"artifactName": "${productName}-Windows-${version}-Setup.${ext}"
},
"nsis": {
"oneClick": false,
"perMachine": false,
"allowToChangeInstallationDirectory": true,
"deleteAppDataOnUninstall": false
},
"linux": {
"target": [
"AppImage"
],
"artifactName": "${productName}-Linux-${version}.${ext}"
}
}
27 changes: 27 additions & 0 deletions electron/electron-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/// <reference types="vite-plugin-electron/electron-env" />

declare namespace NodeJS {
interface ProcessEnv {
/**
* The built directory structure
*
* ```tree
* ├─┬─┬ dist
* │ │ └── index.html
* │ │
* │ ├─┬ dist-electron
* │ │ ├── main.js
* │ │ └── preload.js
* │
* ```
*/
DIST: string
/** /dist/ or /public/ */
VITE_PUBLIC: string
}
}

// Used in Renderer process, expose in `preload.ts`
interface Window {
ipcRenderer: import('electron').IpcRenderer
}
123 changes: 123 additions & 0 deletions electron/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { app, BrowserWindow, ipcMain, shell,Menu } from 'electron'
import path from 'node:path'

var Store = require('electron-store');
const store = new Store();


require('@electron/remote/main').initialize()

var t = store.get('localTime');
if(!t){
store.set('localTime', new Date().getTime())
}

// The built directory structure
//
// ├─┬─┬ dist
// │ │ └── index.html
// │ │
// │ ├─┬ dist-electron
// │ │ ├── main.js
// │ │ └── preload.js
// │
process.env.DIST = path.join(__dirname, '../dist')
process.env.VITE_PUBLIC = app.isPackaged ? process.env.DIST : path.join(process.env.DIST, '../public')


let win: BrowserWindow | null
// 🚧 Use ['ENV_NAME'] avoid vite:define plugin - [email protected]
const VITE_DEV_SERVER_URL = process.env['VITE_DEV_SERVER_URL']

function createWindow() {
win = new BrowserWindow({
width:1200,
height:800,
icon: path.join(process.env.VITE_PUBLIC, 'icon.png'),
webPreferences: {
// preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true,
contextIsolation: false,
webSecurity: false,
enableRemoteModule: true
},
})

require('@electron/remote/main').enable(win.webContents);

// Test active push message to Renderer-process.
win.webContents.on('did-finish-load', () => {
win?.webContents.send('main-process-message', '')
});

Menu.setApplicationMenu(null);

if (VITE_DEV_SERVER_URL) {
win.loadURL(VITE_DEV_SERVER_URL)
} else {
// win.loadFile('dist/index.html')
win.loadFile(path.join(process.env.DIST, 'index.html'))
}
}

// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
win = null
}
})

app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})

app.whenReady().then(createWindow);


ipcMain.on('openExportWindow', (e, arg) => {
var w = new BrowserWindow({
// icon: path.join(process.env.VITE_PUBLIC, 'icon.png')
webPreferences: {
// preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true,
contextIsolation: false,
webSecurity: false,
enableRemoteModule: true
},
});

require('@electron/remote/main').enable(w.webContents);



w.webContents.on('did-finish-load', () => {

w?.webContents.send('main-process-message', arg)
});

if (VITE_DEV_SERVER_URL) {
win.loadURL(VITE_DEV_SERVER_URL)
} else {
// win.loadFile('dist/index.html')
win.loadFile(path.join(process.env.DIST, 'index.html'))
}

})

app.on('window-all-closed', () => {
app.quit()
})

ipcMain.on('relaunch', (e, arg) => {

app.relaunch()
app.exit()
})

Loading

0 comments on commit da93faa

Please sign in to comment.