Skip to content

Commit

Permalink
Fixed permission issues in MAS releases (Security Scoped Bookmarks)
Browse files Browse the repository at this point in the history
  • Loading branch information
ransome1 committed Jan 18, 2025
1 parent aa192b1 commit 1e932be
Show file tree
Hide file tree
Showing 9 changed files with 1,465 additions and 1,756 deletions.
48 changes: 24 additions & 24 deletions .github/workflows/code-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@ jobs:
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif
codecov:
needs: njsscan
name: Codecov
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
language: ['javascript']
steps:
- name: Checkout code
uses: actions/checkout@master
- name: Set up latest available Nodejs
uses: actions/setup-node@master
- name: Install dependencies
run: yarn install
- name: Build
run: yarn build
- name: Run tests
run: yarn run test
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
# codecov:
# needs: njsscan
# name: Codecov
# runs-on: ubuntu-latest
# strategy:
# fail-fast: false
# matrix:
# language: ['javascript']
# steps:
# - name: Checkout code
# uses: actions/checkout@master
# - name: Set up latest available Nodejs
# uses: actions/setup-node@master
# - name: Install dependencies
# run: yarn install
# - name: Build
# run: yarn build
# - name: Run tests
# run: yarn run test
# - name: Upload coverage reports to Codecov
# uses: codecov/codecov-action@v4
# env:
# CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
codeql:
needs: Codecov
needs: njsscan
name: CodeQL
runs-on: ubuntu-latest
strategy:
Expand Down
2 changes: 1 addition & 1 deletion electron-builder.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
directories:
output: dist
buildResources: build
buildVersion: '54'
buildVersion: '56'
asar: true
mac:
appId: com.todotxt.sleek
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sleek",
"productName": "sleek",
"version": "2.0.16-rc.2",
"version": "2.0.16",
"description": "todo.txt manager for Linux, Windows and MacOS, free and open-source (FOSS)",
"synopsis": "todo.txt manager for Linux, Windows and MacOS, free and open-source (FOSS)",
"keywords": [
Expand Down Expand Up @@ -39,7 +39,7 @@
"postinstall": "electron-builder install-app-deps",
"build:unpack": "yarn build && electron-builder --dir",
"mas": "yarn build && electron-builder build -m mas --universal --publish never",
"masdev": "yarn build && electron-builder build -m mas-dev --universal --publish never",
"masdev": "yarn build && electron-builder build -m mas-dev --publish never",
"peggy": "peggy --format es --dts --output ./src/main/modules/Filters/FilterLang.ts ./src/main/modules/Filters/FilterLang.pegjs"
},
"dependencies": {
Expand Down
22 changes: 14 additions & 8 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import path from 'path'
import fs from 'fs'
import { config } from './config.js'
import { createMenu } from './modules/Menu.js'
import { createFileWatcher, watcher } from './modules/File/Watcher.js'
import { createFileWatcher, watcher } from './modules/File/Watcher'
import { addFile } from './modules/File/File'
import { createTray } from './modules/Tray.js'
import macIcon from '../../resources/icon.icns?asset'
import windowsIcon from '../../resources/icon.ico?asset'
Expand Down Expand Up @@ -201,10 +202,13 @@ const handleBeforeQuit = () => {
app.releaseSingleInstanceLock()
}

// const handleOpenFile = (path) => {
// console.log(typeof path)
// if(path) addFile(path, null);
// };
const handleOpenFile = (path) => {
try {
if(path) addFile(path, null);
} catch(error) {
console.error(error)
}
};

app
.whenReady()
Expand All @@ -214,14 +218,16 @@ app
eventListeners.handleCreateWindow = handleCreateWindow
eventListeners.handleWindowAllClosed = handleWindowAllClosed
eventListeners.handleBeforeQuit = handleBeforeQuit
//eventListeners.handleOpenFile = handleOpenFile;
eventListeners.handleOpenFile = handleOpenFile
})
.catch(console.error)

app
.on('window-all-closed', handleWindowAllClosed)
.on('before-quit', handleBeforeQuit)
.on('activate', handleCreateWindow)
//.on('open-file', () => handleOpenFile(path));

.on('open-file', (event, path) => {
event.preventDefault()
handleOpenFile(path)
})
export { mainWindow, handleCreateWindow, eventListeners }
13 changes: 4 additions & 9 deletions src/main/modules/File/File.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,15 @@ import path from 'path'
import { mainWindow } from '../../index'

function readFileContent(filePath: string, bookmark: string | null): string | Error {
const stopAccessingSecurityScopedResource =
process.mas && bookmark ? app.startAccessingSecurityScopedResource(bookmark) : null
const fileContent = fs.readFileSync(filePath, 'utf8')

if (stopAccessingSecurityScopedResource && process.mas && bookmark) {
stopAccessingSecurityScopedResource()
}

return fileContent
}

function addFile(filePath: string, bookmark: string | null) {
if (process.mas && !bookmark)
throw new Error('The Mac App Store release requires you to open files using the file dialog')
if (!bookmark) {
mainWindow!.webContents.send('responseFromMainProcess', 'The Mac App Store release requires you to open files from within the app')
throw new Error('The Mac App Store release requires you to open files from within the app')
}

const files: FileObject[] = config.get('files')
const existingFileIndex = files.findIndex((file) => file.todoFilePath === filePath)
Expand Down
12 changes: 12 additions & 0 deletions src/main/modules/File/Watcher.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import chokidar, { FSWatcher } from 'chokidar'
import { app } from 'electron'
import { dataRequest, searchString } from '../DataRequest/DataRequest'
import { config } from '../../config'
import { handleError } from '../../util'
Expand All @@ -18,6 +19,17 @@ function createFileWatcher(files: FileObject[]): void {
config.set('files', files)
}

if (process.mas) {
files.forEach((file) => {
if (file.todoFileBookmark) {
app.startAccessingSecurityScopedResource(file.todoFileBookmark)
}
if (file.doneFileBookmark) {
app.startAccessingSecurityScopedResource(file.doneFileBookmark)
}
})
}

watcher = chokidar.watch(
files.map((file) => file.todoFilePath),
config.get('chokidarOptions')
Expand Down
7 changes: 0 additions & 7 deletions src/main/modules/File/Write.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@ import { config } from '../../config'
import { replaceSpeakingDatesWithAbsoluteDates } from '../Date'

function writeToFile(string: string, filePath: string, bookmark: string | null) {
const stopAccessingSecurityScopedResource =
process.mas && bookmark ? app.startAccessingSecurityScopedResource(bookmark) : null

fs.writeFileSync(filePath, string, 'utf-8')

if (stopAccessingSecurityScopedResource && process.mas && bookmark) {
stopAccessingSecurityScopedResource()
}
}

function removeLineFromFile(lineNumber: number) {
Expand Down
Loading

0 comments on commit 1e932be

Please sign in to comment.